16 private static $iblockTypeList =
array(
18 "bitrix_processes" =>
true,
19 "lists_socnet" =>
true
22 private static $featuresCache =
array();
31 $group_id = intval($group_id);
33 $grp[$group_id] = $group_id;
37 delete from b_lists_permission
38 where IBLOCK_TYPE_ID = '".
$DB->ForSQL($iblock_type_id).
"'
43 insert into b_lists_permission
49 ibt.ID = '".
$DB->ForSQL($iblock_type_id).
"'
50 and ug.ID in (".implode(
", ", $grp).
")
54 if(CACHED_b_lists_permission !==
false)
63 if(CACHED_b_lists_permission !==
false)
65 if(
$CACHE_MANAGER->Read(CACHED_b_lists_permission,
"b_lists_permission"))
72 $res =
$DB->Query(
"select IBLOCK_TYPE_ID, GROUP_ID from b_lists_permission");
76 if(CACHED_b_lists_permission !==
false)
80 if ($iblock_type_id ===
false)
86 return $arResult[$iblock_type_id] ??
false;
106 $iblock_id = intval($iblock_id);
109 foreach($arToDB as $role => $permission)
110 if(isset($arRoles[$role]))
111 $arToDB[$role] = mb_substr($arRoles[$role], 0, 1);
117 delete from b_lists_socnet_group
118 where IBLOCK_ID = ".$iblock_id.
"
120 foreach($arToDB as $role => $permission)
123 insert into b_lists_socnet_group
124 (IBLOCK_ID, SOCNET_ROLE, PERMISSION)
126 (".$iblock_id.
", '".$role.
"', '".$permission.
"')
130 if(CACHED_b_lists_permission !==
false)
137 $iblock_id = (int)$iblock_id;
140 if(!array_key_exists($iblock_id, $arCache))
144 if(CACHED_b_lists_permission !==
false)
146 $cache_id =
"b_lists_perm".$iblock_id;
155 select SOCNET_ROLE, PERMISSION
156 from b_lists_socnet_group
157 where IBLOCK_ID=".$iblock_id.
"
160 $arCache[$iblock_id][
$ar[
"SOCNET_ROLE"]] =
$ar[
"PERMISSION"];
168 select SOCNET_ROLE, PERMISSION
169 from b_lists_socnet_group
170 where IBLOCK_ID=".$iblock_id.
"
173 $arCache[$iblock_id][
$ar[
"SOCNET_ROLE"]] =
$ar[
"PERMISSION"];
176 $arCache[$iblock_id][
"A"] =
"X";
177 $arCache[$iblock_id][
"T"] =
"D";
178 $arCache[$iblock_id][
"Z"] =
"D";
181 return $arCache[$iblock_id];
189 $Permission = CIBlock::GetPermission($iblock_id, $user_id);
190 if($Permission <
"W")
192 $arIBlock = CIBlock::GetArrayByID($iblock_id);
197 if (is_array($arListsPerm) &&
count($arListsPerm) > 0)
200 if($user_id ==
$USER->GetID())
201 $arUserGroups =
$USER->GetUserGroupArray();
203 $arUserGroups =
$USER->GetUserGroup($user_id);
206 if(
count(array_intersect($arListsPerm, $arUserGroups)))
215 && CModule::IncludeModule(
'socialnetwork')
219 $socnet_role = CSocNetUserToGroup::GetUserRole(
$USER->GetID(),
$arIBlock[
"SOCNET_GROUP_ID"]);
220 $Permission = $arSocnetPerm[$socnet_role];
229 SELECT IBLOCK_TYPE_ID, NAME
230 FROM b_iblock_type_lang
232 LID = '".
$DB->ForSQL($language_id===
false? LANGUAGE_ID: $language_id).
"'
235 FROM b_lists_permission
236 WHERE b_lists_permission.IBLOCK_TYPE_ID = b_iblock_type_lang.IBLOCK_TYPE_ID
242 public static function GetIBlocks($iblock_type_id, $check_permissions, $socnet_group_id =
false)
252 "TYPE" => $iblock_type_id,
253 "CHECK_PERMISSIONS" => ($check_permissions?
"Y":
"N"),
255 if($socnet_group_id > 0)
256 $arFilter[
"=SOCNET_GROUP_ID"] = $socnet_group_id;
270 $iblock_id = intval($iblock_id);
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);
278 self::deleteLockFeatureOption($iblock_id);
285 self::deleteListsCache(
'/lists/crm/attached/');
291 if (CModule::includeModule(
'bizproc'))
293 BizProcDocument::deleteDataIblock($iblock_id);
300 foreach (
GetModuleEvents(
"socialnetwork",
"OnFillSocNetFeaturesList",
true) as $arEvent)
303 $arEvent[
"TO_MODULE_ID"] ==
"lists"
304 && $arEvent[
"TO_CLASS"] ==
"CListsSocnet"
320 RegisterModuleDependences(
"socialnetwork",
"OnFillSocNetFeaturesList",
"lists",
"CListsSocnet",
"OnFillSocNetFeaturesList");
322 RegisterModuleDependences(
"socialnetwork",
"OnParseSocNetComponentPath",
"lists",
"CListsSocnet",
"OnParseSocNetComponentPath");
323 RegisterModuleDependences(
"socialnetwork",
"OnInitSocNetComponentVariables",
"lists",
"CListsSocnet",
"OnInitSocNetComponentVariables");
333 UnRegisterModuleDependences(
"socialnetwork",
"OnInitSocNetComponentVariables",
"lists",
"CListsSocnet",
"OnInitSocNetComponentVariables");
341 $iblock_id = (int)$arInputFields[
"IBLOCK_ID"];
345 $rsFields =
$DB->Query(
"
346 SELECT * FROM b_lists_field
347 WHERE IBLOCK_ID = ".$iblock_id.
"
350 if($rsFields->Fetch())
352 $arNewFields =
array(
354 "NAME" => $arInputFields[
"SP_FIELD"],
357 if(mb_substr($arInputFields[
"FIELD_ID"], 0, 9) ==
"PROPERTY_")
359 $arNewFields[
"ID"] = mb_substr($arInputFields[
"FIELD_ID"], 9);
360 $arNewFields[
"TYPE"] =
"S";
363 $arNewFields[
"TYPE"] = $arInputFields[
"FIELD_ID"];
366 $obList =
new CList($iblock_id);
367 $obList->AddField($arNewFields);
375 $arIBlock = CIBlock::GetArrayByID($iblock_id);
381 is_array($arListsPerm)
382 &&
count($arListsPerm)
386 $arUserGroups =
$USER->GetUserGroupArray();
388 if(
count(array_intersect($arListsPerm, $arUserGroups)))
400 $checked = intval($checked);
402 $resultQuery =
$DB->Query(
"SELECT LIVE_FEED FROM b_lists_url WHERE IBLOCK_ID = ".
$iblockId);
403 $resultData = $resultQuery->fetch();
407 if($resultData[
"LIVE_FEED"] != $checked)
409 $DB->Query(
"UPDATE b_lists_url SET LIVE_FEED = '".$checked.
"' WHERE IBLOCK_ID = ".
$iblockId);
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.
")");
424 $resultQuery =
$DB->Query(
"SELECT LIVE_FEED FROM b_lists_url WHERE IBLOCK_ID = ".
$iblockId);
425 $resultData = $resultQuery->fetch();
428 return $resultData[
"LIVE_FEED"];
436 return CIBlockElement::getList(
448 $integerCode = time();
451 for (
$i = 1; $integerCode >= 0 &&
$i < 10;
$i++)
453 $code = chr(0x41 + ($integerCode % pow(26,
$i) / pow(26,
$i - 1))) .
$code;
454 $integerCode -= pow(26,
$i);
461 if (CModule::includeModule(
'bizproc'))
465 $iblockType = COption::getOptionString(
"lists",
"livefeed_iblock_type_id");
468 if(
$iblock = $iblockQuery->fetch())
470 $iblockType =
$iblock[
"IBLOCK_TYPE_ID"];
474 $listWorkflowId =
array();
475 foreach ($states as $workflowId => $state)
477 $listWorkflowId[] = $workflowId;
480 self::deleteSocnetLog($listWorkflowId);
485 $propertyQuery = CIBlockElement::getProperty(
487 while($property = $propertyQuery->fetch())
489 $userType = \CIBlockProperty::getUserType($property[
'USER_TYPE']);
490 if (array_key_exists(
'DeleteAllAttachedFiles', $userType))
492 call_user_func_array($userType[
'DeleteAllAttachedFiles'],
array(
$fields[
'ID']));
507 if (!Loader::includeModule(
'bizproc'))
509 return Loc::getMessage(
'LISTS_MODULE_BIZPROC_NOT_INSTALLED_MSGVER_1');
517 $documentStates = CBPDocument::getDocumentStates($documentType, $documentId);
519 $permission = CBPDocument::canUserOperateDocument(
524 array(
"DocumentStates" => $documentStates)
529 return Loc::getMessage(
'LISTS_ACCESS_DENIED');
537 CBPDocument::terminateWorkflow(
547 $stringError .=
$error[
'message'];
548 $listError[] =
array(
'id' =>
'stopBizproc',
'text' => $stringError);
553 $errors = CBPDocument::killWorkflow($workflowId);
556 $stringError .=
$error[
'message'];
562 'id' =>
'stopBizproc',
563 'text' => $stringError
568 if(empty($listError) && Loader::includeModule(
'socialnetwork') &&
569 $iblockType == COption::getOptionString(
"lists",
"livefeed_iblock_type_id"))
572 $resultQuery = CSocNetLog::getList(
574 array(
'EVENT_ID' =>
'lists_new_element',
'SOURCE_ID' => $sourceId),
579 while ($log = $resultQuery->fetch())
581 CSocNetLog::delete($log[
'ID']);
585 if (!empty($listError))
587 $stringError = implode(PHP_EOL, array_column($listError,
'text'));
595 if(CModule::includeModule(
'socialnetwork'))
597 foreach ($listWorkflowId as $workflowId)
600 $resultQuery = CSocNetLog::getList(
602 array(
'EVENT_ID' =>
'lists_new_element',
'SOURCE_ID' => $sourceId),
607 while ($log = $resultQuery->fetch())
609 CSocNetLog::delete($log[
'ID']);
626 $errors[] = Loc::getMessage(
'LISTS_REQUIRED_PARAMETER',
array(
'#parameter#' =>
'iblockId'));
635 $errors[] = Loc::getMessage(
'LISTS_COPY_IBLOCK_ERROR_GET_DATA');
638 $iblockMessage = CIBlock::getMessages(
$iblockId);
641 $iblock[
'NAME'] =
$iblock[
'NAME'].Loc::getMessage(
'LISTS_COPY_IBLOCK_NAME_TITLE');
653 $errors[] = Loc::getMessage(
'LISTS_COPY_IBLOCK_ERROR_GET_DATA');
656 $copyIblockId = $iblockObject->add(
$iblock);
666 $errors[] = Loc::getMessage(
'LISTS_COPY_IBLOCK_ERROR_GET_DATA');
672 if(
$iblock[
'RIGHTS_MODE'] ==
'E')
676 foreach($rightObject->getRights() as
$right)
679 'GROUP_CODE' =>
$right[
'GROUP_CODE'],
681 'TASK_ID' =>
$right[
'TASK_ID'],
688 if(!empty(
$iblock[
'SOCNET_GROUP_ID']))
690 $socnetPerm = self::getSocnetPermission(
$iblockId);
691 foreach($socnetPerm as $role => $permission)
693 if($permission >
"W")
701 "GROUP_CODE" =>
"SG".
$iblock[
'SOCNET_GROUP_ID'].
"_".$role,
702 "IS_INHERITED" =>
"N",
703 "TASK_ID" => CIBlockRights::letterToTask($permission),
708 "GROUP_CODE" =>
"AU",
709 "IS_INHERITED" =>
"N",
710 "TASK_ID" => CIBlockRights::letterToTask($permission),
715 "GROUP_CODE" =>
"G2",
716 "IS_INHERITED" =>
"N",
717 "TASK_ID" => CIBlockRights::letterToTask($permission),
725 $groupPermissions = CIBlock::getGroupPermissions(
$iblockId);
726 foreach($groupPermissions as $groupId => $permission)
728 if($permission >
'W')
730 'GROUP_CODE' =>
'G'.$groupId,
731 'IS_INHERITED' =>
'N',
732 'TASK_ID' => CIBlockRights::letterToTask($permission),
739 $resultIblock = $iblockObject->update($copyIblockId,
$iblock);
741 $errors[] = Loc::getMessage(
'LISTS_COPY_IBLOCK_ERROR_SET_RIGHT');
745 $fields = $listObject->getFields();
746 $copyListObject =
new CList($copyIblockId);
747 foreach(
$fields as $fieldId => $field)
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'],
761 if(!$listObject->is_field($fieldId))
763 if($field[
'TYPE'] ==
'L')
765 $enum = CIBlockPropertyEnum::getList(
array(),
array(
'PROPERTY_ID' => $field[
'ID']));
766 while($listData = $enum->fetch())
768 $copyFields[
'VALUES'][] =
array(
769 'XML_ID' => $listData[
'XML_ID'],
770 'VALUE' => $listData[
'VALUE'],
771 'DEF' => $listData[
'DEF'],
772 'SORT' => $listData[
'SORT']
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'];
789 if($fieldId ==
'NAME')
791 $resultUpdateField = $copyListObject->updateField(
"NAME", $copyFields);
792 if($resultUpdateField)
793 $copyListObject->save();
795 $errors[] = Loc::getMessage(
'LISTS_COPY_IBLOCK_ERROR_ADD_FIELD',
796 array(
'#field#' => $field[
'NAME']));
801 $copyFieldId = $copyListObject->addField($copyFields);
803 $copyListObject->save();
805 $errors[] = Loc::getMessage(
'LISTS_COPY_IBLOCK_ERROR_ADD_FIELD',
806 array(
'#field#' => $field[
'NAME']));
812 return $copyIblockId;
817 $changedFields =
array();
819 $elementNewData =
array();
820 $elementQuery = CIBlockElement::getList(
822 $elementObject = $elementQuery->getNextElement();
824 if(is_object($elementObject))
825 $elementNewData = $elementObject->getFields();
827 $elementOldData = $elementFields;
828 unset($elementNewData[
"TIMESTAMP_X"]);
829 unset($elementOldData[
"TIMESTAMP_X"]);
831 $elementNewData[
"PROPERTY_VALUES"] =
array();
832 if(is_object($elementObject))
834 $propertyQuery = CIBlockElement::getProperty(
837 array(
"sort"=>
"asc",
"id"=>
"asc",
"enum_sort"=>
"asc",
"value_id"=>
"asc"),
838 array(
"ACTIVE"=>
"Y",
"EMPTY"=>
"N")
840 while($property = $propertyQuery->fetch())
842 $propertyId = $property[
"ID"];
843 if(!array_key_exists($propertyId, $elementNewData[
"PROPERTY_VALUES"]))
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();
854 $elementNewData[
"PROPERTY_VALUES"][$propertyId][
"FULL_VALUES"][$property[
"PROPERTY_VALUE_ID"]] =
array(
855 "VALUE" => $property[
"VALUE"],
856 "DESCRIPTION" => $property[
"DESCRIPTION"],
858 $elementNewData[
"PROPERTY_VALUES"][$propertyId][
"VALUES_LIST"][$property[
"PROPERTY_VALUE_ID"]] = $property[
"VALUE"];
862 $elementOldData[
"PROPERTY_VALUES"] = $elementProperty;
865 $listNewFieldIdToDelete =
array();
866 $listOldFieldIdToDelete =
array();
867 $differences = array_diff_key($elementNewData, $elementOldData);
868 foreach(array_keys($differences) as $fieldId)
870 if($fieldId[0] ===
'~')
872 $changedFields[] = $fieldId;
873 $listNewFieldIdToDelete[
"FIELD"][] = $fieldId;
875 $differences = array_diff_key($elementOldData, $elementNewData);
876 foreach(array_keys($differences) as $fieldId)
878 if($fieldId[0] ===
'~')
880 $changedFields[] = $fieldId;
881 $listOldFieldIdToDelete[
"FIELD"][] = $fieldId;
884 $differences = array_diff_key(
885 $elementNewData[
"PROPERTY_VALUES"],
886 $elementOldData[
"PROPERTY_VALUES"]
888 foreach(array_keys($differences) as $fieldId)
890 $listNewFieldIdToDelete[
"PROPERTY"][] = $fieldId;
892 if(!empty($elementNewData[
"PROPERTY_VALUES"][$fieldId][
"CODE"]))
893 $fieldId =
"PROPERTY_".$elementNewData[
"PROPERTY_VALUES"][$fieldId][
"CODE"];
895 $fieldId =
"PROPERTY_".$fieldId;
896 $changedFields[] = $fieldId;
898 $differences = array_diff_key(
899 $elementOldData[
"PROPERTY_VALUES"],
900 $elementNewData[
"PROPERTY_VALUES"]
902 foreach(array_keys($differences) as $fieldId)
904 $listOldFieldIdToDelete[
"PROPERTY"][] = $fieldId;
906 if(!empty($elementOldData[
"PROPERTY_VALUES"][$fieldId][
"CODE"]))
907 $fieldId =
"PROPERTY_".$elementOldData[
"PROPERTY_VALUES"][$fieldId][
"CODE"];
909 $fieldId =
"PROPERTY_".$fieldId;
910 $changedFields[] = $fieldId;
913 foreach($listNewFieldIdToDelete as $typeField => $listField)
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]);
922 foreach($listOldFieldIdToDelete as $typeField => $listField)
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]);
934 foreach($elementNewData as $fieldId => $fieldValue)
936 if(!$listObject->is_field($fieldId) && $fieldId !=
"PROPERTY_VALUES")
938 unset($elementNewData[$fieldId]);
940 elseif($fieldId ==
"PROPERTY_VALUES")
942 foreach($fieldValue as $propertyId => $propertyData)
944 if(!empty($propertyData[
"CODE"]))
945 $elementNewData[
"PROPERTY_".$propertyData[
"CODE"]] = $propertyData[
"VALUES_LIST"];
947 $elementNewData[
"PROPERTY_".$propertyData[
"ID"]] = $propertyData[
"VALUES_LIST"];
949 unset($elementNewData[
"PROPERTY_VALUES"][$propertyId]);
951 unset($elementNewData[
"PROPERTY_VALUES"]);
954 foreach($elementOldData as $fieldId => $fieldValue)
956 if(!$listObject->is_field($fieldId) && $fieldId !=
"PROPERTY_VALUES")
958 unset($elementOldData[$fieldId]);
960 elseif($fieldId ==
"PROPERTY_VALUES")
962 foreach($fieldValue as $propertyId => $propertyData)
964 if(!empty($propertyData[
"CODE"]))
965 $elementOldData[
"PROPERTY_".$propertyData[
"CODE"]] = $propertyData[
"VALUES_LIST"];
967 $elementOldData[
"PROPERTY_".$propertyData[
"ID"]] = $propertyData[
"VALUES_LIST"];
969 unset($elementOldData[
"PROPERTY_VALUES"][$propertyId]);
971 unset($elementOldData[
"PROPERTY_VALUES"]);
976 foreach($elementNewData as $fieldName => $fieldValue)
978 if(is_array($fieldValue))
980 if(is_array(current($fieldValue)))
982 $firstValues =
array();
983 $secondValues =
array();
984 foreach ($fieldValue as $values)
986 $firstValues = is_array($values) ? $values : [$values];
988 foreach ($elementOldData[$fieldName] as $values)
990 $secondValues = is_array($values) ? $values : [$values];
993 if(array_key_exists(
"TEXT", $firstValues))
995 $differences = array_diff($firstValues, $secondValues);
996 if(!empty($differences))
997 $changedFields[] = $fieldName;
1001 if(
count($firstValues) !=
count($secondValues))
1002 $changedFields[] = $fieldName;
1007 $differences = array_diff($fieldValue, $elementOldData[$fieldName]);
1008 if(!empty($differences))
1009 $changedFields[] = $fieldName;
1014 if(strcmp((
string)$fieldValue, (
string)$elementOldData[$fieldName]) !== 0)
1015 $changedFields[] = $fieldName;
1019 return $changedFields;
1027 "delete from b_lists_url where IBLOCK_ID=" .
$iblockId
1041 (!self::isFeatureEnabled(
"lists")) &&
1042 (!self::isFeatureEnabled(
"lists_processes"))
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).
'/';
1052 if($cache->initCache($cacheTime, $cacheId, $cacheDir))
1054 $listIblock = $cache->getVars();
1058 $cache->startDataCache();
1059 $listIblock =
array();
1060 $listProperty =
array();
1062 'select' =>
array(
'ID',
'IBLOCK_ID',
'USER_TYPE_SETTINGS'),
1065 '=USER_TYPE' =>
'ECrm',
1068 while($property = $propertyObject->fetch())
1070 $property[
'USER_TYPE_SETTINGS'] = unserialize(
1071 $property[
'USER_TYPE_SETTINGS'],
1072 [
'allowed_classes' =>
false]
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]))
1079 if($property[
'USER_TYPE_SETTINGS'][$entityType] ==
'Y')
1081 $listProperty[$property[
'IBLOCK_ID']][] = $property[
'ID'];
1085 $isListsFeatureEnabled = self::isFeatureEnabled(
"lists");
1086 $isProcessesFeatureEnabled = self::isFeatureEnabled(
"lists_processes");
1087 foreach ($listProperty as
$iblockId => $listPropertyId)
1090 'select' =>
array(
'ID',
'NAME',
'IBLOCK_TYPE_ID'),
1093 if (
$iblock = $iblockObject->fetch())
1095 switch (
$iblock[
'IBLOCK_TYPE_ID'])
1097 case "CRM_PRODUCT_CATALOG":
1101 case "bitrix_processes":
1103 if (!$isProcessesFeatureEnabled)
1110 if (!$isListsFeatureEnabled)
1118 $cache->endDataCache($listIblock);
1127 $cache->cleanDir($cacheDir);
1132 self::deleteCacheToECrmProperty(
$fields);
1137 self::deleteCacheToECrmProperty(
$fields);
1142 self::deleteCacheToECrmProperty(
$fields);
1147 $baseSectionId = intval($baseSectionId);
1148 if (!$baseSectionId)
1150 if(!in_array($baseSectionId, $listChildSection))
1151 $listChildSection[] = $baseSectionId;
1153 foreach($listSection as $sectionId => $section)
1155 if(($section[
'PARENT_ID'] ??
null) == $baseSectionId)
1157 $listChildSection[] = $sectionId;
1158 self::getChildSection($sectionId, $listSection, $listChildSection);
1165 if (!is_array($array) || empty($array))
1167 return array_keys($array) !== range(0,
count($array) - 1);
1181 $fields[
"SEARCHABLE_CONTENT"] = self::createSeachableContent(
$fields);
1198 $fields[
"SEARCHABLE_CONTENT"] = self::createSeachableContent(
$fields);
1212 $rebuildedData = Option::get(
"lists",
"rebuild_seachable_content");
1213 $rebuildedData = unserialize($rebuildedData, [
'allowed_classes' =>
false]);
1214 if(!is_array($rebuildedData))
1215 $rebuildedData =
array();
1225 if($rebuildedElementCount < $limit)
1228 Option::set(
"lists",
"rebuild_seachable_content", serialize($rebuildedData));
1233 $rebuildedData[
$iblockId] = $offset + $rebuildedElementCount;
1234 Option::set(
"lists",
"rebuild_seachable_content", serialize($rebuildedData));
1235 return 'CLists::runRebuildSeachableContent('.$iblockId.
');';
1252 throw new ArgumentException(Loc::getMessage(
"LISTS_REQUIRED_PARAMETER",
array(
"#parameter#" =>
"iblockId")));
1254 $connection = Application::getInstance()->getConnection();
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;
1260 $listElement = $queryObject->fetchAll();
1261 $rebuildedElementCount = $queryObject->getSelectedRowsCount();
1262 $listElementId =
array();
1263 foreach($listElement as $element)
1264 $listElementId[] = $element[
'ID'];
1266 $listElementValue = !empty($listElementId) ? self::getListElementValue(
$iblockId, $listElementId) :
array();
1268 $listSeachableContent =
array();
1269 foreach($listElementValue as $elementId => $elementData)
1271 $listSeachableContent[$elementId] = self::createSeachableContent($elementData);
1275 foreach($listSeachableContent as $elementId => $seachableContent)
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);
1282 return $rebuildedElementCount;
1297 throw new ArgumentException(Loc::getMessage(
"LISTS_REQUIRED_PARAMETER",
array(
"#parameter#" =>
"iblockId")));
1299 $elementId = intval($elementId);
1302 throw new ArgumentException(Loc::getMessage(
"LISTS_REQUIRED_PARAMETER",
array(
"#parameter#" =>
"elementId")));
1305 $elementValue = self::getListElementValue(
$iblockId, $elementId);
1306 $listSeachableContent =
array();
1307 foreach($elementValue as $elementData)
1309 $listSeachableContent[$elementId] = self::createSeachableContent($elementData);
1312 foreach($listSeachableContent as $seachableContent)
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);
1320 private static function getListElementValue(
$iblockId, $listElementId)
1323 $listElementValue =
array();
1326 "=ID" => $listElementId),
false,
false,
array(
'*'));
1327 while($queryResult = $queryObject->getNextElement())
1329 $element = $queryResult->getFields();
1330 if(is_array($element))
1332 foreach($element as $fieldId => $fieldValue)
1334 if(!$listObject->is_field($fieldId))
1336 $listElementValue[$element[
"ID"]][$fieldId] = $element[$fieldId];
1339 if($propertyValues =
$query->fetch())
1341 $listElementValue[$element[
"ID"]][
"PROPERTY_VALUES"] =
array();
1342 foreach($propertyValues as $id => $values)
1344 if($id ==
"IBLOCK_ELEMENT_ID")
1346 $listElementValue[$element[
"ID"]][
"PROPERTY_VALUES"][$id] = $values;
1351 return $listElementValue;
1354 private static function createSeachableContent(
array $fields)
1356 $searchableContent =
$fields[
"NAME"] ??
'';
1358 if(!empty(
$fields[
"DATE_CREATE"]))
1360 $searchableContent .=
"\r\n".$fields[
"DATE_CREATE"];
1362 if(!empty(
$fields[
"TIMESTAMP_X"]))
1364 $searchableContent .=
"\r\n".$fields[
"TIMESTAMP_X"];
1366 if(!empty(
$fields[
"ACTIVE_FROM"]))
1368 $searchableContent .=
"\r\n".$fields[
"ACTIVE_FROM"];
1370 if(!empty(
$fields[
"ACTIVE_TO"]))
1372 $searchableContent .=
"\r\n".$fields[
"ACTIVE_TO"];
1374 if(!empty(
$fields[
"PREVIEW_PICTURE"]))
1376 $fileData = CFile::getFileArray(
$fields[
"PREVIEW_PICTURE"]);
1379 $searchableContent .=
"\r\n".$fileData[
"FILE_NAME"];
1382 if(!empty(
$fields[
"DETAIL_PICTURE"]))
1384 $fileData = CFile::getFileArray(
$fields[
"DETAIL_PICTURE"]);
1387 $searchableContent .=
"\r\n".$fileData[
"FILE_NAME"];
1390 if(!empty(
$fields[
"CREATED_BY"]))
1392 $user =
new CUser();
1393 $userDetails =
$user->getByID(
$fields[
"CREATED_BY"])->fetch();
1394 if(is_array($userDetails))
1396 $siteNameFormat = CSite::getNameFormat(
false);
1397 $searchableContent .=
"\r\n".CUser::formatName($siteNameFormat, $userDetails,
true,
false);
1400 if(!empty(
$fields[
"MODIFIED_BY"]))
1402 $user =
new CUser();
1403 $userDetails =
$user->getByID(
$fields[
"MODIFIED_BY"])->fetch();
1404 if(is_array($userDetails))
1406 $siteNameFormat = CSite::getNameFormat(
false);
1407 $searchableContent .=
"\r\n".CUser::formatName($siteNameFormat, $userDetails,
true,
false);
1410 if(!empty(
$fields[
"PREVIEW_TEXT"]))
1412 if(isset(
$fields[
"PREVIEW_TEXT_TYPE"]) &&
$fields[
"PREVIEW_TEXT_TYPE"] ==
"html")
1413 $searchableContent .=
"\r\n".HTMLToTxt(
$fields[
"PREVIEW_TEXT"]);
1415 $searchableContent .=
"\r\n".$fields[
"PREVIEW_TEXT"];
1417 if(!empty(
$fields[
"DETAIL_TEXT"]))
1419 if(isset(
$fields[
"DETAIL_TEXT_TYPE"]) &&
$fields[
"DETAIL_TEXT_TYPE"] ==
"html")
1420 $searchableContent .=
"\r\n".HTMLToTxt(
$fields[
"DETAIL_TEXT"]);
1422 $searchableContent .=
"\r\n".$fields[
"DETAIL_TEXT"];
1424 if(!empty(
$fields[
"PROPERTY_VALUES"]) && is_array(
$fields[
"PROPERTY_VALUES"]))
1426 $searchableContent .= self::createSeachableContentForProperty(
$fields);
1429 $searchableContent = mb_strtoupper($searchableContent);
1431 return $searchableContent;
1434 private static function createSeachableContentForProperty(
$fields)
1436 $searchableContent =
'';
1440 $properties =
array();
1441 foreach(
$fields[
"PROPERTY_VALUES"] as $propertyId => $valueData)
1445 $properties[$propertyId] =
array();
1446 if(is_array($valueData))
1448 foreach($valueData as $valueId => $value)
1450 if(is_object($value))
1452 if(isset($value[
"VALUE"]))
1454 if(is_array($value[
"VALUE"]))
1456 if(!empty($value[
"VALUE"]))
1457 $properties[$propertyId][] =
$value[
"VALUE"];
1461 if($value[
"VALUE"] <>
'')
1462 $properties[$propertyId][] =
$value[
"VALUE"];
1467 if(is_array($value))
1469 foreach($value as $v)
1472 $properties[$propertyId][] = $v;
1478 $properties[$propertyId][] =
$value;
1485 $properties[$propertyId][] = $valueData;
1488 $queryObject = CIBlockProperty::getById($propertyId);
1489 if($property = $queryObject->fetch())
1491 $propertyValues =
array();
1492 if(!empty($property[
"USER_TYPE"]))
1494 switch($property[
"USER_TYPE"])
1500 if($property[
"USER_TYPE"] ==
"Date")
1502 foreach($properties[$propertyId] as $value)
1506 $date =
new Bitrix\Main\Type\DateTime($value);
1507 $propertyValues[] = $date->format(
$DB->dateFormatToPHP(CSite::getDateFormat($format)));
1509 catch (Exception $ex)
1511 $propertyValues[] =
$value;
1518 foreach($properties[$propertyId] as $value)
1520 if (is_string($value))
1522 $unserialize = unserialize($value, [
'allowed_classes' =>
false]);
1528 && !empty($value[
'TEXT'])
1529 && is_string($value[
'TEXT'])
1532 if (isset($value[
"TYPE"]))
1534 $value[
"TYPE"] = mb_strtoupper($value[
"TYPE"]);
1535 if ($value[
"TYPE"] ==
"HTML")
1536 $propertyValues[] =
HTMLToTxt($value[
"TEXT"]);
1544 if(!empty($properties[$propertyId]))
1546 $queryObject = CIBlockElement::getList(
array(),
array(
"ID" => $properties[$propertyId]),
1547 false,
false,
array(
'NAME'));
1548 while($element = $queryObject->getNext())
1549 $propertyValues[] = $element[
"~NAME"];
1556 $propertyValues = $properties[$propertyId];
1561 foreach($properties[$propertyId] as $value)
1562 $propertyValues[] = intval($value);
1567 if(Loader::includeModule(
"crm"))
1569 foreach($properties[$propertyId] as $value)
1573 foreach($property[
"USER_TYPE_SETTINGS"] as $entityType => $marker)
1575 if ($entityType !=
"VISIBLE" && $marker ==
"Y")
1577 $typeId = CCrmOwnerType::resolveID($entityType);
1578 $propertyValues[] = CCrmOwnerType::getCaption($typeId, $value,
false);
1584 $explode = explode(
'_', $value);
1585 $type = $explode[0];
1586 $typeId = CCrmOwnerType::resolveID(CCrmOwnerTypeAbbr::resolveName(
$type));
1587 $propertyValues[] = CCrmOwnerType::getCaption($typeId, $explode[1],
false);
1595 foreach($properties[$propertyId] as $value)
1603 if(Loader::includeModule(
"disk"))
1605 foreach($properties[$propertyId] as $value)
1607 if(!is_array($value))
1609 foreach($value as $v)
1613 list(
$type, $realId) = FileUserType::detectType($v);
1614 if(
$type == FileUserType::TYPE_ALREADY_ATTACHED)
1616 $attachedModel = AttachedObject::loadById($realId);
1619 $file = $attachedModel->getFile();
1621 $propertyValues[] = $file->getName();
1626 $fileModel = File::loadById($realId,
array(
'STORAGE'));
1628 $propertyValues[] = $fileModel->getName();
1639 switch($property[
"PROPERTY_TYPE"])
1643 $propertyValues = $properties[$propertyId];
1648 $propertyValues = $properties[$propertyId];
1653 $queryObject = CIBlockProperty::getPropertyEnum($propertyId);
1654 while($propertyEnum = $queryObject->fetch())
1656 if(in_array($propertyEnum[
"ID"], $properties[$propertyId]))
1657 $propertyValues[] = $propertyEnum[
"VALUE"];
1663 $listPropertyIdForGetExtraValue =
array();
1664 foreach($properties[$propertyId] as $value)
1666 if(isset($value[
"name"]))
1668 if(!empty($value[
"name"]))
1670 $propertyValues[] =
$value[
"name"];
1674 $listPropertyIdForGetExtraValue[] = $propertyId;
1679 $fileData = CFile::getFileArray($value);
1681 $propertyValues[] = $fileData[
"FILE_NAME"];
1684 if(!empty(
$fields[
"ID"]) && !empty($listPropertyIdForGetExtraValue))
1686 $query = CIblockElement::getPropertyValues($property[
"IBLOCK_ID"],
1687 array(
"ID" =>
$fields[
"ID"]),
false,
array(
"ID" => $listPropertyIdForGetExtraValue));
1688 if($listExtraPropertyValues =
$query->fetch())
1690 foreach($listExtraPropertyValues as $id => $extraPropertyValues)
1692 if($id ==
"IBLOCK_ELEMENT_ID")
1694 if(is_array($extraPropertyValues))
1696 foreach($extraPropertyValues as $extraPropertyValue)
1698 $fileData = CFile::getFileArray($extraPropertyValue);
1700 $propertyValues[] = $fileData[
"FILE_NAME"];
1705 $fileData = CFile::getFileArray($extraPropertyValues);
1707 $propertyValues[] = $fileData[
"FILE_NAME"];
1716 if(!empty($properties[$propertyId]))
1718 $queryObject = CIBlockSection::getList(
array(),
1719 array(
"=ID" => $properties[$propertyId]),
false,
array(
"NAME"));
1720 while($section = $queryObject->getNext())
1721 $propertyValues[] = $section[
"~NAME"];
1727 if(!empty($properties[$propertyId]))
1729 $queryObject = CIBlockElement::getList(
array(),
array(
"ID" => $properties[$propertyId]),
1730 false,
false,
array(
'NAME'));
1731 while($element = $queryObject->getNext())
1732 $propertyValues[] = $element[
"~NAME"];
1739 $searchableContent .=
"\r\n".$propertyValue;
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],
1752 foreach($userResult as $user)
1754 $searchableContent .=
"\r\n" . CUser::formatName($siteNameFormat, $user,
true,
false);
1758 return $searchableContent;
1775 throw new ArgumentException(Loc::getMessage(
"LISTS_REQUIRED_PARAMETER",
array(
"#parameter#" =>
"iblockId")));
1778 $connection = Application::getInstance()->getConnection();
1779 $sqlString =
"SELECT COUNT(ID) as COUNT FROM b_iblock_element WHERE IBLOCK_ID=".$iblockId;
1781 $result = $queryObject->fetch();
1783 return intval(
$result[
"COUNT"]);
1788 return $iblockTypeId == COption::GetOptionString(
'lists',
'livefeed_iblock_type_id');
1807 if (!CModule::IncludeModule(
"bitrix24"))
1810 $featureName = (string)$featureName;
1812 if ($featureName ===
"")
1813 $featureName =
"lists_processes";
1815 if (!isset(static::$featuresCache[$featureName]))
1816 static::$featuresCache[$featureName] = \Bitrix\Bitrix24\Feature::isFeatureEnabled($featureName);
1818 return static::$featuresCache[$featureName];
1825 if (
$USER->isAdmin() ||
$USER->canDoOperation(
"bitrix24_config"))
1832 if (in_array(
$userId, $participants))
1839 if ($state &&
$userId === (
int) $state[
'STARTED_BY'])
1850 $optionData = Option::get(
"lists",
"iblock_lock_feature");
1851 $iblockIdsWithLockFeature = unserialize($optionData, [
'allowed_classes' =>
false]);
1852 if (!is_array($iblockIdsWithLockFeature))
1854 $iblockIdsWithLockFeature = [];
1856 return isset($iblockIdsWithLockFeature[
$iblockId]);
1861 $option = Option::get(
"lists",
"iblock_lock_feature");
1862 $iblockIdsWithLockFeature = (
$option !==
"" ? unserialize(
$option, [
'allowed_classes' =>
false]) : []);
1863 if (isset($iblockIdsWithLockFeature[
$iblockId]))
1865 unset($iblockIdsWithLockFeature[
$iblockId]);
1866 Option::set(
"lists",
"iblock_lock_feature", serialize($iblockIdsWithLockFeature));
1870 private static function deleteCacheToECrmProperty(
$fields): void
1872 if (!empty(
$fields[
'USER_TYPE']) &&
$fields[
'USER_TYPE'] ==
'ECrm')
1874 if (!empty(
$fields[
'USER_TYPE_SETTINGS']))
1876 if (!is_array(
$fields[
'USER_TYPE_SETTINGS']))
1878 $fields[
'USER_TYPE_SETTINGS'] = unserialize(
1879 $fields[
'USER_TYPE_SETTINGS'],
1880 [
'allowed_classes' =>
false]
1883 if (is_array(
$fields[
'USER_TYPE_SETTINGS']))
1885 foreach (
$fields[
'USER_TYPE_SETTINGS'] as $entityType => $marker)
1889 self::deleteListsCache(
'/lists/crm/attached/'.mb_strtolower($entityType).
'/');
1896 self::deleteListsCache(
'/lists/crm/attached/');
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)