Passed
Push — master ( f7e515...09c178 )
by mingyoung
01:34
created

Client::getActivatedUserCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the mingyoung/dingtalk.
5
 *
6
 * (c) 张铭阳 <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyDingTalk\Department;
13
14
use EasyDingTalk\Kernel\BaseClient;
15
16
class Client extends BaseClient
17
{
18
    /**
19
     * 获取子部门ID列表
20
     *
21
     * @param string $id 部门ID
22
     *
23
     * @return mixed
24
     */
25
    public function getSubDepartmentIds($id)
26
    {
27
        return $this->client->get('department/list_ids', compact('id'));
28
    }
29
30
    /**
31
     * 获取部门列表
32
     *
33
     * @param bool   $isFetchChild
34
     * @param string $id
35
     * @param string $lang
36
     *
37
     * @return mixed
38
     */
39
    public function list($id = null, $isFetchChild = false, $lang = null)
40
    {
41
        return $this->client->get('department/list',
42
            compact('id', 'lang') + ['fetch_child' => $isFetchChild]);
43
    }
44
45
    /**
46
     * 获取部门详情
47
     *
48
     * @param string $id
49
     * @param string $lang
50
     *
51
     * @return mixed
52
     */
53
    public function get($id, $lang = null)
54
    {
55
        return $this->client->get('department/get', compact('id', 'lang'));
56
    }
57
58
    /**
59
     * 查询部门的所有上级父部门路径
60
     *
61
     * @param string $id
62
     *
63
     * @return mixed
64
     */
65
    public function getParentsById($id)
66
    {
67
        return $this->client->get('department/list_parent_depts_by_dept', compact('id'));
68
    }
69
70
    /**
71
     * 查询指定用户的所有上级父部门路径
72
     *
73
     * @param string $userId
74
     *
75
     * @return mixed
76
     */
77
    public function getParentsByUserId($userId)
78
    {
79
        return $this->client->get('department/list_parent_depts', compact('userId'));
80
    }
81
82
    /**
83
     * 获取企业员工人数
84
     *
85
     * @param int $onlyActive
86
     *
87
     * @return mixed
88
     */
89
    public function getUserCount($onlyActive = 0)
90
    {
91
        return $this->client->get('user/get_org_user_count', compact('onlyActive'));
92
    }
93
94
    /**
95
     * 获取企业已激活的员工人数
96
     *
97
     * @return mixed
98
     */
99
    public function getActivatedUserCount()
100
    {
101
        return $this->getUserCount(1);
102
    }
103
104
    /**
105
     * 创建部门
106
     *
107
     * @param array $params
108
     *
109
     * @return mixed
110
     */
111
    public function create(array $params)
112
    {
113
        return $this->client->postJson('department/create', $params);
114
    }
115
116
    /**
117
     * 更新部门
118
     *
119
     * @param string $id
120
     * @param array  $params
121
     *
122
     * @return mixed
123
     */
124
    public function update($id, array $params)
125
    {
126
        return $this->client->postJson('department/update', compact('id') + $params);
127
    }
128
129
    /**
130
     * 删除部门
131
     *
132
     * @param string $id
133
     *
134
     * @return mixed
135
     */
136
    public function delete($id)
137
    {
138
        return $this->client->get('department/delete', compact('id'));
139
    }
140
}
141