Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgroupuserlist.php
1<?php
2
4
13
15{
16 public const AVAILABLE_ACTION_VIEW_PROFILE = 'view_profile';
17 public const AVAILABLE_ACTION_SET_OWNER = 'set_owner';
18 public const AVAILABLE_ACTION_SET_SCRUM_MASTER = 'set_scrum_master';
19 public const AVAILABLE_ACTION_EXCLUDE = 'exclude';
20 public const AVAILABLE_ACTION_SET_MODERATOR = 'set_moderator';
21 public const AVAILABLE_ACTION_REMOVE_MODERATOR = 'remove_moderator';
22 public const AVAILABLE_ACTION_PROCESS_INCOMING_REQUEST = 'process_incoming_request';
23 public const AVAILABLE_ACTION_DELETE_OUTGOING_REQUEST = 'delete_outgoing_request';
24 public const AVAILABLE_ACTION_DELETE_INCOMING_REQUEST = 'delete_incoming_request';
25 public const AVAILABLE_ACTION_REINVITE = 'reinvite';
26
27 public const AJAX_ACTION_SET_OWNER = 'setOwner';
28 public const AJAX_ACTION_SET_SCRUM_MASTER = 'setScrumMaster';
29 public const AJAX_ACTION_SET_MODERATOR = 'setModerator';
30 public const AJAX_ACTION_REMOVE_MODERATOR = 'removeModerator';
31 public const AJAX_ACTION_EXCLUDE = 'exclude';
32 public const AJAX_ACTION_DELETE_OUTGOING_REQUEST = 'deleteOutgoingRequest';
33 public const AJAX_ACTION_DELETE_INCOMING_REQUEST = 'deleteIncomingRequest';
34 public const AJAX_ACTION_ACCEPT_INCOMING_REQUEST = 'acceptIncomingRequest';
35 public const AJAX_ACTION_REJECT_INCOMING_REQUEST = 'rejectIncomingRequest';
36 public const AJAX_ACTION_REINVITE = 'reinvite';
37
38 protected const PRESET_ALL = 'all';
39 protected const PRESET_COMPANY = 'company';
40 protected const PRESET_REQUESTS_IN = 'requests_in';
41 protected const PRESET_REQUESTS_OUT = 'requests_out';
42 protected const PRESET_EXTERNAL = 'external';
43 protected const PRESET_AUTO = 'auto';
44
45 protected static $gridId = 'SOCIALNETWORK_WORKGROUP_USER_LIST';
46 protected static $filterId = 'SOCIALNETWORK_WORKGROUP_USER_LIST';
47
49 protected $errorCollection = null;
50
51 public function configureActions()
52 {
53 return [
54 ];
55 }
56
57 public function __construct($component = null)
58 {
59 parent::__construct($component);
60
61 $this->errorCollection = new ErrorCollection();
62 }
63
70 protected function addError(Error $error)
71 {
72 $this->errorCollection[] = $error;
73
74 return $this;
75 }
76
77 public function getErrorByCode($code)
78 {
79 return $this->errorCollection->getErrorByCode($code);
80 }
81
86 public function getErrors()
87 {
88 return $this->errorCollection->toArray();
89 }
90
91 protected function printErrors(): void
92 {
93 foreach ($this->errorCollection as $error)
94 {
95 ShowError($error);
96 }
97 }
98
99 public static function getActions(array $params = []): array
100 {
101 $result = [
103 ];
104
105 $groupId = (int)$params['GROUP_ID'];
106 $group = $params['GROUP'];
107 $currentUserRelation = $params['CURRENT_RELATION'];
108 $relation = $params['RELATION'];
109
110 $accessManager = new AccessManager(
111 $group,
112 $relation,
113 $currentUserRelation,
114 );
115
116 if ($accessManager->canSetOwner())
117 {
119 }
120
121 if ($accessManager->canSetScrumMaster())
122 {
124 }
125
126 if ($accessManager->canSetModerator())
127 {
129 }
130 elseif ($accessManager->canRemoveModerator())
131 {
133 }
134
135 $canDeleteOutgoingRequest = $accessManager->canDeleteOutgoingRequest();
136 if ($accessManager->canDeleteOutgoingRequest())
137 {
139 }
140 elseif ($accessManager->canExclude())
141 {
143 }
144
145 if ($accessManager->canProcessIncomingRequest())
146 {
148 }
149
150 if (
151 $canDeleteOutgoingRequest
152 && ModuleManager::isModuleInstalled('intranet')
153 && !empty($relation->getUser()->getConfirmCode())
154 )
155 {
157 }
158
159 if ($accessManager->canDeleteIncomingRequest())
160 {
162 }
163
164 return $result;
165 }
166
167 public static function prepareFilterResult(
168 array $result,
169 array $groupPerms,
170 string $mode = ''
171 ): array
172 {
173 $entityFilter = Filter\Factory::createEntityFilter(
175 [
176 'ID' => self::$filterId,
177 ]
178 );
179 $result['FILTER'] = $entityFilter->getFieldArrays();
180
181 $result['GRID_ID'] = self::$gridId;
182 $result['FILTER_ID'] = self::$filterId;
183
184 $result['CURRENT_PRESET_ID'] = self::getCurrentPresetId($mode);
185 $result['CURRENT_COUNTER'] = self::getCounter($mode);
186 $result['CUSTOM_FILTER'] = self::getCurrentCustomFilter($mode);
187 $result['FILTER_PRESETS'] = self::getFilterPresets($result['CURRENT_PRESET_ID'], $groupPerms);
188
189 return $result;
190 }
191
192 private static function getCurrentPresetId(string $mode): string
193 {
194 switch ($mode)
195 {
196 case 'MEMBERS':
197 $result = self::PRESET_COMPANY;
198 break;
199 case 'REQUESTS_IN':
200 $result = self::PRESET_REQUESTS_IN;
201 break;
202 case 'REQUESTS_OUT':
204 break;
205 default:
206 $result = 'tmp_filter';
207 }
208
209 return $result;
210 }
211
212 private static function getCounter(string $mode): string
213 {
214 switch ($mode)
215 {
216 case 'REQUESTS_IN':
218 break;
219 case 'REQUESTS_OUT':
221 break;
222 default:
223 $result = '';
224 }
225
226 return $result;
227 }
228
229 private static function getCurrentCustomFilter(string $mode): array
230 {
231 switch ($mode)
232 {
233 case 'MODERATORS':
234 $result = [
236 ];
237 break;
238 default:
239 $result = [];
240 }
241
242 return $result;
243 }
244
245 private static function getFilterPresets(string $currentPresetId, array $groupPerms): array
246 {
247 $result = [];
248
249 $extranetAvailable = \Bitrix\Main\Filter\UserDataProvider::getExtranetAvailability();
250
251 $result[self::PRESET_ALL] = [
252 'name' => Loc::getMessage('SOCIALNETWORK_GROUP_USER_LIST_FILTER_PRESET_ALL'),
253 'fields' => [],
254 'default' => ($currentPresetId === self::PRESET_ALL),
255 ];
256
257 $companyFilter = [
258 'FIRED' => 'N',
260 ];
261 if ($extranetAvailable)
262 {
263 $companyFilter['EXTRANET'] = 'N';
264 }
265
266 $result[self::PRESET_COMPANY] = [
267 'name' => (
268 $extranetAvailable
269 ? Loc::getMessage('SOCIALNETWORK_GROUP_USER_LIST_FILTER_PRESET_COMPANY')
270 : Loc::getMessage('SOCIALNETWORK_GROUP_USER_LIST_FILTER_PRESET_MEMBERS')
271 ),
272 'fields' => $companyFilter,
273 'default' => ($currentPresetId === self::PRESET_COMPANY),
274 ];
275
276 if ($extranetAvailable)
277 {
278 $result[self::PRESET_EXTERNAL] = [
279 'name' => Loc::getMessage('SOCIALNETWORK_GROUP_USER_LIST_FILTER_PRESET_EXTERNAL'),
280 'fields' => [
281 'EXTRANET' => 'Y',
282 'FIRED' => 'N',
284 ],
285 'default' => false,
286 ];
287 }
288
289 if ($groupPerms['UserCanProcessRequestsIn'] ?? null)
290 {
291 $result[self::PRESET_REQUESTS_IN] = [
292 'name' => Loc::getMessage('SOCIALNETWORK_GROUP_USER_LIST_FILTER_PRESET_REQUESTS_IN'),
293 'fields' => [
294 'ROLE' => [ UserToGroupTable::ROLE_REQUEST ],
295 'FIRED' => 'N',
296 'INITIATED_BY_TYPE' => UserToGroupTable::INITIATED_BY_USER,
297 ],
298 'default' => ($currentPresetId === self::PRESET_REQUESTS_IN),
299 ];
300 }
301
302 if ($groupPerms['UserCanInitiate'])
303 {
304 $result[self::PRESET_REQUESTS_OUT] = [
305 'name' => Loc::getMessage('SOCIALNETWORK_GROUP_USER_LIST_FILTER_PRESET_REQUESTS_OUT'),
306 'fields' => [
307 'ROLE' => [ UserToGroupTable::ROLE_REQUEST ],
308 'FIRED' => 'N',
309 'INITIATED_BY_TYPE' => UserToGroupTable::INITIATED_BY_GROUP,
310 ],
311 'default' => ($currentPresetId === self::PRESET_REQUESTS_OUT),
312 ];
313 }
314
315 return $result;
316 }
317}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static prepareFilterResult(array $result, array $groupPerms, string $mode='')