* Get top departments based on app visibility.
This commit is contained in:
@@ -159,26 +159,40 @@ class feishuapi
|
||||
$company = array('id' => '1', 'pId' => '0', 'name' => $response->data->tenant->name, 'open' => 1);
|
||||
$data = array($company);
|
||||
|
||||
/* Get top departments based on app visibility. */
|
||||
$response = $this->queryAPI($this->apiUrl . "contact/v3/scopes", '', array(CURLOPT_CUSTOMREQUEST => "GET"));
|
||||
$deptList = $response->data->department_ids;
|
||||
|
||||
/* Get depts by parent dept. */
|
||||
$pageToken = '';
|
||||
$index = 0;
|
||||
while(true)
|
||||
foreach($deptList as $deptID)
|
||||
{
|
||||
$response = $this->queryAPI($this->apiUrl . "contact/v3/departments?parent_department_id=0" . ($pageToken ? "&page_token={$pageToken}" : '') . "&fetch_child=true", '', array(CURLOPT_CUSTOMREQUEST => "GET"));
|
||||
if(isset($response->data->items))
|
||||
{
|
||||
foreach($response->data->items as $key => $dept)
|
||||
{
|
||||
$index++;
|
||||
$data[$index]['id'] = $dept->open_department_id;
|
||||
$data[$index]['pId'] = empty($dept->parent_department_id) ? 1 : $dept->parent_department_id;
|
||||
$data[$index]['name'] = $dept->name;
|
||||
$data[$index]['open'] = 1;
|
||||
}
|
||||
}
|
||||
$response = $this->queryAPI($this->apiUrl . "contact/v3/departments/$deptID", '', array(CURLOPT_CUSTOMREQUEST => "GET"));
|
||||
$index++;
|
||||
$data[$index]['id'] = $response->data->department->open_department_id;
|
||||
$data[$index]['pId'] = 1;
|
||||
$data[$index]['name'] = $response->data->department->name;
|
||||
$data[$index]['open'] = 1;
|
||||
|
||||
if(!isset($response->data->page_token)) break;
|
||||
$pageToken = $response->data->page_token;
|
||||
while(true)
|
||||
{
|
||||
$response = $this->queryAPI($this->apiUrl . "contact/v3/departments?parent_department_id=$deptID" . ($pageToken ? "&page_token={$pageToken}" : '') . "&fetch_child=true", '', array(CURLOPT_CUSTOMREQUEST => "GET"));
|
||||
if(isset($response->data->items))
|
||||
{
|
||||
foreach($response->data->items as $key => $dept)
|
||||
{
|
||||
$index++;
|
||||
$data[$index]['id'] = $dept->open_department_id;
|
||||
$data[$index]['pId'] = empty($dept->parent_department_id) ? 1 : $dept->parent_department_id;
|
||||
$data[$index]['name'] = $dept->name;
|
||||
$data[$index]['open'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($response->data->page_token)) break;
|
||||
$pageToken = $response->data->page_token;
|
||||
}
|
||||
}
|
||||
|
||||
$depts['data'] = $data;
|
||||
|
||||
Reference in New Issue
Block a user