Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgrouplist.php
1<?php
2
4
11
13{
14 public const AVAILABLE_ACTION_VIEW = 'view';
15 public const AVAILABLE_ACTION_EDIT = 'edit';
16 public const AVAILABLE_ACTION_DELETE = 'delete';
17 public const AVAILABLE_ACTION_ADD_TO_ARCHIVE = 'add_to_archive';
18 public const AVAILABLE_ACTION_REMOVE_FROM_ARCHIVE = 'remove_from_archive';
19 public const AVAILABLE_ACTION_ADD_TO_FAVORITES = 'add_to_favorites';
20 public const AVAILABLE_ACTION_REMOVE_FROM_FAVORITES = 'remove_from_favorites';
21
22 public const AVAILABLE_ACTION_SET_CURRENT_USER_OWNER = 'set_current_user_owner';
23 public const AVAILABLE_ACTION_SET_CURRENT_USER_SCRUM_MASTER = 'set_current_user_scrum_master';
24 public const AVAILABLE_ACTION_LEAVE = 'leave';
25 public const AVAILABLE_ACTION_JOIN = 'join';
26 public const AVAILABLE_ACTION_DELETE_INCOMING_REQUEST = 'delete_incoming_request';
27
28 public const AJAX_ACTION_SET_OWNER = 'setOwner';
29 public const AJAX_ACTION_JOIN = 'join';
30 public const AJAX_ACTION_SET_SCRUM_MASTER = 'setScrumMaster';
31 public const AJAX_ACTION_DELETE_INCOMING_REQUEST = 'deleteIncomingRequest';
32 public const AJAX_ACTION_REJECT_OUTGOING_REQUEST = 'rejectOutgoingRequest';
33 public const AJAX_ACTION_ADD_TO_ARCHIVE = 'addToArchive';
34 public const AJAX_ACTION_REMOVE_FROM_ARCHIVE = 'removeFromArchive';
35 public const AJAX_ACTION_ADD_TO_FAVORITES = 'addToFavorites';
36 public const AJAX_ACTION_REMOVE_FROM_FAVORITES = 'removeFromFavorites';
37
38 public const GROUP_ACTION_ADD_TO_ARCHIVE = 'addToArchive';
39 public const GROUP_ACTION_REMOVE_FROM_ARCHIVE = 'removeFromArchive';
40 public const GROUP_ACTION_DELETE = 'delete';
41
42 public const MODE_COMMON = '';
43 public const MODE_USER = 'user_groups';
44 public const MODE_TASKS_PROJECT = 'tasks_project';
45 public const MODE_TASKS_SCRUM = 'tasks_scrum';
46
47 protected \Bitrix\Main\Grid\Options $gridOptions;
48 protected \Bitrix\Main\UI\Filter\Options $filterOptions;
49
51 protected $errorCollection = null;
52 protected int $currentUserId = 0;
55 protected array $counterData = [];
56
57 public function configureActions()
58 {
59 return [
60 ];
61 }
62
63 public function __construct($component = null)
64 {
65 parent::__construct($component);
66
67 $this->runtimeFieldsManager = new WorkgroupList\RuntimeFieldsManager();
68 $this->selectFieldsManager = new WorkgroupList\SelectFieldsManager();
69 $this->errorCollection = new ErrorCollection();
70 $this->currentUserId = Helper\User::getCurrentUserId();
71 }
72
79 protected function addError(Error $error)
80 {
81 $this->errorCollection[] = $error;
82
83 return $this;
84 }
85
86 public function getErrorByCode($code)
87 {
88 return $this->errorCollection->getErrorByCode($code);
89 }
90
95 public function getErrors()
96 {
97 return $this->errorCollection->toArray();
98 }
99
100 protected function printErrors(): void
101 {
102 foreach ($this->errorCollection as $error)
103 {
104 ShowError($error);
105 }
106 }
107
108 public static function getActions(
109 WorkgroupList\RuntimeFieldsManager $runtimeFieldsManager,
110 array $params = []
111 ): array
112 {
113 $result = [
114 self::AVAILABLE_ACTION_VIEW,
115 ];
116
117 $groupFields = $params['GROUP'];
118 $runtimeFields = $runtimeFieldsManager->get();
119 $queryInitAlias = $params['QUERY_INIT_ALIAS'];
120
121 $entityManager = new EntityManager([
122 'queryInitAlias' => $params['QUERY_INIT_ALIAS'],
123 ]);
124
125 if (in_array('CURRENT_RELATION', $runtimeFields, true))
126 {
127 $group = $entityManager->wakeUpWorkgroupEntityObject($groupFields);
128 $currentUserRelation = $entityManager->wakeUpCurrentRelationEntityObject($groupFields, $queryInitAlias);
129 $favorites = $entityManager->wakeUpFavoritesEntityObject($groupFields);
130
131 $accessManager = new \Bitrix\Socialnetwork\Item\Workgroup\AccessManager(
132 $group,
133 $currentUserRelation,
134 $currentUserRelation,
135 [
136 'currentUserFavorites' => $favorites,
137 ]
138 );
139
140 if ($accessManager->canEdit())
141 {
142 $result[] = self::AVAILABLE_ACTION_EDIT;
143 }
144
145 if ($accessManager->canSetOwner())
146 {
147 $result[] = self::AVAILABLE_ACTION_SET_CURRENT_USER_OWNER;
148 }
149
150 if ($accessManager->canSetScrumMaster())
151 {
152 $result[] = self::AVAILABLE_ACTION_SET_CURRENT_USER_SCRUM_MASTER;
153 }
154
155 if ($accessManager->canJoin())
156 {
157 $result[] = self::AVAILABLE_ACTION_JOIN;
158 }
159
160 if ($accessManager->canLeave())
161 {
162 $result[] = self::AVAILABLE_ACTION_LEAVE;
163 }
164
165 if ($accessManager->canDeleteIncomingRequest())
166 {
167 $result[] = self::AVAILABLE_ACTION_DELETE_INCOMING_REQUEST;
168 }
169
170 if ($accessManager->canAddToFavorites())
171 {
172 $result[] = self::AVAILABLE_ACTION_ADD_TO_FAVORITES;
173 }
174
175 if ($accessManager->canRemoveFromFavorites())
176 {
177 $result[] = self::AVAILABLE_ACTION_REMOVE_FROM_FAVORITES;
178 }
179
180 if ($accessManager->canAddToArchive())
181 {
182 $result[] = self::AVAILABLE_ACTION_ADD_TO_ARCHIVE;
183 }
184
185 if ($accessManager->canRemoveFromArchive())
186 {
187 $result[] = self::AVAILABLE_ACTION_REMOVE_FROM_ARCHIVE;
188 }
189
190 if ($accessManager->canDelete())
191 {
192 $result[] = self::AVAILABLE_ACTION_DELETE;
193 }
194 }
195
196 return $result;
197 }
198
199 public static function getCellActions(
200 WorkgroupList\RuntimeFieldsManager $runtimeFieldsManager,
201 $params
202 ): array
203 {
204
205 $gridId = (string)($params['GRID_ID'] ?? '');
206 $groupFields = ($params['GROUP'] ?? null);
207 if (
208 !$groupFields
209 || $gridId === ''
210 )
211 {
212 return [];
213 }
214
215 $runtimeFields = $runtimeFieldsManager->get();
216
217 $entityManager = new EntityManager([
218 'queryInitAlias' => $params['QUERY_INIT_ALIAS'],
219 ]);
220
221 $group = $entityManager->wakeUpWorkgroupEntityObject($groupFields);
222 if (!$group)
223 {
224 return [];
225 }
226
227 $groupId = (int)$group->get('ID');
228
229 $pin = [];
230 if (in_array('PIN', $runtimeFields, true))
231 {
232 $pinEntity = $entityManager->wakeUpPinEntityObject($groupFields);
233 $isPinned = ($pinEntity !== null);
234
235 $pin = [
236 'class' => [
237 Grid\CellActions::PIN,
238 ($isPinned ? Grid\CellActionState::ACTIVE : Grid\CellActionState::SHOW_BY_HOVER),
239 ],
240 'events' => [
241 'click' => 'BX.Socialnetwork.UI.Grid.ActionController
242 .changePin.bind(BX.Socialnetwork.UI.Grid.ActionController, ' . $groupId . ')',
243 ],
244 ];
245 }
246
247 return [
248 'NAME' => [
249 $pin,
250 ],
251 ];
252 }
253
254 protected function checkAjaxAction(string $action = ''): bool
255 {
256 return in_array($action, [
257 self::AJAX_ACTION_JOIN,
258 self::AJAX_ACTION_SET_OWNER,
259 self::AJAX_ACTION_SET_SCRUM_MASTER,
260 self::AJAX_ACTION_DELETE_INCOMING_REQUEST,
261 self::AJAX_ACTION_REJECT_OUTGOING_REQUEST,
262 self::AJAX_ACTION_ADD_TO_ARCHIVE,
263 self::AJAX_ACTION_REMOVE_FROM_ARCHIVE,
264 ], true);
265 }
266
267 public static function getTasksModeList(): array
268 {
269 return [
270 self::MODE_TASKS_PROJECT,
271 self::MODE_TASKS_SCRUM,
272 ];
273 }
274
275 protected function getAccessToTasksCounters(): bool
276 {
277 return TasksCounter::getAccessToTasksCounters([
278 'mode' => $this->arParams['MODE'],
279 'contextUserId' => $this->arParams['USER_ID'],
280 ]);
281 }
282
283 protected function getTasksCounters(): array
284 {
285 return TasksCounter::getTasksCounters([
286 'mode' => $this->arParams['MODE'],
287 ]);
288 }
289
290 protected function getTasksCountersScope(): string
291 {
292 return TasksCounter::getTasksCountersScope([
293 'mode' => $this->arParams['MODE'],
294 ]);
295 }
296
297 protected function isFilterApplied(): bool
298 {
299 $currentPreset = $this->filterOptions->getCurrentFilterId();
300 $isDefaultPreset = ($this->filterOptions->getDefaultFilterId() === $currentPreset);
301 $additionalFields = $this->filterOptions->getAdditionalPresetFields($currentPreset);
302 $isSearchStringEmpty = ($this->filterOptions->getSearchString() === '');
303
304 return (!$isSearchStringEmpty || !$isDefaultPreset || !empty($additionalFields));
305 }
306}
static getCellActions(WorkgroupList\RuntimeFieldsManager $runtimeFieldsManager, $params)
WorkgroupList SelectFieldsManager $selectFieldsManager
WorkgroupList RuntimeFieldsManager $runtimeFieldsManager
static getActions(WorkgroupList\RuntimeFieldsManager $runtimeFieldsManager, array $params=[])
Bitrix Main UI Filter Options $filterOptions