Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgroupdataprovider.php
1<?php
2
4
11
13{
16 protected ?array $additionalParams;
17
19 {
20 $this->settings = $settings;
21 $this->additionalParams = $additionalParams;
22 }
23
28 public function getSettings(): ?WorkgroupSettings
29 {
30 return $this->settings;
31 }
32
38 protected function getFieldName($fieldID): string
39 {
40 switch ($fieldID)
41 {
42 case 'OWNER':
43 $name = (
44 ModuleManager::isModuleInstalled('intranet')
45 ? Loc::getMessage("SOCIALNETWORK_WORKGROUP_FILTER_{$fieldID}_INTRANET")
46 : Loc::getMessage("SOCIALNETWORK_WORKGROUP_FILTER_{$fieldID}")
47 );
48 break;
49 default:
50 $name = Loc::getMessage("SOCIALNETWORK_WORKGROUP_FILTER_{$fieldID}");
51 }
52
53 if ($name === null)
54 {
55 $name = $fieldID;
56 }
57
58 return $name;
59 }
60
61 public function prepareFieldData($fieldID): ?array
62 {
63 $result = null;
64
65 if ($fieldID === 'ROLE')
66 {
67/*
68 $roles = [
69 UserToGroupTable::ROLE_OWNER => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_ROLE_OWNER'),
70 UserToGroupTable::ROLE_MODERATOR => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_ROLE_MODERATOR'),
71 UserToGroupTable::ROLE_USER => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_ROLE_USER'),
72 UserToGroupTable::ROLE_REQUEST => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_ROLE_REQUEST'),
73 ];
74 $result = [
75 'params' => ['multiple' => 'Y'],
76 'items' => $roles
77 ];
78*/
79 }
80 elseif ($fieldID === 'INITIATED_BY_TYPE')
81 {
82/*
83 $result = [
84 'params' => ['multiple' => 'N'],
85 'items' => [
86 UserToGroupTable::INITIATED_BY_USER => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_INITIATED_BY_USER'),
87 UserToGroupTable::INITIATED_BY_GROUP => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_INITIATED_BY_GROUP'),
88 ]
89 ];
90*/
91 }
92 elseif ($fieldID === 'OWNER')
93 {
94 return [
95 'params' => [
96 'apiVersion' => '3',
97 'context' => 'SONET_GROUP_LIST_FILTER_OWNER',
98 'multiple' => 'N',
99 'contextCode' => 'U',
100 'enableAll' => 'N',
101 'enableSonetgroups' => 'N',
102 'allowEmailInvitation' => 'N',
103 'allowSearchEmailUsers' => 'N',
104 'departmentSelectDisable' => 'Y',
105 ],
106 ];
107 }
108 elseif ($fieldID === 'MEMBER')
109 {
110 return [
111 'params' => [
112 'apiVersion' => '3',
113 'context' => 'SONET_GROUP_LIST_FILTER_MEMBER',
114 'multiple' => 'N',
115 'contextCode' => 'U',
116 'enableAll' => 'N',
117 'enableSonetgroups' => 'N',
118 'allowEmailInvitation' => 'N',
119 'allowSearchEmailUsers' => 'N',
120 'departmentSelectDisable' => 'Y',
121 ],
122 ];
123 }
124 elseif (in_array($fieldID, [ 'FAVORITES', 'EXTRANET' ], true))
125 {
126 return [
127 'items' => [
128 '' => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_LIST_VALUE_NOT_SPECIFIED'),
129 'Y' => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_LIST_VALUE_Y'),
130 ],
131 ];
132 }
133 elseif ($fieldID === 'COUNTERS')
134 {
135 $items = [];
136
137 if (
138 is_array($this->additionalParams)
139 && isset($this->additionalParams['MODE'])
140 && in_array($this->additionalParams['MODE'], WorkgroupList::getTasksModeList(), true)
141 )
142 {
143 if ($this->additionalParams['MODE'] === WorkgroupList::MODE_TASKS_SCRUM)
144 {
145 $items = [
146 'NEW_COMMENTS' => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_COUNTERS_LIST_VALUE_NEW_COMMENTS'),
147 'PROJECT_NEW_COMMENTS' => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_COUNTERS_LIST_VALUE_PROJECT_NEW_COMMENTS'),
148 ];
149 }
150 elseif ($this->additionalParams['MODE'] === WorkgroupList::MODE_TASKS_PROJECT)
151 {
152 $items = [
153 'EXPIRED' => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_COUNTERS_LIST_VALUE_EXPIRED'),
154 'NEW_COMMENTS' => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_COUNTERS_LIST_VALUE_NEW_COMMENTS'),
155 'PROJECT_EXPIRED' => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_COUNTERS_LIST_VALUE_PROJECT_EXPIRED'),
156 'PROJECT_NEW_COMMENTS' => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_COUNTERS_LIST_VALUE_PROJECT_NEW_COMMENTS'),
157 ];
158 }
159 }
160
161 return [
162 'items' => $items,
163 ];
164 }
165 elseif ($fieldID === 'COMMON_COUNTERS')
166 {
167 $items = [];
168
169 if (
170 is_array($this->additionalParams)
171 && isset($this->additionalParams['MODE'])
172 && $this->additionalParams['MODE'] === WorkgroupList::MODE_COMMON
173 )
174 {
175 $items = [
176 CounterFilter::VALUE_LIVEFEED => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_COUNTERS_LIST_VALUE_LIVEFEED'),
177 CounterFilter::VALUE_TASKS => Loc::getMessage('SOCIALNETWORK_WORKGROUP_FILTER_COUNTERS_LIST_VALUE_TASKS'),
178 ];
179 }
180
181 return [
182 'items' => $items,
183 ];
184 }
185
186 return $result;
187 }
188
193 public function prepareFields(): array
194 {
195 $result = [];
196
197 $fieldsList = [
198 'ID' => [
199 'options' => [ 'type' => 'number' ],
200 ],
201 'NAME' => [
202 'options' => [ 'default' => true ],
203 ],
204 'OWNER' => [
205 'options' => [ 'type' => 'dest_selector', 'partial' => true ],
206 ],
207 'MEMBER' => [
208 'options' => [ 'type' => 'dest_selector', 'partial' => true ],
209 ],
210 'TAG' => [
211 'options' => [],
212 ],
213 'VISIBLE' => [
214 'options' => [ 'type' => 'checkbox' ],
215 ],
216 'OPENED' => [
217 'options' => [ 'type' => 'checkbox' ],
218 ],
219 'CLOSED' => [
220 'conditionMethod' => '\Bitrix\Socialnetwork\Filter\WorkgroupDataProvider::getClosedAvailability',
221 'options' => [ 'type' => 'checkbox' ],
222 ],
223 'PROJECT' => [
224 'conditionMethod' => '\Bitrix\Main\Filter\UserDataProvider::getProjectAvailability',
225 'options' => [ 'type' => 'checkbox' ],
226 ],
227 'SCRUM' => [
228 'conditionMethod' => '\Bitrix\Main\Filter\UserDataProvider::getScrumAvailability',
229 'options' => [ 'type' => 'checkbox' ],
230 ],
231 'PROJECT_DATE' => [
232 'conditionMethod' => '\Bitrix\Main\Filter\UserDataProvider::getProjectAvailability',
233 'options' => [ 'type' => 'date' ]
234 ],
235 'EXTRANET' => [
236 'conditionMethod' => '\Bitrix\Main\Filter\UserDataProvider::getExtranetAvailability',
237 'options' => [ 'type' => 'list', 'partial' => true ],
238 ],
239 'LANDING' => [
240 'conditionMethod' => '\Bitrix\Main\Filter\UserDataProvider::getLandingAvailability',
241 'options' => [ 'type' => 'checkbox' ],
242 ],
243 'FAVORITES' => [
244 'options' => [ 'type' => 'list', 'partial' => true ],
245 ],
246 'COUNTERS' => [
247 'options' => [ 'type' => 'list', 'partial' => true ],
248 ],
249 ];
250
251 //todo oh
252 if (
253 is_array($this->additionalParams)
254 && isset($this->additionalParams['MODE'])
255 && in_array($this->additionalParams['MODE'], WorkgroupList::getTasksModeList(), true)
256 )
257 {
258 $fieldsList['COMMON_COUNTERS'] = [
259 'options' => [ 'type' => 'list', 'partial' => true ],
260 ];
261 }
262
263 foreach ($fieldsList as $column => $field)
264 {
265 $whiteListPassed = true;
266
267 if (
268 !empty($field['conditionMethod'])
269 && is_callable($field['conditionMethod'])
270 )
271 {
272 $whiteListPassed = call_user_func_array($field['conditionMethod'], []);
273 }
274
275 if ($whiteListPassed)
276 {
277 if (
278 is_array($this->additionalParams)
279 && isset($this->additionalParams['MODE'])
280 && in_array($column, ['SCRUM', 'PROJECT'], true)
281 && in_array($this->additionalParams['MODE'], WorkgroupList::getTasksModeList(), true)
282 )
283 {
284 continue;
285 }
286
287 if (
288 $column === 'COUNTERS'
289 && (
290 !is_array($this->additionalParams)
291 || !isset($this->additionalParams['MODE'])
292 || !in_array($this->additionalParams['MODE'], WorkgroupList::getTasksModeList(), true)
293 )
294 )
295 {
296 continue;
297 }
298
299 if (
300 $column === 'COMMON_COUNTERS'
301 && (
302 !isset($this->additionalParams['MODE'], $this->additionalParams['CONTEXT_USER_ID'])
303 || !is_array($this->additionalParams)
304 || $this->additionalParams['MODE'] !== WorkgroupList::MODE_COMMON
305 || $this->additionalParams['CONTEXT_USER_ID'] !== Helper\User::getCurrentUserId()
306 )
307 )
308 {
309 continue;
310 }
311
312 $result[$column] = $this->createField(
313 $column,
314 (!empty($field['options']) ? $field['options'] : [])
315 );
316 }
317 }
318
319 return $result;
320 }
321
322 public static function getClosedAvailability(): bool
323 {
324 return (Option::get('socialnetwork', 'work_with_closed_groups', 'N') !== 'Y');
325 }
326
327 public static function getProjectAvailability(): bool
328 {
329 return (
330 ModuleManager::isModuleInstalled('intranet')
331 && ModuleManager::isModuleInstalled('tasks')
332 );
333 }
334
335 public static function getScrumAvailability(): bool
336 {
337 return (
338 ModuleManager::isModuleInstalled('intranet')
339 && ModuleManager::isModuleInstalled('tasks')
340 );
341 }
342
343 public static function getLandingAvailability(): bool
344 {
345 $extranetSiteId = Option::get('extranet', 'extranet_site');
346 $extranetSiteId = ($extranetSiteId && ModuleManager::isModuleInstalled('extranet') ? $extranetSiteId : '');
347
348 return (
349 SITE_ID !== $extranetSiteId
350 && ModuleManager::isModuleInstalled('landing')
351 );
352 }
353
354}
createField($fieldID, array $params=null)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
__construct(WorkgroupSettings $settings, ?array $additionalParams=null)