Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entities.php
1<?php
9
13
14Loc::loadMessages(__FILE__);
15
17{
20
21 public static function getData($options = array())
22 {
23 $result = array(
24 'ITEMS' => array(),
25 'ITEMS_LAST' => array(),
26 'DEST_SORT' => array(),
27 'ADDITIONAL_INFO' => array()
28 );
29
30 $filterParams = array(
31 "DEST_CONTEXT" => $options["context"],
32 "ALLOW_EMAIL_INVITATION" => (isset($options["allowEmailInvitation"]) && $options["allowEmailInvitation"] == "Y")
33 );
34
35 if (!empty($options['contextCode']))
36 {
37 $filterParams["CODE_TYPE"] = $options['contextCode'];
38 }
39
40 $dataAdditional = array();
41 $destSortData = \CSocNetLogDestination::getDestinationSort($filterParams, $dataAdditional);
42 $result["DEST_SORT"] = $destSortData;
43 $lastItems = $items = array();
44 \CSocNetLogDestination::fillLastDestination(
45 $destSortData,
46 $lastItems,
47 array(
48 "EMAILS" => (
49 (
50 isset($options["allowAddUser"])
51 && $options["allowAddUser"] == 'Y'
52 )
53 || (
54 isset($options["allowSearchEmailUsers"])
55 && $options["allowSearchEmailUsers"] == 'Y'
56 )
57 || (
58 isset($options["allowEmailInvitation"])
59 && $options["allowEmailInvitation"] == 'Y'
60 )
61 ? 'Y'
62 : 'N'
63 ),
64 "DATA_ADDITIONAL" => $dataAdditional
65 )
66 );
67
68 if (
70 && \Bitrix\Socialnetwork\ComponentHelper::getAllowToAllDestination()
71 && (!isset($options["enableAll"]) || $options["enableAll"] != 'N')
72 )
73 {
74 $lastItems['GROUPS'] = array(
75 'UA' => true
76 );
77 $items['GROUPS'] = array(
78 'UA' => array(
79 'id' => 'UA',
80 'name' => (
81 ModuleManager::isModuleInstalled('intranet')
82 ? Loc::getMessage("MPF_DESTINATION_3")
83 : Loc::getMessage("MPF_DESTINATION_4")
84 )
85 )
86 );
87 }
88
89 $result["ITEMS_LAST"] = $lastItems;
90
91 if ($options["enableSonetgroups"] != 'N')
92 {
93 $limitReached = false;
94 $sonetGroupsList = \Bitrix\Socialnetwork\ComponentHelper::getSonetGroupAvailable(array(
95 'limit' => 100
96 ), $limitReached);
97
98 $result["SONETGROUPS_LIMITED"] = ($limitReached ? 'Y' : 'N');
99
100 if(
101 !empty($lastItems['SONETGROUPS'])
102 && !empty($sonetGroupsList)
103 )
104 {
105 $lastSonetGroupsList = array();
106 foreach ($lastItems['SONETGROUPS'] as $value)
107 {
108 if (!array_key_exists($value, $sonetGroupsList))
109 {
110 $lastSonetGroupsList[] = intval(mb_substr($value, 2));
111 }
112 }
113 if (!empty($lastSonetGroupsList))
114 {
115 $sonetGroupsAdditionalList = \CSocNetLogDestination::getSocnetGroup(array(
116 'features' => array("blog", array("premoderate_post", "moderate_post", "write_post", "full_post")),
117 'id' => $lastSonetGroupsList
118 ));
119 if (!empty($sonetGroupsAdditionalList))
120 {
121 $sonetGroupsList = array_merge($sonetGroupsList, $sonetGroupsAdditionalList);
122 }
123 }
124 }
125 $items['SONETGROUPS'] = $sonetGroupsList;
126 }
127
129 {
130 $result['EXTRANET_USER'] = 'Y';
131 $items['USERS'] = \CSocNetLogDestination::getExtranetUser();
132 }
133 else
134 {
135 $lastUserList = array();
136 if(!empty($lastItems['USERS']))
137 {
138 foreach ($lastItems['USERS'] as $value)
139 {
140 $lastUserList[] = str_replace('U', '', $value);
141 }
142 }
143
144 $result['EXTRANET_USER'] = 'N';
145 if (!empty($lastUserList))
146 {
147 $items['USERS'] = \CSocNetLogDestination::getUsers(array(
148 'id' => $lastUserList,
149 'CRM_ENTITY' => ModuleManager::isModuleInstalled('crm')
150 ));
151 if (
152 isset($options['extranetContext'])
153 && in_array($options['extranetContext'], array(self::EXTRANET_CONTEXT_INTERNAL, self::EXTRANET_CONTEXT_EXTERNAL))
154 )
155 {
156 foreach($items['USERS'] as $key => $value)
157 {
158 if (isset($value["isExtranet"]))
159 {
160 if (
161 (
162 $value["isExtranet"] == 'Y'
163 && $options['extranetContext'] == self::EXTRANET_CONTEXT_INTERNAL
164 )
165 || (
166 $value["isExtranet"] == 'N'
167 && $options['extranetContext'] == self::EXTRANET_CONTEXT_EXTERNAL
168 )
169 )
170 {
171 unset($items['USERS'][$key]);
172 }
173 }
174 }
175 }
176 }
177
178 if (
179 (
180 isset($options["allowAddUser"])
181 && $options["allowAddUser"] == 'Y'
182 )
183 || (
184 isset($options["allowSearchEmailUsers"])
185 && $options["allowSearchEmailUsers"] == 'Y'
186 )
187 || (
188 isset($options["allowEmailInvitation"])
189 && $options["allowEmailInvitation"] == 'Y'
190 )
191 )
192 {
193 $items['LAST'] = $result["ITEMS_LAST"];
194 \CSocNetLogDestination::fillEmails($items);
195 $result["ITEMS_LAST"] = $items['LAST'];
196 unset($items['LAST']);
197 }
198 }
199
200 if (
201 $options["enableDepartments"] == "Y"
202 && ModuleManager::isModuleInstalled('intranet')
204 )
205 {
206 $structure = \CSocNetLogDestination::getStucture(array("LAZY_LOAD" => true));
207 $items['DEPARTMENT'] = $structure['department'];
208 $items['DEPARTMENT_RELATION'] = $structure['department_relation'];
209 $result['ADDITIONAL_INFO']['DEPARTMENT'] = array(
210 'PREFIX' => 'DR',
211 'TYPE' => 'tree'
212 );
213 }
214
215 $result["ITEMS"] = $items;
216
217 $lastItems = array();
218 foreach($result["ITEMS_LAST"] as $group => $items)
219 {
220 $i = 0;
221 foreach($result["ITEMS_LAST"][$group] as $key => $value)
222 {
223 $lastItems[$group][$key] = ++$i;
224 }
225 }
226 $result["ITEMS_LAST"] = $lastItems;
227
228 return $result;
229 }
230
231 public static function getList($params = array())
232 {
233 $itemsSelected = $params['itemsSelected'];
234
235 $entities = array(
236 'USERS' => array(),
237 'SONETGROUPS' => array(),
238 'GROUPS' => array(),
239 'DEPARTMENTS' => array()
240 );
241
242 $sonetGroupIdList = $userIdList = $departmentIdList = array();
243 foreach ($itemsSelected as $code => $entityGroup)
244 {
245 if ($entityGroup == 'users')
246 {
247 $userIdList[] = str_replace('U', '', $code);
248 }
249 elseif ($entityGroup == 'sonetgroups')
250 {
251 $sonetGroupIdList[] = str_replace('SG', '', $code);
252 }
253 elseif ($entityGroup == 'department')
254 {
255 $departmentIdList[] = str_replace('DR', '', $code);
256 }
257 }
258
259 if (!empty($userIdList))
260 {
261 $entities['USERS'] = self::getUsers(array('id' => $userIdList));
262 }
263
264 if (!empty($sonetGroupIdList))
265 {
266 $entities['SONETGROUPS'] = self::getSonetgroups(array('id' => $sonetGroupIdList));
267 }
268
269 if (!empty($departmentIdList))
270 {
271 $entities['DEPARTMENTS'] = self::getDepartments(array('id' => $departmentIdList));
272 }
273
274 if (
277 )
278 {
279 $entities['GROUPS'] = array(
280 'UA' => array(
281 'id' => 'UA',
282 'name' => (
283 ModuleManager::isModuleInstalled('intranet')
284 ? Loc::getMessage("MPF_DESTINATION_3")
285 : Loc::getMessage("MPF_DESTINATION_4")
286 )
287 )
288 );
289 }
290 else
291 {
292 $entities['GROUPS'] = array();
293 }
294
295 return $entities;
296 }
297
298 protected static function getUsers($params = array())
299 {
300 return \CSocNetLogDestination::getUsers($params);
301 }
302
303 protected static function getSonetgroups($params = array())
304 {
305 return \CSocNetLogDestination::getSocnetGroup($params);
306 }
307
308 protected static function getDepartments($params = array())
309 {
310 $result = array();
311 if (
312 !empty($params['id'])
313 && is_array($params['id'])
314 && Loader::includeModule('intranet')
315 )
316 {
317 $departmentsList = \CIntranetUtils::getDepartmentsData($params['id']);
318 foreach($departmentsList as $id => $name)
319 {
320 $result['DR'.$id] = array(
321 'id' => 'DR'.$id,
322 'entityId' => $id,
323 'name' => htmlspecialcharsbx($name),
324 'parent' => false
325 );
326 }
327 }
328
329 return $result;
330 }
331
332 public static function getDepartmentData($requestFields = []): array
333 {
334 $allowSearchSelf = (!isset($requestFields['allowSearchSelf']) || $requestFields['allowSearchSelf'] !== 'N');
335
336 return [
337 'USERS' => \CSocNetLogDestination::getUsers([
338 'deportament_id' => $requestFields['DEPARTMENT_ID'],
339 'NAME_TEMPLATE' => Handler::getNameTemplate($requestFields),
340 ], $allowSearchSelf),
341 'leafEntityType' => 'USERS',
342 'dataOnly' => true,
343 ];
344 }
345}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29