Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
iblock.php
1<?php
3
4use Bitrix\Iblock\Copy\Implement\Iblock as IblockImplementer;
7
8class Iblock extends IblockImplementer
9{
10 public function add(Container $container, array $fields)
11 {
12 $iblockId = parent::add($container, $fields);
13
14 if ($iblockId)
15 {
16 $this->setUrlTemplate($container, $iblockId, $fields);
17 }
18
19 return $iblockId;
20 }
21
22 public function copyChildren(Container $container, $iblockId, $copiedIblockId)
23 {
24 $this->copyLockFeature($iblockId, $copiedIblockId);
25
26 return parent::copyChildren($container, $iblockId, $copiedIblockId);
27 }
28
29 protected function cleanCache(int $iblockId): void
30 {
31 parent::cleanCache($iblockId);
32
33 if ($this->cacheManager)
34 {
35 $this->cacheManager->clearByTag("lists_list_".$iblockId);
36 $this->cacheManager->clearByTag("lists_list_any");
37 }
38 }
39
40 protected function getSocnetPermission($iblockId, $socnetGroupId): array
41 {
42 $rights = [];
43 $i = 0;
44 $socnetPerm = \CLists::getSocnetPermission($iblockId);
45 foreach ($socnetPerm as $role => $permission)
46 {
47 if ($permission > "W")
48 {
49 $permission = "W";
50 }
51 switch ($role)
52 {
53 case "A":
54 case "E":
55 case "K":
56 $rights["n" . ($i++)] = [
57 "GROUP_CODE" => "SG" . $socnetGroupId . "_" . $role,
58 "IS_INHERITED" => "N",
59 "TASK_ID" => \CIBlockRights::letterToTask($permission),
60 ];
61 break;
62 case "L":
63 $rights["n" . ($i++)] = [
64 "GROUP_CODE" => "AU",
65 "IS_INHERITED" => "N",
66 "TASK_ID" => \CIBlockRights::letterToTask($permission),
67 ];
68 break;
69 case "N":
70 $rights["n" . ($i++)] = [
71 "GROUP_CODE" => "G2",
72 "IS_INHERITED" => "N",
73 "TASK_ID" => \CIBlockRights::letterToTask($permission),
74 ];
75 break;
76 }
77 }
78 return $rights;
79 }
80
81 private function copyLockFeature(int $iblockId, int $copiedIblockId): void
82 {
83 $option = Option::get("lists", "iblock_lock_feature");
84 $iblockIdsWithLockFeature = ($option !== "" ? unserialize($option) : []);
85 if (isset($iblockIdsWithLockFeature[$iblockId]))
86 {
87 $iblockIdsWithLockFeature[$copiedIblockId] = $copiedIblockId;
88 Option::set("lists", "iblock_lock_feature", serialize($iblockIdsWithLockFeature));
89 }
90 }
91
92 private function setUrlTemplate(Container $container, int $iblockId, array $fields)
93 {
94 $list = new \CList($iblockId);
95
96 $dictionary = $container->getDictionary();
97
98 if (!empty($dictionary["LIST_ELEMENT_URL"]))
99 {
100 $listElementUrl = $dictionary["LIST_ELEMENT_URL"];
101 }
102 else
103 {
104 $listElementUrl = $list->getUrlByIblockId($container->getEntityId());
105 $listElementUrl = str_replace($container->getEntityId(), $iblockId, $listElementUrl);
106 }
107
108 $socnetGroupId = ($fields["SOCNET_GROUP_ID"] ? $fields["SOCNET_GROUP_ID"] : 0);
109
110 $list->actualizeDocumentAdminPage(str_replace(
111 ["#list_id#", "#group_id#"],
112 [$iblockId, $socnetGroupId],
113 $listElementUrl
114 ));
115 }
116}
getSocnetPermission($iblockId, $socnetGroupId)
Definition iblock.php:40
copyChildren(Container $container, $iblockId, $copiedIblockId)
Definition iblock.php:22
add(Container $container, array $fields)
Definition iblock.php:10