Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sonetgroups.php
1<?
3
8
10{
11 public static function getFeatureOperations($feature = false)
12 {
13 $result = [];
14 if (!$feature)
15 {
16 return $result;
17 }
18
19 switch($feature)
20 {
21 case 'blog':
22 $result = [ 'premoderate_post', 'moderate_post', 'write_post', 'full_post' ];
23 break;
24 default:
25 $result = [];
26 }
27
28 return $result;
29 }
30
31 public function getData($params = array())
32 {
33 $result = array(
34 'ITEMS' => array(),
35 'ITEMS_LAST' => array(),
36 'ITEMS_HIDDEN' => array(),
37 'ADDITIONAL_INFO' => array(
38 'GROUPS_LIST' => array(
39 'sonetgroups' => array(
40 'TITLE' => Loc::getMessage('MAIN_UI_SELECTOR_TITLE_SONETGROUPS'),
41 'TYPE_LIST' => array(Handler::ENTITY_TYPE_SONETGROUPS),
42 'DESC_LESS_MODE' => 'Y',
43 'SORT' => 20
44 )
45 ),
46 'SORT_SELECTED' => 300
47 )
48 );
49
51
52 $options = (!empty($params['options']) ? $params['options'] : array());
53
54 $lastItems = (!empty($params['lastItems']) ? $params['lastItems'] : array());
55 $selectedItems = (!empty($params['selectedItems']) ? $params['selectedItems'] : array());
56
57 $limitReached = false;
58
59 $filter = array(
60 'limit' => 100,
61 'useProjects' => (!empty($options['enableProjects']) ? $options['enableProjects'] : 'N')
62 );
63
64 if (!empty($options['siteId']))
65 {
66 $filter['siteId'] = $options['siteId'];
67 }
68
69 if (
70 !empty($options['landing'])
71 && ModuleManager::isModuleInstalled('landing')
72 )
73 {
74 $filter['landing'] = $options['landing'];
75 }
76
77 $sonetGroupsList = \Bitrix\Socialnetwork\ComponentHelper::getSonetGroupAvailable($filter, $limitReached);
78
79 if (
80 !empty($options['enableProjects'])
81 && $options['enableProjects'] == 'Y'
82 )
83 {
84 $sonetGroupsList = $sonetGroupsList['SONETGROUPS'];
85 }
86
87 $result['ADDITIONAL_INFO']['LIMITED'] = ($limitReached ? 'Y' : 'N');
88
89 $lastSonetGroupsList = array();
90 if(!empty($lastItems[$entityType]))
91 {
92 $result["ITEMS_LAST"] = array_values($lastItems[$entityType]);
93 foreach ($lastItems[$entityType] as $value)
94 {
95 $lastSonetGroupsList[] = str_replace('SG', '', $value);
96 }
97 }
98
99 $selectedSonetGroupsList = array();
100 if(!empty($selectedItems[Handler::ENTITY_TYPE_SONETGROUPS]))
101 {
102 foreach ($selectedItems[Handler::ENTITY_TYPE_SONETGROUPS] as $value)
103 {
104 $selectedSonetGroupsList[] = str_replace('SG', '', $value);
105 }
106 }
107
108 if (!empty($lastSonetGroupsList))
109 {
110 $filter = array(
111 'id' => $lastSonetGroupsList,
112 'useProjects' => (!empty($options['enableProjects']) ? $options['enableProjects'] : 'N')
113 );
114
115 if (!empty($options['feature']))
116 {
117 $feature = $options['feature'];
118 if (trim($feature) <> '')
119 {
120 $operations = self::getFeatureOperations($feature);
121 if (!empty($operations))
122 {
123 $filter['features'] = [ $feature, $operations ];
124 }
125 }
126 }
127
128 if (
129 !empty($options['landing'])
130 && ModuleManager::isModuleInstalled('landing')
131 )
132 {
133 $filter['landing'] = $options['landing'];
134 }
135 if (!empty($options['siteId']))
136 {
137 $filter['site_id'] = $options['siteId'];
138 }
139
140 $sonetGroupsAdditionalList = \CSocNetLogDestination::getSocnetGroup($filter);
141 if (!empty($sonetGroupsAdditionalList))
142 {
143 if (
144 !empty($options['enableProjects'])
145 && $options['enableProjects'] == 'Y'
146 )
147 {
148 $sonetGroupsAdditionalList = $sonetGroupsAdditionalList['SONETGROUPS'];
149 }
150
151 $sonetGroupsList = array_merge($sonetGroupsList, $sonetGroupsAdditionalList);
152 }
153 }
154
155 if (!empty($selectedSonetGroupsList))
156 {
157 $filter = array(
158 'id' => $selectedSonetGroupsList,
159 'useProjects' => (!empty($options['enableProjects']) ? $options['enableProjects'] : 'N')
160 );
161
162 if (!empty($options['feature']))
163 {
164 $feature = $options['feature'];
165 if (trim($feature) <> '')
166 {
167 $operations = self::getFeatureOperations($feature);
168 if (!empty($operations))
169 {
170 $filter['features'] = [ $feature, $operations ];
171 }
172 }
173 }
174
175 if (
176 !empty($options['landing'])
177 && ModuleManager::isModuleInstalled('landing')
178 )
179 {
180 $filter['landing'] = $options['landing'];
181 }
182 if (!empty($options['siteId']))
183 {
184 $filter['site_id'] = $options['siteId'];
185 }
186
187 $sonetGroupsAdditionalList = \CSocNetLogDestination::getSocnetGroup($filter);
188 if (!empty($sonetGroupsAdditionalList))
189 {
190 if (
191 !empty($options['enableProjects'])
192 && $options['enableProjects'] == 'Y'
193 )
194 {
195 $sonetGroupsAdditionalList = $sonetGroupsAdditionalList['SONETGROUPS'];
196 }
197
198 $sonetGroupsList = array_merge($sonetGroupsList, $sonetGroupsAdditionalList);
199 }
200 }
201
202 if (!empty($selectedItems[Handler::ENTITY_TYPE_SONETGROUPS]))
203 {
204 $hiddenItemsList = array_diff($selectedItems[Handler::ENTITY_TYPE_SONETGROUPS], array_keys($sonetGroupsList));
205 $hiddenItemsList = array_map(function($code) { return preg_replace('/^SG(\d+)$/', '$1', $code); }, $hiddenItemsList);
206
207 if (!empty($hiddenItemsList))
208 {
209 $filter = array(
210 "@ID" => $hiddenItemsList
211 );
212
213 if (
214 !empty($options['enableProjects'])
215 && $options['enableProjects'] == 'Y'
216 )
217 {
218 $filter['PROJECT'] = 'N';
219 }
220
221 $isCurrentUserModuleAdmin = \CSocNetUser::isCurrentUserModuleAdmin();
222 $res = \Bitrix\Socialnetwork\WorkgroupTable::getList(array(
223 'filter' => $filter,
224 'select' => array("ID", "NAME", "DESCRIPTION", "OPENED", "VISIBLE")
225 ));
226
227 $extranetGroupsIdList = \Bitrix\Socialnetwork\ComponentHelper::getExtranetSonetGroupIdList();
228
229 while($groupFields = $res->fetch())
230 {
231 if (
232 (
233 $groupFields['OPENED'] == "Y"
234 || $isCurrentUserModuleAdmin
235 )
237 )
238 {
239 $sonetGroupsList['SG'.$groupFields["ID"]] = array(
240 "id" => 'SG'.$groupFields["ID"],
241 "entityId" => $groupFields["ID"],
242 "name" => $groupFields["NAME"],
243 "desc" => $groupFields["DESCRIPTION"],
244 "isExtranet" => (in_array($groupFields["ID"], $extranetGroupsIdList) ? 'Y' : 'N')
245 );
246 }
247 elseif (
248 $groupFields['VISIBLE'] == "Y"
250 )
251 {
252 $sonetGroupsList['SG'.$groupFields["ID"]] = array(
253 "id" => 'SG'.$groupFields["ID"],
254 "entityId" => $groupFields["ID"],
255 "name" => $groupFields["NAME"],
256 "desc" => $groupFields["DESCRIPTION"],
257 "isExtranet" => (in_array($groupFields["ID"], $extranetGroupsIdList) ? 'Y' : 'N'),
258 "selectable" => 'N'
259 );
260 }
261 else
262 {
263 $result['ITEMS_HIDDEN'][] = 'SG'.$groupFields["ID"];
264 }
265 }
266 }
267 }
268
269 $result['ITEMS'] = $sonetGroupsList;
270
271 return $result;
272 }
273
274 public function getTabList($params = array())
275 {
276 $options = (!empty($params['options']) ? $params['options'] : array());
277
278 return array(
279 array(
280 'id' => 'sonetgroups',
281 'name' => Loc::getMessage('MAIN_UI_SELECTOR_TAB_SONETGROUPS'),
282 'sort' => 30
283 )
284 );
285 }
286
287 public function search($params = array())
288 {
289 $result = array(
290 'ITEMS' => array(),
291 'ADDITIONAL_INFO' => array()
292 );
293
294 $entityOptions = (!empty($params['options']) ? $params['options'] : array());
295 $requestFields = (!empty($params['requestFields']) ? $params['requestFields'] : array());
296
297 if (
298 !empty($entityOptions['additionalData'])
299 && !empty($entityOptions['additionalData']['LIMITED'])
300 && $entityOptions['additionalData']['LIMITED'] = 'Y'
301 )
302 {
303 $filter = array(
304 "SEARCH" => $requestFields['searchString'],
305 "LANDING" => (!empty($entityOptions['landing']) && ModuleManager::isModuleInstalled('landing') && $entityOptions['landing'] == 'Y' ? 'Y' : 'N')
306 );
307
308 if (!empty($entityOptions['feature']))
309 {
310 $feature = $entityOptions['feature'];
311 if (trim($feature) <> '')
312 {
313 $operations = self::getFeatureOperations($feature);
314 if (!empty($operations))
315 {
316 $filter['FEATURES'] = [ $feature, $operations ];
317 }
318 }
319 }
320
321 if (!empty($entityOptions['siteId']))
322 {
323 $filter['SITE_ID'] = $entityOptions['siteId'];
324 }
325 $result["ITEMS"] = \CSocNetLogDestination::searchSonetGroups($filter);
326 }
327
328 return $result;
329 }
330
331 public function getItemName($itemCode = '')
332 {
333 return \Bitrix\Socialnetwork\Integration\Main\UISelector\SonetGroups::getWorkgroupName($itemCode);
334 }
335
336 public static function getWorkgroupName($itemCode = '')
337 {
338 global $USER;
339
340 $result = '';
341
342 $entityId = (
343 preg_match('/^SG(\d+)$/i', $itemCode, $matches)
344 && intval($matches[1]) > 0
345 ? intval($matches[1])
346 : 0
347 );
348
349 if ($entityId > 0)
350 {
351 $res = WorkgroupTable::getList(array(
352 'filter' => array(
353 '=ID' => $entityId
354 ),
355 'select' => array('VISIBLE', 'NAME')
356 ));
357 if (
358 ($workgroupFields = $res->fetch())
359 && ($workgroupFields["VISIBLE"] == "Y")
360 || (\CSocNetUser::isCurrentUserModuleAdmin(SITE_ID, false))
361 )
362 {
363 $result = $workgroupFields['NAME'];
364 }
365
366 if (empty($result))
367 {
368 $res = UserToGroupTable::getList(
369 array(
370 'filter' => array(
371 '=GROUP_ID' => $entityId,
372 '=USER_ID' => $USER->getId()
373 ),
374 'select' => array(
375 'GROUP_ID',
376 'GROUP_NAME' => 'GROUP.NAME'
377 )
378 )
379 );
380 if ($relationFields = $res->fetch())
381 {
382 $result = $relationFields['GROUP_NAME'];
383 }
384 }
385 }
386
387 return $result;
388 }
389
390
391}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29