1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
lists.php
См. документацию.
1<?php
2
5use Bitrix\Disk\Uf\FileUserType;
6use Bitrix\Disk\AttachedObject;
7use Bitrix\Disk\File;
11
12Loc::loadMessages(__FILE__);
13
14class CLists
15{
16 private static $iblockTypeList = array(
17 "lists" => true,
18 "bitrix_processes" => true,
19 "lists_socnet" => true
20 );
21
22 private static $featuresCache = array();
23
24 public static function SetPermission($iblock_type_id, $arGroups)
25 {
26 global $DB, $CACHE_MANAGER;
27
28 $grp = array();
29 foreach($arGroups as $group_id)
30 {
31 $group_id = intval($group_id);
32 if($group_id)
33 $grp[$group_id] = $group_id;
34 }
35
36 $DB->Query("
37 delete from b_lists_permission
38 where IBLOCK_TYPE_ID = '".$DB->ForSQL($iblock_type_id)."'
39 ");
40 if(count($grp))
41 {
42 $DB->Query("
43 insert into b_lists_permission
44 select ibt.ID, ug.ID
45 from
46 b_iblock_type ibt
47 ,b_group ug
48 where
49 ibt.ID = '".$DB->ForSQL($iblock_type_id)."'
50 and ug.ID in (".implode(", ", $grp).")
51 ");
52 }
53
54 if(CACHED_b_lists_permission !== false)
55 $CACHE_MANAGER->Clean("b_lists_permission");
56 }
57
58 public static function GetPermission($iblock_type_id = false)
59 {
60 global $DB, $CACHE_MANAGER;
61
62 $arResult = false;
63 if(CACHED_b_lists_permission !== false)
64 {
65 if($CACHE_MANAGER->Read(CACHED_b_lists_permission, "b_lists_permission"))
66 $arResult = $CACHE_MANAGER->Get("b_lists_permission");
67 }
68
69 if($arResult === false)
70 {
71 $arResult = array();
72 $res = $DB->Query("select IBLOCK_TYPE_ID, GROUP_ID from b_lists_permission");
73 while($ar = $res->Fetch())
74 $arResult[$ar["IBLOCK_TYPE_ID"]][] = $ar["GROUP_ID"];
75
76 if(CACHED_b_lists_permission !== false)
77 $CACHE_MANAGER->Set("b_lists_permission", $arResult);
78 }
79
80 if ($iblock_type_id === false)
81 {
82 return $arResult;
83 }
84 else
85 {
86 return $arResult[$iblock_type_id] ?? false;
87 }
88 }
89
90 public static function GetDefaultSocnetPermission()
91 {
92 return array(
93 "A" => "X", //Group owner
94 "E" => "W", //Group moderator
95 "K" => "W", //Group member
96 "L" => "D", //Authorized users
97 "N" => "D", //Everyone
98 "T" => "D", //Banned
99 "Z" => "D", //Request?
100 );
101 }
102
103 public static function SetSocnetPermission($iblock_id, $arRoles)
104 {
105 global $DB, $CACHE_MANAGER;
106 $iblock_id = intval($iblock_id);
107
109 foreach($arToDB as $role => $permission)
110 if(isset($arRoles[$role]))
111 $arToDB[$role] = mb_substr($arRoles[$role], 0, 1);
112 $arToDB["A"] = "X"; //Group owner always in charge
113 $arToDB["T"] = "D"; //Banned
114 $arToDB["Z"] = "D"; //and Request never get to list
115
116 $DB->Query("
117 delete from b_lists_socnet_group
118 where IBLOCK_ID = ".$iblock_id."
119 ");
120 foreach($arToDB as $role => $permission)
121 {
122 $DB->Query("
123 insert into b_lists_socnet_group
124 (IBLOCK_ID, SOCNET_ROLE, PERMISSION)
125 values
126 (".$iblock_id.", '".$role."', '".$permission."')
127 ");
128 }
129
130 if(CACHED_b_lists_permission !== false)
131 $CACHE_MANAGER->Clean("b_lists_perm".$iblock_id);
132 }
133
134 public static function GetSocnetPermission($iblock_id)
135 {
136 global $DB, $CACHE_MANAGER;
137 $iblock_id = (int)$iblock_id;
138
139 $arCache = array();
140 if(!array_key_exists($iblock_id, $arCache))
141 {
142 $arCache[$iblock_id] = CLists::GetDefaultSocnetPermission();
143
144 if(CACHED_b_lists_permission !== false)
145 {
146 $cache_id = "b_lists_perm".$iblock_id;
147
148 if($CACHE_MANAGER->Read(CACHED_b_lists_permission, $cache_id))
149 {
150 $arCache[$iblock_id] = $CACHE_MANAGER->Get($cache_id);
151 }
152 else
153 {
154 $res = $DB->Query("
155 select SOCNET_ROLE, PERMISSION
156 from b_lists_socnet_group
157 where IBLOCK_ID=".$iblock_id."
158 ");
159 while($ar = $res->Fetch())
160 $arCache[$iblock_id][$ar["SOCNET_ROLE"]] = $ar["PERMISSION"];
161
162 $CACHE_MANAGER->Set($cache_id, $arCache[$iblock_id]);
163 }
164 }
165 else
166 {
167 $res = $DB->Query("
168 select SOCNET_ROLE, PERMISSION
169 from b_lists_socnet_group
170 where IBLOCK_ID=".$iblock_id."
171 ");
172 while($ar = $res->Fetch())
173 $arCache[$iblock_id][$ar["SOCNET_ROLE"]] = $ar["PERMISSION"];
174 }
175
176 $arCache[$iblock_id]["A"] = "X"; //Group owner always in charge
177 $arCache[$iblock_id]["T"] = "D"; //Banned
178 $arCache[$iblock_id]["Z"] = "D"; //and Request never get to list
179 }
180
181 return $arCache[$iblock_id];
182 }
183
184 public static function GetIBlockPermission($iblock_id, $user_id)
185 {
186 global $USER;
187
188 //IBlock permissions by default
189 $Permission = CIBlock::GetPermission($iblock_id, $user_id);
190 if($Permission < "W")
191 {
192 $arIBlock = CIBlock::GetArrayByID($iblock_id);
193 if($arIBlock)
194 {
195 //Check if iblock is list
196 $arListsPerm = CLists::GetPermission($arIBlock["IBLOCK_TYPE_ID"]);
197 if (is_array($arListsPerm) && count($arListsPerm) > 0)
198 {
199 //User groups
200 if($user_id == $USER->GetID())
201 $arUserGroups = $USER->GetUserGroupArray();
202 else
203 $arUserGroups = $USER->GetUserGroup($user_id);
204
205 //One of lists admins
206 if(count(array_intersect($arListsPerm, $arUserGroups)))
207 $Permission = "X";
208 }
209 }
210 }
211
212 if(
213 $Permission < "W"
214 && $arIBlock["SOCNET_GROUP_ID"]
215 && CModule::IncludeModule('socialnetwork')
216 )
217 {
218 $arSocnetPerm = CLists::GetSocnetPermission($iblock_id);
219 $socnet_role = CSocNetUserToGroup::GetUserRole($USER->GetID(), $arIBlock["SOCNET_GROUP_ID"]);
220 $Permission = $arSocnetPerm[$socnet_role];
221 }
222 return $Permission;
223 }
224
225 public static function GetIBlockTypes($language_id = false)
226 {
227 global $DB;
228 $res = $DB->Query("
229 SELECT IBLOCK_TYPE_ID, NAME
230 FROM b_iblock_type_lang
231 WHERE
232 LID = '".$DB->ForSQL($language_id===false? LANGUAGE_ID: $language_id)."'
233 AND EXISTS (
234 SELECT *
235 FROM b_lists_permission
236 WHERE b_lists_permission.IBLOCK_TYPE_ID = b_iblock_type_lang.IBLOCK_TYPE_ID
237 )
238 ");
239 return $res;
240 }
241
242 public static function GetIBlocks($iblock_type_id, $check_permissions, $socnet_group_id = false)
243 {
244 $arOrder = array(
245 "SORT" => "ASC",
246 "NAME" => "ASC",
247 );
248
250 "ACTIVE" => "Y",
251 "SITE_ID" => SITE_ID,
252 "TYPE" => $iblock_type_id,
253 "CHECK_PERMISSIONS" => ($check_permissions? "Y": "N"), //This cancels iblock permissions for trusted users
254 );
255 if($socnet_group_id > 0)
256 $arFilter["=SOCNET_GROUP_ID"] = $socnet_group_id;
257
258 $arResult = array();
259 $rsIBlocks = CIBlock::GetList($arOrder, $arFilter);
260 while($ar = $rsIBlocks->Fetch())
261 {
262 $arResult[$ar["ID"]] = $ar["NAME"];
263 }
264 return $arResult;
265 }
266
267 public static function OnIBlockDelete($iblock_id)
268 {
269 global $DB, $CACHE_MANAGER;
270 $iblock_id = intval($iblock_id);
271
272 $DB->Query("delete from b_lists_url where IBLOCK_ID=".$iblock_id);
273 $DB->Query("delete from b_lists_socnet_group where IBLOCK_ID=".$iblock_id);
274 $CACHE_MANAGER->Clean("b_lists_perm".$iblock_id);
275
277
278 self::deleteLockFeatureOption($iblock_id);
279 }
280
281 public static function OnAfterIBlockUpdate(array &$fields)
282 {
283 if (!empty($fields["RESULT"]))
284 {
285 self::deleteListsCache('/lists/crm/attached/');
286 }
287 }
288
289 public static function OnAfterIBlockDelete($iblock_id)
290 {
291 if (CModule::includeModule('bizproc'))
292 {
293 BizProcDocument::deleteDataIblock($iblock_id);
294 }
295 }
296
297 public static function IsEnabledSocnet()
298 {
299 $bActive = false;
300 foreach (GetModuleEvents("socialnetwork", "OnFillSocNetFeaturesList", true) as $arEvent)
301 {
302 if(
303 $arEvent["TO_MODULE_ID"] == "lists"
304 && $arEvent["TO_CLASS"] == "CListsSocnet"
305 )
306 {
307 $bActive = true;
308 break;
309 }
310 }
311 return $bActive;
312 }
313
314 public static function EnableSocnet($bActive = false)
315 {
316 if($bActive)
317 {
319 {
320 RegisterModuleDependences("socialnetwork", "OnFillSocNetFeaturesList", "lists", "CListsSocnet", "OnFillSocNetFeaturesList");
321 RegisterModuleDependences("socialnetwork", "OnFillSocNetMenu", "lists", "CListsSocnet", "OnFillSocNetMenu");
322 RegisterModuleDependences("socialnetwork", "OnParseSocNetComponentPath", "lists", "CListsSocnet", "OnParseSocNetComponentPath");
323 RegisterModuleDependences("socialnetwork", "OnInitSocNetComponentVariables", "lists", "CListsSocnet", "OnInitSocNetComponentVariables");
324 }
325 }
326 else
327 {
329 {
330 UnRegisterModuleDependences("socialnetwork", "OnFillSocNetFeaturesList", "lists", "CListsSocnet", "OnFillSocNetFeaturesList");
331 UnRegisterModuleDependences("socialnetwork", "OnFillSocNetMenu", "lists", "CListsSocnet", "OnFillSocNetMenu");
332 UnRegisterModuleDependences("socialnetwork", "OnParseSocNetComponentPath", "lists", "CListsSocnet", "OnParseSocNetComponentPath");
333 UnRegisterModuleDependences("socialnetwork", "OnInitSocNetComponentVariables", "lists", "CListsSocnet", "OnInitSocNetComponentVariables");
334 }
335 }
336 }
337
338 public static function OnSharepointCreateProperty($arInputFields)
339 {
340 global $DB;
341 $iblock_id = (int)$arInputFields["IBLOCK_ID"];
342 if($iblock_id > 0)
343 {
344 //Check if there is at list one field defined for given iblock
345 $rsFields = $DB->Query("
346 SELECT * FROM b_lists_field
347 WHERE IBLOCK_ID = ".$iblock_id."
348 ORDER BY SORT ASC
349 ");
350 if($rsFields->Fetch())
351 {
352 $arNewFields = array(
353 "SORT" => 500,
354 "NAME" => $arInputFields["SP_FIELD"],
355 );
356
357 if(mb_substr($arInputFields["FIELD_ID"], 0, 9) == "PROPERTY_")
358 {
359 $arNewFields["ID"] = mb_substr($arInputFields["FIELD_ID"], 9);
360 $arNewFields["TYPE"] = "S";
361 }
362 else
363 $arNewFields["TYPE"] = $arInputFields["FIELD_ID"];
364
365 //Publish property on the list
366 $obList = new CList($iblock_id);
367 $obList->AddField($arNewFields);
368 }
369 }
370 }
371
372 public static function OnSharepointCheckAccess($iblock_id)
373 {
374 global $USER;
375 $arIBlock = CIBlock::GetArrayByID($iblock_id);
376 if($arIBlock)
377 {
378 //Check if iblock is list
379 $arListsPerm = CLists::GetPermission($arIBlock["IBLOCK_TYPE_ID"]);
380 if(
381 is_array($arListsPerm)
382 && count($arListsPerm)
383 )
384 {
385 //User groups
386 $arUserGroups = $USER->GetUserGroupArray();
387 //One of lists admins
388 if(count(array_intersect($arListsPerm, $arUserGroups)))
389 return true;
390 else
391 return false;
392 }
393 }
394 }
395
396 public static function setLiveFeed($checked, $iblockId)
397 {
398 global $DB;
399 $iblockId = intval($iblockId);
400 $checked = intval($checked);
401
402 $resultQuery = $DB->Query("SELECT LIVE_FEED FROM b_lists_url WHERE IBLOCK_ID = ".$iblockId);
403 $resultData = $resultQuery->fetch();
404
405 if($resultData)
406 {
407 if($resultData["LIVE_FEED"] != $checked)
408 {
409 $DB->Query("UPDATE b_lists_url SET LIVE_FEED = '".$checked."' WHERE IBLOCK_ID = ".$iblockId);
410 }
411 }
412 else
413 {
414 $url = Option::get('lists', 'livefeed_url') . $iblockId . '/element/#section_id#/#element_id#/';
415 $DB->Query("INSERT INTO b_lists_url (IBLOCK_ID, URL, LIVE_FEED) values (".$iblockId.", '".$DB->ForSQL($url)."', ".$checked.")");
416 }
417 }
418
419 public static function getLiveFeed($iblockId)
420 {
421 global $DB;
422 $iblockId = intval($iblockId);
423
424 $resultQuery = $DB->Query("SELECT LIVE_FEED FROM b_lists_url WHERE IBLOCK_ID = ".$iblockId);
425 $resultData = $resultQuery->fetch();
426
427 if ($resultData)
428 return $resultData["LIVE_FEED"];
429 else
430 return "";
431 }
432
434 {
435 $userId = intval($userId);
436 return CIBlockElement::getList(
437 array(),
438 array('CREATED_BY' => $userId, 'IBLOCK_TYPE' => $iblockTypeId),
439 true,
440 false,
441 array('ID')
442 );
443 }
444
445 public static function generateMnemonicCode($integerCode = 0)
446 {
447 if(!$integerCode)
448 $integerCode = time();
449
450 $code = '';
451 for ($i = 1; $integerCode >= 0 && $i < 10; $i++)
452 {
453 $code = chr(0x41 + ($integerCode % pow(26, $i) / pow(26, $i - 1))) . $code;
454 $integerCode -= pow(26, $i);
455 }
456 return $code;
457 }
458
459 public static function OnAfterIBlockElementDelete($fields)
460 {
461 if (CModule::includeModule('bizproc'))
462 {
463 $errors = array();
464
465 $iblockType = COption::getOptionString("lists", "livefeed_iblock_type_id");
466
467 $iblockQuery = CIBlock::getList(array(), array('ID' => $fields['IBLOCK_ID']));
468 if($iblock = $iblockQuery->fetch())
469 {
470 $iblockType = $iblock["IBLOCK_TYPE_ID"];
471 }
472
474 $listWorkflowId = array();
475 foreach ($states as $workflowId => $state)
476 {
477 $listWorkflowId[] = $workflowId;
478 }
479
480 self::deleteSocnetLog($listWorkflowId);
481
482 CBPDocument::onDocumentDelete(BizprocDocument::getDocumentComplexId($iblockType, $fields['ID']), $errors);
483 }
484
485 $propertyQuery = CIBlockElement::getProperty(
486 $fields['IBLOCK_ID'], $fields['ID'], 'sort', 'asc', array('ACTIVE'=>'Y'));
487 while($property = $propertyQuery->fetch())
488 {
489 $userType = \CIBlockProperty::getUserType($property['USER_TYPE']);
490 if (array_key_exists('DeleteAllAttachedFiles', $userType))
491 {
492 call_user_func_array($userType['DeleteAllAttachedFiles'], array($fields['ID']));
493 }
494 }
495 }
496
505 public static function completeWorkflow($workflowId, $iblockType, $elementId, $iblockId, $action)
506 {
507 if (!Loader::includeModule('bizproc'))
508 {
509 return Loc::getMessage('LISTS_MODULE_BIZPROC_NOT_INSTALLED_MSGVER_1');
510 }
511
512 global $USER;
513 $userId = $USER->getID();
514
515 $documentType = BizprocDocument::generateDocumentComplexType($iblockType, $iblockId);
516 $documentId = BizprocDocument::getDocumentComplexId($iblockType, $elementId);
517 $documentStates = CBPDocument::getDocumentStates($documentType, $documentId);
518
519 $permission = CBPDocument::canUserOperateDocument(
522 $userId,
523 $documentId,
524 array("DocumentStates" => $documentStates)
525 );
526
527 if(!$permission)
528 {
529 return Loc::getMessage('LISTS_ACCESS_DENIED');
530 }
531
532 $stringError = '';
533
534 if($action == 'stop')
535 {
536 $errors = array();
537 CBPDocument::terminateWorkflow(
538 $workflowId,
539 $documentId,
540 $errors
541 );
542
543 if (!empty($errors))
544 {
545 $stringError = '';
546 foreach ($errors as $error)
547 $stringError .= $error['message'];
548 $listError[] = array('id' => 'stopBizproc', 'text' => $stringError);
549 }
550 }
551 else
552 {
553 $errors = CBPDocument::killWorkflow($workflowId);
554 foreach ($errors as $error)
555 {
556 $stringError .= $error['message'];
557 }
558
559 if ($errors)
560 {
561 $listError[] = [
562 'id' => 'stopBizproc',
563 'text' => $stringError
564 ];
565 }
566 }
567
568 if(empty($listError) && Loader::includeModule('socialnetwork') &&
569 $iblockType == COption::getOptionString("lists", "livefeed_iblock_type_id"))
570 {
571 $sourceId = CBPStateService::getWorkflowIntegerId($workflowId);
572 $resultQuery = CSocNetLog::getList(
573 array(),
574 array('EVENT_ID' => 'lists_new_element', 'SOURCE_ID' => $sourceId),
575 false,
576 false,
577 array('ID')
578 );
579 while ($log = $resultQuery->fetch())
580 {
581 CSocNetLog::delete($log['ID']);
582 }
583 }
584
585 if (!empty($listError))
586 {
587 $stringError = implode(PHP_EOL, array_column($listError, 'text'));
588 }
589
590 return $stringError;
591 }
592
593 public static function deleteSocnetLog(array $listWorkflowId)
594 {
595 if(CModule::includeModule('socialnetwork'))
596 {
597 foreach ($listWorkflowId as $workflowId)
598 {
599 $sourceId = CBPStateService::getWorkflowIntegerId($workflowId);
600 $resultQuery = CSocNetLog::getList(
601 array(),
602 array('EVENT_ID' => 'lists_new_element', 'SOURCE_ID' => $sourceId),
603 false,
604 false,
605 array('ID')
606 );
607 while ($log = $resultQuery->fetch())
608 {
609 CSocNetLog::delete($log['ID']);
610 }
611 }
612 }
613 }
614
621 public static function copyIblock($iblockId, array &$errors)
622 {
623 $iblockId = (int)$iblockId;
624 if(!$iblockId)
625 {
626 $errors[] = Loc::getMessage('LISTS_REQUIRED_PARAMETER', array('#parameter#' => 'iblockId'));
627 return false;
628 }
629
630 /* We obtain data on old iblock and add a new iblock */
631 $query = CIBlock::getList(array(), array('ID' => $iblockId), true);
632 $iblock = $query->fetch();
633 if(!$iblock)
634 {
635 $errors[] = Loc::getMessage('LISTS_COPY_IBLOCK_ERROR_GET_DATA');
636 return false;
637 }
638 $iblockMessage = CIBlock::getMessages($iblockId);
639 $iblock = array_merge($iblock, $iblockMessage);
640
641 $iblock['NAME'] = $iblock['NAME'].Loc::getMessage('LISTS_COPY_IBLOCK_NAME_TITLE');
642 if(!empty($iblock['PICTURE']))
643 {
644 $iblock['PICTURE'] = CFile::makeFileArray($iblock['PICTURE']);
645 }
646 if(!empty($iblock['CODE']))
647 {
648 $iblock['CODE'] = $iblock['CODE'].'_copy';
649 }
650 $iblockObject = new CIBlock;
651 if(!$iblockObject)
652 {
653 $errors[] = Loc::getMessage('LISTS_COPY_IBLOCK_ERROR_GET_DATA');
654 return false;
655 }
656 $copyIblockId = $iblockObject->add($iblock);
657 if($copyIblockId)
658 {
659 global $CACHE_MANAGER;
660 $CACHE_MANAGER->ClearByTag('lists_list_'.$copyIblockId);
661 $CACHE_MANAGER->ClearByTag('lists_list_any');
662 $CACHE_MANAGER->CleanDir('menu');
663 }
664 else
665 {
666 $errors[] = Loc::getMessage('LISTS_COPY_IBLOCK_ERROR_GET_DATA');
667 return false;
668 }
669
670 /* Set right */
671 $rights = array();
672 if($iblock['RIGHTS_MODE'] == 'E')
673 {
674 $rightObject = new CIBlockRights($iblockId);
675 $i = 0;
676 foreach($rightObject->getRights() as $right)
677 {
678 $rights['n'.($i++)] = array(
679 'GROUP_CODE' => $right['GROUP_CODE'],
680 'DO_CLEAN' => 'N',
681 'TASK_ID' => $right['TASK_ID'],
682 );
683 }
684 }
685 else
686 {
687 $i = 0;
688 if(!empty($iblock['SOCNET_GROUP_ID']))
689 {
690 $socnetPerm = self::getSocnetPermission($iblockId);
691 foreach($socnetPerm as $role => $permission)
692 {
693 if($permission > "W")
694 $permission = "W";
695 switch($role)
696 {
697 case "A":
698 case "E":
699 case "K":
700 $rights['n'.($i++)] = array(
701 "GROUP_CODE" => "SG".$iblock['SOCNET_GROUP_ID']."_".$role,
702 "IS_INHERITED" => "N",
703 "TASK_ID" => CIBlockRights::letterToTask($permission),
704 );
705 break;
706 case "L":
707 $rights['n'.($i++)] = array(
708 "GROUP_CODE" => "AU",
709 "IS_INHERITED" => "N",
710 "TASK_ID" => CIBlockRights::letterToTask($permission),
711 );
712 break;
713 case "N":
714 $rights['n'.($i++)] = array(
715 "GROUP_CODE" => "G2",
716 "IS_INHERITED" => "N",
717 "TASK_ID" => CIBlockRights::letterToTask($permission),
718 );
719 break;
720 }
721 }
722 }
723 else
724 {
725 $groupPermissions = CIBlock::getGroupPermissions($iblockId);
726 foreach($groupPermissions as $groupId => $permission)
727 {
728 if($permission > 'W')
729 $rights['n'.($i++)] = array(
730 'GROUP_CODE' => 'G'.$groupId,
731 'IS_INHERITED' => 'N',
732 'TASK_ID' => CIBlockRights::letterToTask($permission),
733 );
734 }
735 }
736
737 }
738 $iblock['RIGHTS'] = $rights;
739 $resultIblock = $iblockObject->update($copyIblockId, $iblock);
740 if(!$resultIblock)
741 $errors[] = Loc::getMessage('LISTS_COPY_IBLOCK_ERROR_SET_RIGHT');
742
743 /* Add fields */
744 $listObject = new CList($iblockId);
745 $fields = $listObject->getFields();
746 $copyListObject = new CList($copyIblockId);
747 foreach($fields as $fieldId => $field)
748 {
749 $copyFields = array(
750 'NAME' => $field['NAME'],
751 'SORT' => $field['SORT'],
752 'MULTIPLE' => $field['MULTIPLE'],
753 'IS_REQUIRED' => $field['IS_REQUIRED'],
754 'IBLOCK_ID' => $copyIblockId,
755 'SETTINGS' => $field['SETTINGS'],
756 'DEFAULT_VALUE' => $field['DEFAULT_VALUE'],
757 'TYPE' => $field['TYPE'],
758 'PROPERTY_TYPE' => $field['PROPERTY_TYPE'],
759 );
760
761 if(!$listObject->is_field($fieldId))
762 {
763 if($field['TYPE'] == 'L')
764 {
765 $enum = CIBlockPropertyEnum::getList(array(), array('PROPERTY_ID' => $field['ID']));
766 while($listData = $enum->fetch())
767 {
768 $copyFields['VALUES'][] = array(
769 'XML_ID' => $listData['XML_ID'],
770 'VALUE' => $listData['VALUE'],
771 'DEF' => $listData['DEF'],
772 'SORT' => $listData['SORT']
773 );
774 }
775 }
776
777 $copyFields['CODE'] = $field['CODE'];
778 $copyFields['LINK_IBLOCK_ID'] = $field['LINK_IBLOCK_ID'];
779 if(!empty($field['PROPERTY_USER_TYPE']['USER_TYPE']))
780 $copyFields['USER_TYPE'] = $field['PROPERTY_USER_TYPE']['USER_TYPE'];
781 if(!empty($field['ROW_COUNT']))
782 $copyFields['ROW_COUNT'] = $field['ROW_COUNT'];
783 if(!empty($field['COL_COUNT']))
784 $copyFields['COL_COUNT'] = $field['COL_COUNT'];
785 if(!empty($field['USER_TYPE_SETTINGS']))
786 $copyFields['USER_TYPE_SETTINGS'] = $field['USER_TYPE_SETTINGS'];
787 }
788
789 if($fieldId == 'NAME')
790 {
791 $resultUpdateField = $copyListObject->updateField("NAME", $copyFields);
792 if($resultUpdateField)
793 $copyListObject->save();
794 else
795 $errors[] = Loc::getMessage('LISTS_COPY_IBLOCK_ERROR_ADD_FIELD',
796 array('#field#' => $field['NAME']));
797
798 continue;
799 }
800
801 $copyFieldId = $copyListObject->addField($copyFields);
802 if($copyFieldId)
803 $copyListObject->save();
804 else
805 $errors[] = Loc::getMessage('LISTS_COPY_IBLOCK_ERROR_ADD_FIELD',
806 array('#field#' => $field['NAME']));
807 }
808
809 /* Copy Workflow Template */
810 // Make a copy workflow templates
811
812 return $copyIblockId;
813 }
814
815 public static function checkChangedFields($iblockId, $elementId, array $select, array $elementFields, array $elementProperty)
816 {
817 $changedFields = array();
818 /* We get the new data element. */
819 $elementNewData = array();
820 $elementQuery = CIBlockElement::getList(
821 array(), array('IBLOCK_ID' => $iblockId, '=ID' => $elementId), false, false, $select);
822 $elementObject = $elementQuery->getNextElement();
823
824 if(is_object($elementObject))
825 $elementNewData = $elementObject->getFields();
826
827 $elementOldData = $elementFields;
828 unset($elementNewData["TIMESTAMP_X"]);
829 unset($elementOldData["TIMESTAMP_X"]);
830
831 $elementNewData["PROPERTY_VALUES"] = array();
832 if(is_object($elementObject))
833 {
834 $propertyQuery = CIBlockElement::getProperty(
835 $iblockId,
836 $elementId,
837 array("sort"=>"asc", "id"=>"asc", "enum_sort"=>"asc", "value_id"=>"asc"),
838 array("ACTIVE"=>"Y", "EMPTY"=>"N")
839 );
840 while($property = $propertyQuery->fetch())
841 {
842 $propertyId = $property["ID"];
843 if(!array_key_exists($propertyId, $elementNewData["PROPERTY_VALUES"]))
844 {
845 $elementNewData["PROPERTY_VALUES"][$propertyId] = $property;
846 unset($elementNewData["PROPERTY_VALUES"][$propertyId]["DESCRIPTION"]);
847 unset($elementNewData["PROPERTY_VALUES"][$propertyId]["VALUE_ENUM_ID"]);
848 unset($elementNewData["PROPERTY_VALUES"][$propertyId]["VALUE_ENUM"]);
849 unset($elementNewData["PROPERTY_VALUES"][$propertyId]["VALUE_XML_ID"]);
850 $elementNewData["PROPERTY_VALUES"][$propertyId]["FULL_VALUES"] = array();
851 $elementNewData["PROPERTY_VALUES"][$propertyId]["VALUES_LIST"] = array();
852 }
853
854 $elementNewData["PROPERTY_VALUES"][$propertyId]["FULL_VALUES"][$property["PROPERTY_VALUE_ID"]] = array(
855 "VALUE" => $property["VALUE"],
856 "DESCRIPTION" => $property["DESCRIPTION"],
857 );
858 $elementNewData["PROPERTY_VALUES"][$propertyId]["VALUES_LIST"][$property["PROPERTY_VALUE_ID"]] = $property["VALUE"];
859 }
860 }
861
862 $elementOldData["PROPERTY_VALUES"] = $elementProperty;
863
864 /* Check added or deleted fields. */
865 $listNewFieldIdToDelete = array();
866 $listOldFieldIdToDelete = array();
867 $differences = array_diff_key($elementNewData, $elementOldData);
868 foreach(array_keys($differences) as $fieldId)
869 {
870 if($fieldId[0] === '~')
871 continue;
872 $changedFields[] = $fieldId;
873 $listNewFieldIdToDelete["FIELD"][] = $fieldId;
874 }
875 $differences = array_diff_key($elementOldData, $elementNewData);
876 foreach(array_keys($differences) as $fieldId)
877 {
878 if($fieldId[0] === '~')
879 continue;
880 $changedFields[] = $fieldId;
881 $listOldFieldIdToDelete["FIELD"][] = $fieldId;
882 }
883
884 $differences = array_diff_key(
885 $elementNewData["PROPERTY_VALUES"],
886 $elementOldData["PROPERTY_VALUES"]
887 );
888 foreach(array_keys($differences) as $fieldId)
889 {
890 $listNewFieldIdToDelete["PROPERTY"][] = $fieldId;
891
892 if(!empty($elementNewData["PROPERTY_VALUES"][$fieldId]["CODE"]))
893 $fieldId = "PROPERTY_".$elementNewData["PROPERTY_VALUES"][$fieldId]["CODE"];
894 else
895 $fieldId = "PROPERTY_".$fieldId;
896 $changedFields[] = $fieldId;
897 }
898 $differences = array_diff_key(
899 $elementOldData["PROPERTY_VALUES"],
900 $elementNewData["PROPERTY_VALUES"]
901 );
902 foreach(array_keys($differences) as $fieldId)
903 {
904 $listOldFieldIdToDelete["PROPERTY"][] = $fieldId;
905
906 if(!empty($elementOldData["PROPERTY_VALUES"][$fieldId]["CODE"]))
907 $fieldId = "PROPERTY_".$elementOldData["PROPERTY_VALUES"][$fieldId]["CODE"];
908 else
909 $fieldId = "PROPERTY_".$fieldId;
910 $changedFields[] = $fieldId;
911 }
912
913 foreach($listNewFieldIdToDelete as $typeField => $listField)
914 {
915 if($typeField == "FIELD")
916 foreach($listField as $fieldId)
917 unset($elementNewData[$fieldId]);
918 elseif($typeField == "PROPERTY")
919 foreach($listField as $fieldId)
920 unset($elementNewData["PROPERTY_VALUES"][$fieldId]);
921 }
922 foreach($listOldFieldIdToDelete as $typeField => $listField)
923 {
924 if($typeField == "FIELD")
925 foreach($listField as $fieldId)
926 unset($elementOldData[$fieldId]);
927 elseif($typeField == "PROPERTY")
928 foreach($listField as $fieldId)
929 unset($elementOldData["PROPERTY_VALUES"][$fieldId]);
930 }
931
932 /* Preparing arrays to compare */
933 $listObject = new CList($iblockId);
934 foreach($elementNewData as $fieldId => $fieldValue)
935 {
936 if(!$listObject->is_field($fieldId) && $fieldId != "PROPERTY_VALUES")
937 {
938 unset($elementNewData[$fieldId]);
939 }
940 elseif($fieldId == "PROPERTY_VALUES")
941 {
942 foreach($fieldValue as $propertyId => $propertyData)
943 {
944 if(!empty($propertyData["CODE"]))
945 $elementNewData["PROPERTY_".$propertyData["CODE"]] = $propertyData["VALUES_LIST"];
946 else
947 $elementNewData["PROPERTY_".$propertyData["ID"]] = $propertyData["VALUES_LIST"];
948
949 unset($elementNewData["PROPERTY_VALUES"][$propertyId]);
950 }
951 unset($elementNewData["PROPERTY_VALUES"]);
952 }
953 }
954 foreach($elementOldData as $fieldId => $fieldValue)
955 {
956 if(!$listObject->is_field($fieldId) && $fieldId != "PROPERTY_VALUES")
957 {
958 unset($elementOldData[$fieldId]);
959 }
960 elseif($fieldId == "PROPERTY_VALUES")
961 {
962 foreach($fieldValue as $propertyId => $propertyData)
963 {
964 if(!empty($propertyData["CODE"]))
965 $elementOldData["PROPERTY_".$propertyData["CODE"]] = $propertyData["VALUES_LIST"];
966 else
967 $elementOldData["PROPERTY_".$propertyData["ID"]] = $propertyData["VALUES_LIST"];
968
969 unset($elementOldData["PROPERTY_VALUES"][$propertyId]);
970 }
971 unset($elementOldData["PROPERTY_VALUES"]);
972 }
973 }
974
975 /* Compares the value */
976 foreach($elementNewData as $fieldName => $fieldValue)
977 {
978 if(is_array($fieldValue))
979 {
980 if(is_array(current($fieldValue)))
981 {
982 $firstValues = array();
983 $secondValues = array();
984 foreach ($fieldValue as $values)
985 {
986 $firstValues = is_array($values) ? $values : [$values];
987 }
988 foreach ($elementOldData[$fieldName] as $values)
989 {
990 $secondValues = is_array($values) ? $values : [$values];
991 }
992
993 if(array_key_exists("TEXT", $firstValues))
994 {
995 $differences = array_diff($firstValues, $secondValues);
996 if(!empty($differences))
997 $changedFields[] = $fieldName;
998 }
999 else
1000 {
1001 if(count($firstValues) != count($secondValues))
1002 $changedFields[] = $fieldName;
1003 }
1004 }
1005 else
1006 {
1007 $differences = array_diff($fieldValue, $elementOldData[$fieldName]);
1008 if(!empty($differences))
1009 $changedFields[] = $fieldName;
1010 }
1011 }
1012 else
1013 {
1014 if(strcmp((string)$fieldValue, (string)$elementOldData[$fieldName]) !== 0)
1015 $changedFields[] = $fieldName;
1016 }
1017 }
1018
1019 return $changedFields;
1020 }
1021
1022 public static function deleteListsUrl($iblockId)
1023 {
1024 global $DB;
1025 $iblockId = intval($iblockId);
1026 $DB->Query(
1027 "delete from b_lists_url where IBLOCK_ID=" . $iblockId
1028 );
1029 }
1030
1038 public static function getIblockAttachedCrm($entityType)
1039 {
1040 if (
1041 (!self::isFeatureEnabled("lists")) &&
1042 (!self::isFeatureEnabled("lists_processes"))
1043 )
1044 {
1045 return [];
1046 }
1047
1048 $cacheTime = defined('BX_COMP_MANAGED_CACHE') ? 3153600 : 3600*4;
1049 $cacheId = 'lists-crm-attached-'.mb_strtolower($entityType);
1050 $cacheDir = '/lists/crm/attached/'.mb_strtolower($entityType).'/';
1051 $cache = new CPHPCache;
1052 if($cache->initCache($cacheTime, $cacheId, $cacheDir))
1053 {
1054 $listIblock = $cache->getVars();
1055 }
1056 else
1057 {
1058 $cache->startDataCache();
1059 $listIblock = array();
1060 $listProperty = array();
1062 'select' => array('ID', 'IBLOCK_ID', 'USER_TYPE_SETTINGS'),
1063 'filter' => array(
1064 '=ACTIVE' => 'Y',
1065 '=USER_TYPE' => 'ECrm',
1066 )
1067 ));
1068 while($property = $propertyObject->fetch())
1069 {
1070 $property['USER_TYPE_SETTINGS'] = unserialize(
1071 $property['USER_TYPE_SETTINGS'],
1072 ['allowed_classes' => false]
1073 );
1074 if(empty($property['USER_TYPE_SETTINGS']['VISIBLE']))
1075 $property['USER_TYPE_SETTINGS']['VISIBLE'] = 'Y';
1076 if($property['USER_TYPE_SETTINGS']['VISIBLE'] == 'Y'
1077 && !empty($property['USER_TYPE_SETTINGS'][$entityType]))
1078 {
1079 if($property['USER_TYPE_SETTINGS'][$entityType] == 'Y')
1080 {
1081 $listProperty[$property['IBLOCK_ID']][] = $property['ID'];
1082 }
1083 }
1084 }
1085 $isListsFeatureEnabled = self::isFeatureEnabled("lists");
1086 $isProcessesFeatureEnabled = self::isFeatureEnabled("lists_processes");
1087 foreach ($listProperty as $iblockId => $listPropertyId)
1088 {
1090 'select' => array('ID', 'NAME', 'IBLOCK_TYPE_ID'),
1091 'filter' => array('=ACTIVE' => 'Y', '=ID' => $iblockId)
1092 ));
1093 if ($iblock = $iblockObject->fetch())
1094 {
1095 switch ($iblock['IBLOCK_TYPE_ID'])
1096 {
1097 case "CRM_PRODUCT_CATALOG":
1098 {
1099 continue 2;
1100 }
1101 case "bitrix_processes":
1102 {
1103 if (!$isProcessesFeatureEnabled)
1104 {
1105 continue 2;
1106 }
1107 break;
1108 }
1109 default:
1110 if (!$isListsFeatureEnabled)
1111 {
1112 continue 2;
1113 }
1114 }
1115 $listIblock[$iblockId] = $iblock['NAME'];
1116 }
1117 }
1118 $cache->endDataCache($listIblock);
1119 }
1120
1121 return $listIblock;
1122 }
1123
1124 protected static function deleteListsCache($cacheDir)
1125 {
1126 $cache = new CPHPCache;
1127 $cache->cleanDir($cacheDir);
1128 }
1129
1130 public static function OnAfterIBlockPropertyAdd($fields)
1131 {
1132 self::deleteCacheToECrmProperty($fields);
1133 }
1134
1135 public static function OnAfterIBlockPropertyUpdate($fields)
1136 {
1137 self::deleteCacheToECrmProperty($fields);
1138 }
1139
1140 public static function OnAfterIBlockPropertyDelete($fields)
1141 {
1142 self::deleteCacheToECrmProperty($fields);
1143 }
1144
1145 public static function getChildSection($baseSectionId, array $listSection, array &$listChildSection)
1146 {
1147 $baseSectionId = intval($baseSectionId);
1148 if (!$baseSectionId)
1149 return;
1150 if(!in_array($baseSectionId, $listChildSection))
1151 $listChildSection[] = $baseSectionId;
1152
1153 foreach($listSection as $sectionId => $section)
1154 {
1155 if(($section['PARENT_ID'] ?? null) == $baseSectionId)
1156 {
1157 $listChildSection[] = $sectionId;
1158 self::getChildSection($sectionId, $listSection, $listChildSection);
1159 }
1160 }
1161 }
1162
1163 public static function isAssociativeArray($array)
1164 {
1165 if (!is_array($array) || empty($array))
1166 return false;
1167 return array_keys($array) !== range(0, count($array) - 1);
1168 }
1169
1176 public static function OnBeforeIBlockElementAdd(&$fields)
1177 {
1178 $iblockTypeId = (string)CIBlock::GetArrayByID($fields["IBLOCK_ID"], 'IBLOCK_TYPE_ID');
1179 if (isset(self::$iblockTypeList[$iblockTypeId]))
1180 {
1181 $fields["SEARCHABLE_CONTENT"] = self::createSeachableContent($fields);
1182 }
1183 unset($iblockTypeId);
1184 return true;
1185 }
1186
1193 public static function OnBeforeIBlockElementUpdate(&$fields)
1194 {
1195 $iblockTypeId = (string)CIBlock::GetArrayByID($fields["IBLOCK_ID"], 'IBLOCK_TYPE_ID');
1196 if (isset(self::$iblockTypeList[$iblockTypeId]))
1197 {
1198 $fields["SEARCHABLE_CONTENT"] = self::createSeachableContent($fields);
1199 }
1200 unset($iblockTypeId);
1201 return true;
1202 }
1203
1211 {
1212 $rebuildedData = Option::get("lists", "rebuild_seachable_content");
1213 $rebuildedData = unserialize($rebuildedData, ['allowed_classes' => false]);
1214 if(!is_array($rebuildedData))
1215 $rebuildedData = array();
1216 if(!isset($rebuildedData[$iblockId]))
1217 {
1218 return '';
1219 }
1220
1221 $limit = 50;
1222 $offset = $rebuildedData[$iblockId];
1223 $rebuildedElementCount = CLists::rebuildSeachableContent($iblockId, $limit, $offset);
1224
1225 if($rebuildedElementCount < $limit)
1226 {
1227 unset($rebuildedData[$iblockId]);
1228 Option::set("lists", "rebuild_seachable_content", serialize($rebuildedData));
1229 return '';
1230 }
1231 else
1232 {
1233 $rebuildedData[$iblockId] = $offset + $rebuildedElementCount;
1234 Option::set("lists", "rebuild_seachable_content", serialize($rebuildedData));
1235 return 'CLists::runRebuildSeachableContent('.$iblockId.');';
1236 }
1237 }
1238
1248 public static function rebuildSeachableContent($iblockId, $limit = 100, $offset = 0)
1249 {
1250 $iblockId = intval($iblockId);
1251 if(!$iblockId)
1252 throw new ArgumentException(Loc::getMessage("LISTS_REQUIRED_PARAMETER",array("#parameter#" => "iblockId")));
1253
1254 $connection = Application::getInstance()->getConnection();
1255 $iblockId = $connection->getSqlHelper()->forSql($iblockId);
1256 $offset = intval($offset);
1257 $limit = intval($limit);
1258 $sqlString = "SELECT ID FROM b_iblock_element WHERE IBLOCK_ID=".$iblockId." ORDER BY ID ASC LIMIT ".$limit." OFFSET ".$offset;
1259 $queryObject = $connection->query($sqlString);
1260 $listElement = $queryObject->fetchAll();
1261 $rebuildedElementCount = $queryObject->getSelectedRowsCount();
1262 $listElementId = array();
1263 foreach($listElement as $element)
1264 $listElementId[] = $element['ID'];
1265
1266 $listElementValue = !empty($listElementId) ? self::getListElementValue($iblockId, $listElementId) : array();
1267
1268 $listSeachableContent = array();
1269 foreach($listElementValue as $elementId => $elementData)
1270 {
1271 $listSeachableContent[$elementId] = self::createSeachableContent($elementData);
1272 }
1273
1274 global $DB;
1275 foreach($listSeachableContent as $elementId => $seachableContent)
1276 {
1277 $strUpdate = $DB->prepareUpdate("b_iblock_element", array("SEARCHABLE_CONTENT" => $seachableContent));
1278 $strSql = "UPDATE b_iblock_element SET ".$strUpdate." WHERE ID=".intval($elementId);
1279 $DB->query($strSql);
1280 }
1281
1282 return $rebuildedElementCount;
1283 }
1284
1292 public static function rebuildSeachableContentForElement($iblockId, $elementId)
1293 {
1294 $iblockId = intval($iblockId);
1295 if(!$iblockId)
1296 {
1297 throw new ArgumentException(Loc::getMessage("LISTS_REQUIRED_PARAMETER",array("#parameter#" => "iblockId")));
1298 }
1299 $elementId = intval($elementId);
1300 if(!$elementId)
1301 {
1302 throw new ArgumentException(Loc::getMessage("LISTS_REQUIRED_PARAMETER",array("#parameter#" => "elementId")));
1303 }
1304
1305 $elementValue = self::getListElementValue($iblockId, $elementId);
1306 $listSeachableContent = array();
1307 foreach($elementValue as $elementData)
1308 {
1309 $listSeachableContent[$elementId] = self::createSeachableContent($elementData);
1310 }
1311 global $DB;
1312 foreach($listSeachableContent as $seachableContent)
1313 {
1314 $strUpdate = $DB->prepareUpdate("b_iblock_element", array("SEARCHABLE_CONTENT" => $seachableContent));
1315 $strSql = "UPDATE b_iblock_element SET ".$strUpdate." WHERE ID=".intval($elementId);
1316 $DB->query($strSql);
1317 }
1318 }
1319
1320 private static function getListElementValue($iblockId, $listElementId)
1321 {
1322 $iblockId = intval($iblockId);
1323 $listElementValue = array();
1324 $listObject = new CList($iblockId);
1325 $queryObject = CIBlockElement::getList(array(), array("IBLOCK_ID" => $iblockId,
1326 "=ID" => $listElementId), false, false, array('*'));
1327 while($queryResult = $queryObject->getNextElement())
1328 {
1329 $element = $queryResult->getFields();
1330 if(is_array($element))
1331 {
1332 foreach($element as $fieldId => $fieldValue)
1333 {
1334 if(!$listObject->is_field($fieldId))
1335 continue;
1336 $listElementValue[$element["ID"]][$fieldId] = $element[$fieldId];
1337 }
1338 $query = CIblockElement::getPropertyValues($iblockId, array("ID" => $element["ID"]));
1339 if($propertyValues = $query->fetch())
1340 {
1341 $listElementValue[$element["ID"]]["PROPERTY_VALUES"] = array();
1342 foreach($propertyValues as $id => $values)
1343 {
1344 if($id == "IBLOCK_ELEMENT_ID")
1345 continue;
1346 $listElementValue[$element["ID"]]["PROPERTY_VALUES"][$id] = $values;
1347 }
1348 }
1349 }
1350 }
1351 return $listElementValue;
1352 }
1353
1354 private static function createSeachableContent(array $fields)
1355 {
1356 $searchableContent = $fields["NAME"] ?? '';
1357
1358 if(!empty($fields["DATE_CREATE"]))
1359 {
1360 $searchableContent .= "\r\n".$fields["DATE_CREATE"];
1361 }
1362 if(!empty($fields["TIMESTAMP_X"]))
1363 {
1364 $searchableContent .= "\r\n".$fields["TIMESTAMP_X"];
1365 }
1366 if(!empty($fields["ACTIVE_FROM"]))
1367 {
1368 $searchableContent .= "\r\n".$fields["ACTIVE_FROM"];
1369 }
1370 if(!empty($fields["ACTIVE_TO"]))
1371 {
1372 $searchableContent .= "\r\n".$fields["ACTIVE_TO"];
1373 }
1374 if(!empty($fields["PREVIEW_PICTURE"]))
1375 {
1376 $fileData = CFile::getFileArray($fields["PREVIEW_PICTURE"]);
1377 if($fileData)
1378 {
1379 $searchableContent .= "\r\n".$fileData["FILE_NAME"];
1380 }
1381 }
1382 if(!empty($fields["DETAIL_PICTURE"]))
1383 {
1384 $fileData = CFile::getFileArray($fields["DETAIL_PICTURE"]);
1385 if($fileData)
1386 {
1387 $searchableContent .= "\r\n".$fileData["FILE_NAME"];
1388 }
1389 }
1390 if(!empty($fields["CREATED_BY"]))
1391 {
1392 $user = new CUser();
1393 $userDetails = $user->getByID($fields["CREATED_BY"])->fetch();
1394 if(is_array($userDetails))
1395 {
1396 $siteNameFormat = CSite::getNameFormat(false);
1397 $searchableContent .= "\r\n".CUser::formatName($siteNameFormat, $userDetails, true, false);
1398 }
1399 }
1400 if(!empty($fields["MODIFIED_BY"]))
1401 {
1402 $user = new CUser();
1403 $userDetails = $user->getByID($fields["MODIFIED_BY"])->fetch();
1404 if(is_array($userDetails))
1405 {
1406 $siteNameFormat = CSite::getNameFormat(false);
1407 $searchableContent .= "\r\n".CUser::formatName($siteNameFormat, $userDetails, true, false);
1408 }
1409 }
1410 if(!empty($fields["PREVIEW_TEXT"]))
1411 {
1412 if(isset($fields["PREVIEW_TEXT_TYPE"]) && $fields["PREVIEW_TEXT_TYPE"] == "html")
1413 $searchableContent .= "\r\n".HTMLToTxt($fields["PREVIEW_TEXT"]);
1414 else
1415 $searchableContent .= "\r\n".$fields["PREVIEW_TEXT"];
1416 }
1417 if(!empty($fields["DETAIL_TEXT"]))
1418 {
1419 if(isset($fields["DETAIL_TEXT_TYPE"]) && $fields["DETAIL_TEXT_TYPE"] == "html")
1420 $searchableContent .= "\r\n".HTMLToTxt($fields["DETAIL_TEXT"]);
1421 else
1422 $searchableContent .= "\r\n".$fields["DETAIL_TEXT"];
1423 }
1424 if(!empty($fields["PROPERTY_VALUES"]) && is_array($fields["PROPERTY_VALUES"]))
1425 {
1426 $searchableContent .= self::createSeachableContentForProperty($fields);
1427 }
1428
1429 $searchableContent = mb_strtoupper($searchableContent);
1430
1431 return $searchableContent;
1432 }
1433
1434 private static function createSeachableContentForProperty($fields)
1435 {
1436 $searchableContent = '';
1437 $userIds = [];
1438
1439 global $DB;
1440 $properties = array();
1441 foreach($fields["PROPERTY_VALUES"] as $propertyId => $valueData)
1442 {
1443 if(!$valueData)
1444 continue;
1445 $properties[$propertyId] = array();
1446 if(is_array($valueData))
1447 {
1448 foreach($valueData as $valueId => $value)
1449 {
1450 if(is_object($value))
1451 continue;
1452 if(isset($value["VALUE"]))
1453 {
1454 if(is_array($value["VALUE"]))
1455 {
1456 if(!empty($value["VALUE"]))
1457 $properties[$propertyId][] = $value["VALUE"];
1458 }
1459 else
1460 {
1461 if($value["VALUE"] <> '')
1462 $properties[$propertyId][] = $value["VALUE"];
1463 }
1464 }
1465 else
1466 {
1467 if(is_array($value))
1468 {
1469 foreach($value as $v)
1470 {
1471 if($v <> '')
1472 $properties[$propertyId][] = $v;
1473 }
1474 }
1475 else
1476 {
1477 if($value <> '')
1478 $properties[$propertyId][] = $value;
1479 }
1480 }
1481 }
1482 }
1483 else
1484 {
1485 $properties[$propertyId][] = $valueData;
1486 }
1487
1488 $queryObject = CIBlockProperty::getById($propertyId);
1489 if($property = $queryObject->fetch())
1490 {
1491 $propertyValues = array();
1492 if(!empty($property["USER_TYPE"]))
1493 {
1494 switch($property["USER_TYPE"])
1495 {
1496 case "Date":
1497 case "DateTime":
1498 {
1499 $format = "FULL";
1500 if($property["USER_TYPE"] == "Date")
1501 $format = "SHORT";
1502 foreach($properties[$propertyId] as $value)
1503 {
1504 try
1505 {
1506 $date = new Bitrix\Main\Type\DateTime($value);
1507 $propertyValues[] = $date->format($DB->dateFormatToPHP(CSite::getDateFormat($format)));
1508 }
1509 catch (Exception $ex)
1510 {
1511 $propertyValues[] = $value;
1512 }
1513 }
1514 break;
1515 }
1516 case "HTML":
1517 {
1518 foreach($properties[$propertyId] as $value)
1519 {
1520 if (is_string($value))
1521 {
1522 $unserialize = unserialize($value, ['allowed_classes' => false]);
1523 if($unserialize)
1524 $value = $unserialize;
1525 }
1526 if (
1527 is_array($value)
1528 && !empty($value['TEXT'])
1529 && is_string($value['TEXT'])
1530 )
1531 {
1532 if (isset($value["TYPE"]))
1533 {
1534 $value["TYPE"] = mb_strtoupper($value["TYPE"]);
1535 if ($value["TYPE"] == "HTML")
1536 $propertyValues[] = HTMLToTxt($value["TEXT"]);
1537 }
1538 }
1539 }
1540 break;
1541 }
1542 case "EList":
1543 {
1544 if(!empty($properties[$propertyId]))
1545 {
1546 $queryObject = CIBlockElement::getList(array(), array("ID" => $properties[$propertyId]),
1547 false, false, array('NAME'));
1548 while($element = $queryObject->getNext())
1549 $propertyValues[] = $element["~NAME"];
1550 }
1551 break;
1552 }
1553 case "Money":
1554 case "map_yandex":
1555 {
1556 $propertyValues = $properties[$propertyId];
1557 break;
1558 }
1559 case "Sequence":
1560 {
1561 foreach($properties[$propertyId] as $value)
1562 $propertyValues[] = intval($value);
1563 break;
1564 }
1565 case "ECrm":
1566 {
1567 if(Loader::includeModule("crm"))
1568 {
1569 foreach($properties[$propertyId] as $value)
1570 {
1571 if (intval($value))
1572 {
1573 foreach($property["USER_TYPE_SETTINGS"] as $entityType => $marker)
1574 {
1575 if ($entityType != "VISIBLE" && $marker == "Y")
1576 {
1577 $typeId = CCrmOwnerType::resolveID($entityType);
1578 $propertyValues[] = CCrmOwnerType::getCaption($typeId, $value, false);
1579 }
1580 }
1581 }
1582 else
1583 {
1584 $explode = explode('_', $value);
1585 $type = $explode[0];
1586 $typeId = CCrmOwnerType::resolveID(CCrmOwnerTypeAbbr::resolveName($type));
1587 $propertyValues[] = CCrmOwnerType::getCaption($typeId, $explode[1], false);
1588 }
1589 }
1590 }
1591 break;
1592 }
1593 case "employee":
1594 {
1595 foreach($properties[$propertyId] as $value)
1596 {
1597 $userIds[] = $value;
1598 }
1599 break;
1600 }
1601 case "DiskFile":
1602 {
1603 if(Loader::includeModule("disk"))
1604 {
1605 foreach($properties[$propertyId] as $value)
1606 {
1607 if(!is_array($value))
1608 $value = array($value);
1609 foreach($value as $v)
1610 {
1611 if(empty($v))
1612 continue;
1613 list($type, $realId) = FileUserType::detectType($v);
1614 if($type == FileUserType::TYPE_ALREADY_ATTACHED)
1615 {
1616 $attachedModel = AttachedObject::loadById($realId);
1617 if($attachedModel)
1618 {
1619 $file = $attachedModel->getFile();
1620 if($file)
1621 $propertyValues[] = $file->getName();
1622 }
1623 }
1624 else
1625 {
1626 $fileModel = File::loadById($realId, array('STORAGE'));
1627 if($fileModel)
1628 $propertyValues[] = $fileModel->getName();
1629 }
1630 }
1631 }
1632 }
1633 break;
1634 }
1635 }
1636 }
1637 else
1638 {
1639 switch($property["PROPERTY_TYPE"])
1640 {
1641 case "S":
1642 {
1643 $propertyValues = $properties[$propertyId];
1644 break;
1645 }
1646 case "N":
1647 {
1648 $propertyValues = $properties[$propertyId];
1649 break;
1650 }
1651 case "L":
1652 {
1653 $queryObject = CIBlockProperty::getPropertyEnum($propertyId);
1654 while($propertyEnum = $queryObject->fetch())
1655 {
1656 if(in_array($propertyEnum["ID"], $properties[$propertyId]))
1657 $propertyValues[] = $propertyEnum["VALUE"];
1658 }
1659 break;
1660 }
1661 case "F":
1662 {
1663 $listPropertyIdForGetExtraValue = array();
1664 foreach($properties[$propertyId] as $value)
1665 {
1666 if(isset($value["name"]))
1667 {
1668 if(!empty($value["name"]))
1669 {
1670 $propertyValues[] = $value["name"];
1671 }
1672 else
1673 {
1674 $listPropertyIdForGetExtraValue[] = $propertyId;
1675 }
1676 }
1677 else
1678 {
1679 $fileData = CFile::getFileArray($value);
1680 if($fileData)
1681 $propertyValues[] = $fileData["FILE_NAME"];
1682 }
1683 }
1684 if(!empty($fields["ID"]) && !empty($listPropertyIdForGetExtraValue))
1685 {
1686 $query = CIblockElement::getPropertyValues($property["IBLOCK_ID"],
1687 array("ID" => $fields["ID"]), false, array("ID" => $listPropertyIdForGetExtraValue));
1688 if($listExtraPropertyValues = $query->fetch())
1689 {
1690 foreach($listExtraPropertyValues as $id => $extraPropertyValues)
1691 {
1692 if($id == "IBLOCK_ELEMENT_ID")
1693 continue;
1694 if(is_array($extraPropertyValues))
1695 {
1696 foreach($extraPropertyValues as $extraPropertyValue)
1697 {
1698 $fileData = CFile::getFileArray($extraPropertyValue);
1699 if($fileData)
1700 $propertyValues[] = $fileData["FILE_NAME"];
1701 }
1702 }
1703 else
1704 {
1705 $fileData = CFile::getFileArray($extraPropertyValues);
1706 if($fileData)
1707 $propertyValues[] = $fileData["FILE_NAME"];
1708 }
1709 }
1710 }
1711 }
1712 break;
1713 }
1714 case "G":
1715 {
1716 if(!empty($properties[$propertyId]))
1717 {
1718 $queryObject = CIBlockSection::getList(array(),
1719 array("=ID" => $properties[$propertyId]), false, array("NAME"));
1720 while($section = $queryObject->getNext())
1721 $propertyValues[] = $section["~NAME"];
1722 }
1723 break;
1724 }
1725 case "E":
1726 {
1727 if(!empty($properties[$propertyId]))
1728 {
1729 $queryObject = CIBlockElement::getList(array(), array("ID" => $properties[$propertyId]),
1730 false, false, array('NAME'));
1731 while($element = $queryObject->getNext())
1732 $propertyValues[] = $element["~NAME"];
1733 }
1734 break;
1735 }
1736 }
1737 }
1738 foreach($propertyValues as $propertyValue)
1739 $searchableContent .= "\r\n".$propertyValue;
1740 }
1741 }
1742
1743 if ($userIds)
1744 {
1745 $siteNameFormat = CSite::getNameFormat(false);
1746 $userResult = \Bitrix\Main\UserTable::getList([
1747 'filter' => ['@ID' => $userIds],
1748 'select' => ['ID', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'LOGIN', 'TITLE', 'EMAIL'],
1749 'cache' => ['ttl' => 3600],
1750 ]);
1751
1752 foreach($userResult as $user)
1753 {
1754 $searchableContent .= "\r\n" . CUser::formatName($siteNameFormat, $user,true,false);
1755 }
1756 }
1757
1758 return $searchableContent;
1759 }
1760
1770 public static function getNumberOfElements($iblockId)
1771 {
1772 $iblockId = intval($iblockId);
1773 if(!$iblockId)
1774 {
1775 throw new ArgumentException(Loc::getMessage("LISTS_REQUIRED_PARAMETER",array("#parameter#" => "iblockId")));
1776 }
1777
1778 $connection = Application::getInstance()->getConnection();
1779 $sqlString = "SELECT COUNT(ID) as COUNT FROM b_iblock_element WHERE IBLOCK_ID=".$iblockId;
1780 $queryObject = $connection->query($sqlString);
1781 $result = $queryObject->fetch();
1782
1783 return intval($result["COUNT"]);
1784 }
1785
1786 public static function isListProcesses(string $iblockTypeId): bool
1787 {
1788 return $iblockTypeId == COption::GetOptionString('lists', 'livefeed_iblock_type_id');
1789 }
1790
1791 public static function isBpFeatureEnabled(string $iblockTypeId): bool
1792 {
1794
1795 return ($processes ? CLists::isFeatureEnabled() : CBPRuntime::isFeatureEnabled());
1796 }
1797
1798 public static function isListFeatureEnabled(string $iblockTypeId): bool
1799 {
1801
1802 return ($processes ? CLists::isFeatureEnabled('lists_processes') : CLists::isFeatureEnabled('lists'));
1803 }
1804
1805 public static function isFeatureEnabled($featureName = '')
1806 {
1807 if (!CModule::IncludeModule("bitrix24"))
1808 return true;
1809
1810 $featureName = (string)$featureName;
1811
1812 if ($featureName === "")
1813 $featureName = "lists_processes";
1814
1815 if (!isset(static::$featuresCache[$featureName]))
1816 static::$featuresCache[$featureName] = \Bitrix\Bitrix24\Feature::isFeatureEnabled($featureName);
1817
1818 return static::$featuresCache[$featureName];
1819 }
1820
1821 public static function isWorkflowParticipant($workflowId)
1822 {
1823 global $USER;
1824
1825 if ($USER->isAdmin() || $USER->canDoOperation("bitrix24_config"))
1826 {
1827 return true;
1828 }
1829
1830 $userId = (int) $USER->getID();
1831 $participants = \CBPTaskService::getWorkflowParticipants($workflowId);
1832 if (in_array($userId, $participants))
1833 {
1834 return true;
1835 }
1836 else
1837 {
1838 $state = \CBPStateService::getWorkflowStateInfo($workflowId);
1839 if ($state && $userId === (int) $state['STARTED_BY'])
1840 {
1841 return true;
1842 }
1843 }
1844
1845 return false;
1846 }
1847
1848 public static function isEnabledLockFeature($iblockId)
1849 {
1850 $optionData = Option::get("lists", "iblock_lock_feature");
1851 $iblockIdsWithLockFeature = unserialize($optionData, ['allowed_classes' => false]);
1852 if (!is_array($iblockIdsWithLockFeature))
1853 {
1854 $iblockIdsWithLockFeature = [];
1855 }
1856 return isset($iblockIdsWithLockFeature[$iblockId]);
1857 }
1858
1859 public static function deleteLockFeatureOption(int $iblockId)
1860 {
1861 $option = Option::get("lists", "iblock_lock_feature");
1862 $iblockIdsWithLockFeature = ($option !== "" ? unserialize($option, ['allowed_classes' => false]) : []);
1863 if (isset($iblockIdsWithLockFeature[$iblockId]))
1864 {
1865 unset($iblockIdsWithLockFeature[$iblockId]);
1866 Option::set("lists", "iblock_lock_feature", serialize($iblockIdsWithLockFeature));
1867 }
1868 }
1869
1870 private static function deleteCacheToECrmProperty($fields): void
1871 {
1872 if (!empty($fields['USER_TYPE']) && $fields['USER_TYPE'] == 'ECrm')
1873 {
1874 if (!empty($fields['USER_TYPE_SETTINGS']))
1875 {
1876 if (!is_array($fields['USER_TYPE_SETTINGS']))
1877 {
1878 $fields['USER_TYPE_SETTINGS'] = unserialize(
1879 $fields['USER_TYPE_SETTINGS'],
1880 ['allowed_classes' => false]
1881 );
1882 }
1883 if (is_array($fields['USER_TYPE_SETTINGS']))
1884 {
1885 foreach ($fields['USER_TYPE_SETTINGS'] as $entityType => $marker)
1886 {
1887 if ($marker == 'Y')
1888 {
1889 self::deleteListsCache('/lists/crm/attached/'.mb_strtolower($entityType).'/');
1890 }
1891 }
1892 }
1893 }
1894 else
1895 {
1896 self::deleteListsCache('/lists/crm/attached/');
1897 }
1898 }
1899 }
1900}
$connection
Определения actionsdefinitions.php:38
$type
Определения options.php:106
$arResult
Определения generate_coupon.php:16
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения loader.php:13
static getList(array $parameters=array())
Определения datamanager.php:431
static getDocumentComplexId($iblockType, $documentId)
Определения bizprocdocument.php:54
static generateDocumentComplexType($iblockType, $iblockId)
Определения bizprocdocument.php:41
const CreateWorkflow
Определения constants.php:213
const StartWorkflow
Определения constants.php:212
static getWorkflowIntegerId($workflowId)
Определения stateservice.php:404
static getDocumentStates(array $documentId, array|string $workflowId='')
Определения stateservice.php:247
static getWorkflowStateInfo($workflowId)
Определения stateservice.php:360
static getWorkflowParticipants($workflowId, $userStatus=null)
Определения taskservice.php:172
Определения iblock.php:9
Определения iblock_rights.php:7
static DeleteFields($iblock_id)
Определения listfields.php:363
Определения list.php:6
Определения lists.php:15
static getChildSection($baseSectionId, array $listSection, array &$listChildSection)
Определения lists.php:1145
static OnBeforeIBlockElementUpdate(&$fields)
Определения lists.php:1193
static OnIBlockDelete($iblock_id)
Определения lists.php:267
static GetSocnetPermission($iblock_id)
Определения lists.php:134
static GetIBlockPermission($iblock_id, $user_id)
Определения lists.php:184
static EnableSocnet($bActive=false)
Определения lists.php:314
static checkChangedFields($iblockId, $elementId, array $select, array $elementFields, array $elementProperty)
Определения lists.php:815
static generateMnemonicCode($integerCode=0)
Определения lists.php:445
static getNumberOfElements($iblockId)
Определения lists.php:1770
static rebuildSeachableContentForElement($iblockId, $elementId)
Определения lists.php:1292
static isEnabledLockFeature($iblockId)
Определения lists.php:1848
static SetSocnetPermission($iblock_id, $arRoles)
Определения lists.php:103
static isFeatureEnabled($featureName='')
Определения lists.php:1805
static OnBeforeIBlockElementAdd(&$fields)
Определения lists.php:1176
static completeWorkflow($workflowId, $iblockType, $elementId, $iblockId, $action)
Определения lists.php:505
static OnAfterIBlockUpdate(array &$fields)
Определения lists.php:281
static getCountProcessesUser($userId, $iblockTypeId)
Определения lists.php:433
static rebuildSeachableContent($iblockId, $limit=100, $offset=0)
Определения lists.php:1248
static GetDefaultSocnetPermission()
Определения lists.php:90
static OnAfterIBlockPropertyUpdate($fields)
Определения lists.php:1135
static OnSharepointCheckAccess($iblock_id)
Определения lists.php:372
static OnAfterIBlockPropertyAdd($fields)
Определения lists.php:1130
static copyIblock($iblockId, array &$errors)
Определения lists.php:621
static getIblockAttachedCrm($entityType)
Определения lists.php:1038
static OnSharepointCreateProperty($arInputFields)
Определения lists.php:338
static runRebuildSeachableContent($iblockId)
Определения lists.php:1210
static GetIBlockTypes($language_id=false)
Определения lists.php:225
static deleteSocnetLog(array $listWorkflowId)
Определения lists.php:593
static isBpFeatureEnabled(string $iblockTypeId)
Определения lists.php:1791
static GetIBlocks($iblock_type_id, $check_permissions, $socnet_group_id=false)
Определения lists.php:242
static isListFeatureEnabled(string $iblockTypeId)
Определения lists.php:1798
static OnAfterIBlockDelete($iblock_id)
Определения lists.php:289
static isAssociativeArray($array)
Определения lists.php:1163
static setLiveFeed($checked, $iblockId)
Определения lists.php:396
static GetPermission($iblock_type_id=false)
Определения lists.php:58
static deleteListsUrl($iblockId)
Определения lists.php:1022
static deleteLockFeatureOption(int $iblockId)
Определения lists.php:1859
static getLiveFeed($iblockId)
Определения lists.php:419
static isWorkflowParticipant($workflowId)
Определения lists.php:1821
static IsEnabledSocnet()
Определения lists.php:297
static SetPermission($iblock_type_id, $arGroups)
Определения lists.php:24
static isListProcesses(string $iblockTypeId)
Определения lists.php:1786
static OnAfterIBlockElementDelete($fields)
Определения lists.php:459
static OnAfterIBlockPropertyDelete($fields)
Определения lists.php:1140
static deleteListsCache($cacheDir)
Определения lists.php:1124
Определения cache.php:11
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$right
Определения options.php:8
</td ></tr ></table ></td ></tr ><?endif?><? $propertyIndex=0;foreach( $arGlobalProperties as $propertyCode=> $propertyValue
Определения file_new.php:729
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$arGroups
Определения options.php:1766
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$iblockTypeId
Определения group_lists.php:25
$iblockId
Определения iblock_catalog_edit.php:30
$errors
Определения iblock_catalog_edit.php:74
if(! $catalogEdit->isSuccess()) $iblock
Определения iblock_catalog_edit.php:38
$select
Определения iblock_catalog_list.php:194
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
RegisterModuleDependences($FROM_MODULE_ID, $MESSAGE_ID, $TO_MODULE_ID, $TO_CLASS="", $TO_METHOD="", $SORT=100, $TO_PATH="", $TO_METHOD_ARG=[])
Определения tools.php:5295
UnRegisterModuleDependences($FROM_MODULE_ID, $MESSAGE_ID, $TO_MODULE_ID, $TO_CLASS="", $TO_METHOD="", $TO_PATH="", $TO_METHOD_ARG=[])
Определения tools.php:5289
HTMLToTxt($str, $strSiteUrl="", $aDelete=[], $maxlen=70)
Определения tools.php:2587
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
$value
Определения Param.php:39
$user
Определения mysql_to_pgsql.php:33
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$option
Определения options.php:1711
const SITE_ID
Определения sonet_set_content_view.php:12
$error
Определения subscription_card_product.php:20
$action
Определения file_dialog.php:21
$arFilter
Определения user_search.php:106
$rights
Определения options.php:4
$url
Определения iframe.php:7
$rsIBlocks
Определения yandex_detail.php:58
$arIBlock['PROPERTY']
Определения yandex_detail.php:172
$fields
Определения yandex_run.php:501