ListChildrenController.class.php
4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 16/11/14
* Time: 17:14
*/
namespace Apicp\Controller\Department;
use Common\Common\AdminerRole;
use Common\Common\User;
use VcySDK\Department;
use VcySDK\Member;
use VcySDK\Service;
class ListChildrenController extends AbstractController
{
/**
* VcySDK 附件操作类
*
* @type Department
*/
protected $_department;
/**
* VcySDK 用户操作类
*
* @type Member
*/
protected $_mem;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$serv = &Service::instance();
$this->_department = new Department($serv);
$this->_mem = new Member($serv);
return true;
}
/**
* 【通讯录】部门列表
* @author liyifei
*/
public function Index_post()
{
$dpParentId = I("post.dpParentId");
$limit = I("post.limit", 30);
$page = I("post.page", 1);
// 如果上级部门ID为空
if (empty($dpParentId)) {
// 获取顶级部门
$dpParentId = $this->maxDpId();
}
// 查询部分指定部门
list($departments, $data) = $this->partdp($dpParentId, $page, $limit);
$this->_result = array(
'list' => $departments,
'total' => (int)$data['total'],
'limit' => (int)$data['pageSize'],
'page' => (int)$data['pageNum'],
);
return true;
}
/**
* 获取部门列表
*
* @param string $dpParentId 上级部门ID
* @param int $page 页码
* @param int $limit 每页条数
*
* @return array
*/
private function partdp($dpParentId, $page, $limit)
{
// 初始化
$data = array();
// 获取部门详情
$dpIds = array_values(\Common\Common\Department::instance()->list_childrens_by_cdid($dpParentId, true));
$departments = \Common\Common\Department::instance()->listAll();
$start = ($page - 1) * $limit;
$end = $start + $limit;
$dpId2uids = array();
$adminerRoleUtil = new AdminerRole();
for (; $start < $end; $start++) {
if (empty($dpIds[$start])) {
break;
}
// 获取部门管理员权限
if (false === ($auth = $adminerRoleUtil->childrenDepInAuth($this->_login->role, $dpIds[$start]))) {
// 部门 以及 部门所有子部门 没有权限, 直接不显示
continue;
};
$currentDp = $departments[$dpIds[$start]];
if (!empty($currentDp['dpLead'])) {
$dpId2uids[$currentDp['dpId']] = explode(',', $currentDp['dpLead']);
}
$data[$currentDp['dpId']] = array(
'read' => $auth[1] ? true : $auth[0],
'write' => $auth[1],
'dpId' => $currentDp['dpId'],
'dpName' => $currentDp['dpName'],
'isChildDepartment' => $currentDp['isChildDepartment'],
'order' => $currentDp['dpDisplayorder'],
'user_total' => $currentDp['departmentMemberCount'],
'dept_level' => $currentDp['dpLevel'],
'dptName' => $currentDp['dptName'],
'dpSerialNum' => $currentDp['dpSerialNum'],
'dpLead' => $currentDp['dpLead'],
'dpLeadList' => array()
);
}
$uids = array();
foreach ($dpId2uids as $_uids) {
foreach ($_uids as $_uid) {
$uids[$_uid] = $_uid;
}
}
$users = User::instance()->listByUid($uids);
foreach ($dpId2uids as $_dpId => $_uids) {
foreach ($_uids as $_uid) {
if (!empty($users[$_uid])) {
$data[$_dpId]['dpLeadList'][] = $users[$_uid];
}
}
}
return array(array_values($data), array('total' => count($dpIds), 'pageNum' => $page, 'pageSize' => $limit));
}
/**
* 获取顶级部门ID
*
*/
private function maxDpId()
{
$topId = '';
\Common\Common\Department::instance()->get_top_dpId($topId);
return $topId;
}
}