Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgroupform.php
1<?php
2
4
5use Bitrix\Intranet\Internals\ThemeTable;
9use Bitrix\Intranet\Integration\Templates\Bitrix24\ThemePicker;
10
11class WorkgroupForm extends \CBitrixComponent
12{
13 protected function prepareData(): array
14 {
15 $result = [
16 'preset' => (!empty($_GET['preset']) ? $_GET['preset'] : false),
17 'bVarsFromForm' => false,
18 'templateEditMode' => 'N',
19 'destinationContextOwner' => 'GROUP_INVITE_OWNER',
20 'destinationContextModerators' => 'GROUP_INVITE_MODERATORS',
21 'destinationContextUsers' => 'GROUP_INVITE',
22 'isCurrentUserAdmin' => \CSocNetUser::isCurrentUserModuleAdmin(),
23 ];
24
25 $this->processGroupProperties($result);
26 $this->processParams($result);
27 $this->processRequest($result);
28 $this->getThemePickerData($result);
29
30 return $result;
31 }
32
33 protected function processParams(array &$result = []): void
34 {
35 if (empty($this->arParams['TAB']))
36 {
37 return;
38 }
39
40 $result['TAB'] = strtolower($this->arParams['TAB']);
41 }
42
43 protected function processRequest(array &$result = []): void
44 {
45 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
46
47 $result['IS_IFRAME'] = ($request->get('IFRAME') === 'Y' || $this->arParams['IFRAME'] === 'Y');
48 $result['IS_POPUP'] = ($request->get('POPUP') === 'Y');
49
50 if (in_array($request->get('CALLBACK'), [ 'REFRESH', 'GROUP' ]))
51 {
52 $result['CALLBACK'] = $request->get('CALLBACK');
53 }
54
55 if (!empty($request->getPost('TAB')))
56 {
57 $result['TAB'] = $request->getPost('TAB');
58 }
59 elseif (!empty($request->get('tab')))
60 {
61 $result['TAB'] = $request->get('tab');
62 }
63 }
64
65 protected function getThemePickerData(array &$result = []): void
66 {
67 global $USER;
68
69 $groupId = (isset($this->arParams['GROUP_ID']) ? (int)$this->arParams['GROUP_ID'] : 0);
70
71 if (
72 SITE_TEMPLATE_ID !== 'bitrix24'
73 || !Loader::includeModule('intranet')
74 )
75 {
76 return;
77 }
78
79 $result['showThemePicker'] = (
80 $result['IS_IFRAME']
81 && (empty($result['TAB']) || $result['TAB'] === 'edit')
82 && ($this->arParams['THEME_ENTITY_TYPE'] ?? null) === 'SONET_GROUP'
83 );
84
85 $result['themePickerData'] = [];
86
87 if (!$result['showThemePicker'])
88 {
89 return;
90 }
91
92 if ($groupId > 0)
93 {
94 $themePicker = new ThemePicker(SITE_TEMPLATE_ID, false, $USER->getId(), ThemePicker::ENTITY_TYPE_SONET_GROUP, $groupId);
95 $themeId = $themePicker->getCurrentThemeId();
96 $themeUserId = false;
97 if ($themeId)
98 {
99 $res = ThemeTable::getList([
100 'filter' => [
101 '=ENTITY_TYPE' => $themePicker->getEntityType(),
102 'ENTITY_ID' => $themePicker->getEntityId(),
103 '=CONTEXT' => $themePicker->getContext(),
104 ],
105 'select' => [ 'USER_ID' ],
106 ]);
107 if (
108 ($themeFields = $res->fetch())
109 && (int)$themeFields['USER_ID'] > 0
110 )
111 {
112 $themeUserId = (int)$themeFields['USER_ID'];
113 }
114 }
115 $result['themePickerData'] = $themePicker->getTheme($themeId, $themeUserId);
116 }
117 elseif ($themePicker = new ThemePicker(SITE_TEMPLATE_ID))
118 {
119 $themesList = $themePicker->getPatternThemes();
120 $result['themePickerData'] = $themesList[array_rand($themesList)];
121 }
122 }
123
124 protected function processGroupProperties(array &$result = []): void
125 {
126 global $USER_FIELD_MANAGER;
127
128 $result['GROUP_PROPERTIES'] = $USER_FIELD_MANAGER->getUserFields('SONET_GROUP', 0, LANGUAGE_ID);
129
130 foreach ($result['GROUP_PROPERTIES'] as $field => $userFieldFata)
131 {
132 if (
133 !empty($userFieldFata['EDIT_IN_LIST'])
134 && $userFieldFata['EDIT_IN_LIST'] === 'N'
135 && (
136 empty($userFieldFata['MANDATORY'])
137 || $userFieldFata['MANDATORY'] !== 'Y'
138 )
139 )
140 {
141 unset($result['GROUP_PROPERTIES'][$field]);
142 continue;
143 }
144
145 $result['GROUP_PROPERTIES'][$field]['EDIT_FORM_LABEL'] = (
146 (string)$userFieldFata['EDIT_FORM_LABEL'] !== ''
147 ? $userFieldFata['EDIT_FORM_LABEL']
148 : $userFieldFata['FIELD_NAME']
149 );
150 $result['GROUP_PROPERTIES'][$field]['EDIT_FORM_LABEL'] = htmlspecialcharsEx($result['GROUP_PROPERTIES'][$field]['EDIT_FORM_LABEL']);
151 $result['GROUP_PROPERTIES'][$field]['~EDIT_FORM_LABEL'] = $result['GROUP_PROPERTIES'][$field]['EDIT_FORM_LABEL'];
152 }
153 }
154
155 public static function processWorkgroupData(&$groupId, &$groupPropertiesList = [], &$groupData = [], $tab = false): void
156 {
157 global $USER;
158
159 $currentUserId = (int)$USER->getId();
160 $currentAdmin = \CSocNetUser::isCurrentUserModuleAdmin();
161 $groupFields = \CSocNetGroup::getById($groupId);
162
163 $canUpdate = \Bitrix\Socialnetwork\Helper\Workgroup\Access::canUpdate([
164 'groupId' => $groupId,
165 ]);
166
167 $groupPerms = \Bitrix\Socialnetwork\Helper\Workgroup::getPermissions([
168 'groupId' => $groupId,
169 ]);
170
171 if (
172 $groupFields
173 && (
174 (
175 $tab === 'edit'
176 && $canUpdate
177 )
178 || (
179 $tab === 'invite'
180 && (
181 $currentAdmin
182 || $groupPerms['UserCanInitiate']
183 || $groupPerms['UserCanModifyGroup']
184 )
185 )
186 )
187 )
188 {
189 $groupData['NAME'] = $groupFields['NAME'];
190 $groupData['DESCRIPTION'] = $groupFields["DESCRIPTION"];
191 $groupData['IMAGE_ID_DEL'] = 'N';
192 $groupData['SUBJECT_ID'] = $groupFields['SUBJECT_ID'];
193 $groupData['VISIBLE'] = $groupFields['VISIBLE'];
194 $groupData['OPENED'] = $groupFields['OPENED'];
195 $groupData['CLOSED'] = $groupFields['CLOSED'];
196 $groupData['PROJECT'] = ($groupFields['PROJECT'] === 'Y' ? 'Y' : 'N');
197 $groupData['PROJECT_DATE_START'] = ($groupData['PROJECT'] === 'Y' ? $groupFields['PROJECT_DATE_START'] : false);
198 $groupData['PROJECT_DATE_FINISH'] = ($groupData['PROJECT'] === 'Y' ? $groupFields['PROJECT_DATE_FINISH'] : false);
199 $groupData['KEYWORDS'] = $groupFields['KEYWORDS'];
200 $groupData['OWNER_ID'] = $groupFields['OWNER_ID'];
201 $groupData['INITIATE_PERMS'] = $groupFields['INITIATE_PERMS'];
202 $groupData['SPAM_PERMS'] = $groupFields['SPAM_PERMS'];
203 $groupData['IMAGE_ID'] = $groupFields['IMAGE_ID'];
204 $groupData['IMAGE_ID_FILE'] = \CFile::getFileArray($groupFields['IMAGE_ID']);
205 $groupData['IMAGE_ID_IMG'] = '<img src="' . ($groupData['IMAGE_ID_FILE'] != false ? $groupData['IMAGE_ID_FILE']['SRC'] : '/bitrix/images/1.gif') . '" height="60" class="sonet-group-create-popup-image" id="sonet_group_create_popup_image" border="0">';
206 $groupData['MODERATOR_IDS'] = [];
207 $groupData['LANDING'] = ($groupFields['LANDING'] === 'Y' ? 'Y' : 'N');
208 $groupData['SCRUM_OWNER_ID'] = ($groupFields['SCRUM_OWNER_ID'] ?: null);
209 $groupData['SCRUM_MASTER_ID'] = ($groupFields['SCRUM_MASTER_ID'] ?: null);
210 $groupData['SCRUM_SPRINT_DURATION'] = ($groupFields['SCRUM_SPRINT_DURATION'] ?: null);
211 $groupData['SCRUM_TASK_RESPONSIBLE'] = ($groupFields['SCRUM_TASK_RESPONSIBLE'] ?: null);
212 $groupData['AVATAR_TYPE'] = (string)($groupFields['AVATAR_TYPE'] ?? '');
213
214 foreach (array_keys($groupPropertiesList) as $field)
215 {
216 if (!isset($groupFields[$field]))
217 {
218 continue;
219 }
220
221 $groupPropertiesList[$field]['VALUE'] = $groupFields['~' . $field];
222 $groupPropertiesList[$field]['ENTITY_VALUE_ID'] = $groupFields['ID'];
223 }
224
225 $groupData['IS_EXTRANET_GROUP'] = (
226 Loader::includeModule('extranet')
227 && \CExtranet::isExtranetSocNetGroup($groupId)
228 ? 'Y'
229 : 'N'
230 );
231
232 $res = UserToGroupTable::getList([
233 'filter' => [
235 'GROUP_ID' => $groupId,
236 ],
237 'select' => [ 'USER_ID' ]
238 ]);
239 while ($relation = $res->fetch())
240 {
241 $groupData['MODERATOR_IDS'][] = (int)$relation['USER_ID'];
242 }
243 }
244 else
245 {
246 $groupData['VISIBLE'] = 'Y';
247 $groupData['IS_EXTRANET_GROUP'] = 'N';
248 $groupId = 0;
249 }
250 }
251
252 public static function processWorkgroupFeatures($groupId, &$featuresList): void
253 {
254 $result = [];
255
256 if ((int)$groupId > 0)
257 {
258 $res = \CSocNetFeatures::getList(
259 [],
260 [
261 'ENTITY_ID' => $groupId,
262 'ENTITY_TYPE' => SONET_ENTITY_GROUP,
263 ]
264 );
265 while ($featureFields = $res->GetNext())
266 {
267 $result[$featureFields['FEATURE']] = $featureFields;
268 }
269 }
270
271 $allowedFeaturesList = \CSocNetAllowed::getAllowedFeatures();
272
273 $sampleKeysList = [
274 'tasks' => 1,
275 'calendar' => 2,
276 'files' => 3,
277 'chat' => 4,
278 'forum' => 5,
279 'microblog' => 6,
280 'blog' => 7,
281 'photo' => 8,
282 'group_lists' => 9,
283 'wiki' => 10,
284 'content_search' => 11,
285 'marketplace' => 12,
286 ];
287
288 uksort($allowedFeaturesList, static function($a, $b) use ($sampleKeysList) {
289
290 $valA = ($sampleKeysList[$a] ?? 100);
291 $valB = ($sampleKeysList[$b] ?? 100);
292
293 if ($valA > $valB)
294 {
295 return 1;
296 }
297
298 if ($valA < $valB)
299 {
300 return -1;
301 }
302
303 return 0;
304 });
305
306 foreach ($allowedFeaturesList as $feature => $featureData)
307 {
308 if (
309 !is_array($featureData['allowed'])
310 || !in_array(SONET_ENTITY_GROUP, $featureData['allowed'], true)
311 )
312 {
313 continue;
314 }
315
316 if ((int)$groupId === 0)
317 {
318 $result[$feature]['ACTIVE'] = (
319 $feature === 'chat'
320 ? \CUserOptions::getOption('socialnetwork', 'default_chat_create_default', 'Y')
321 : Option::get('socialnetwork', 'default_' . $feature . '_create_default', 'Y', SITE_ID)
322 );
323 }
324
325 $featuresList[$feature] = [
326 'FeatureName' => (
327 isset($result[$feature])
328 ? ($result[$feature]['FEATURE_NAME'] ?? '')
329 : false
330 ),
331 'Active' => (!isset($result[$feature]) || $result[$feature]['ACTIVE'] === 'Y')
332 ];
333 }
334 }
335
336}
static processWorkgroupData(&$groupId, &$groupPropertiesList=[], &$groupData=[], $tab=false)
static processWorkgroupFeatures($groupId, &$featuresList)