Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basetemplate.php
1<?php
8
10{
12 protected $entity = null;
13
18 {
19 $this->entity = $entity;
20 }
21
27 public function getValuesEntity()
28 {
29 return $this->entity;
30 }
31
40 public function set(array $templates)
41 {
42 $templateList = \Bitrix\Iblock\InheritedPropertyTable::getList(array(
43 "select" => array("ID", "CODE", "TEMPLATE"),
44 "filter" => array(
45 "=IBLOCK_ID" => $this->entity->getIblockId(),
46 "=ENTITY_TYPE" => $this->entity->getType(),
47 "=ENTITY_ID" => $this->entity->getId(),
48 ),
49 ));
50 array_map("trim", $templates);
51 while ($row = $templateList->fetch())
52 {
53 $CODE = $row["CODE"];
54 if (array_key_exists($CODE, $templates))
55 {
56 if ($templates[$CODE] !== $row["TEMPLATE"])
57 {
58 if ($templates[$CODE] != "")
59 \Bitrix\Iblock\InheritedPropertyTable::update($row["ID"], array(
60 "TEMPLATE" => $templates[$CODE],
61 ));
62 else
63 \Bitrix\Iblock\InheritedPropertyTable::delete($row["ID"]);
64
65 $this->entity->deleteValues($row["ID"]);
66 }
67 unset($templates[$CODE]);
68 }
69 }
70
71 if (!empty($templates))
72 {
73 foreach ($templates as $CODE => $TEMPLATE)
74 {
75 if ($TEMPLATE != "")
76 {
77 \Bitrix\Iblock\InheritedPropertyTable::add(array(
78 "IBLOCK_ID" => $this->entity->getIblockId(),
79 "CODE" => $CODE,
80 "ENTITY_TYPE" => $this->entity->getType(),
81 "ENTITY_ID" => $this->entity->getId(),
82 "TEMPLATE" => $TEMPLATE,
83 ));
84 }
85 }
86 $this->entity->clearValues();
87 }
88 }
89
97 public function get(BaseValues $entity = null)
98 {
99 static $cache = array();
100 if ($entity === null)
102
103 $filter = array(
104 "=IBLOCK_ID" => $entity->getIblockId(),
105 "=ENTITY_TYPE" => $entity->getType(),
106 "=ENTITY_ID" => $entity->getId(),
107 );
108 $cacheKey = implode('|', $filter);
109 if (!isset($cache[$cacheKey]))
110 {
111 $result = array();
112 $templateList = \Bitrix\Iblock\InheritedPropertyTable::getList(array(
113 "select" => array("ID", "CODE", "TEMPLATE", "ENTITY_TYPE", "ENTITY_ID"),
114 "filter" => $filter,
115 ));
116 while ($row = $templateList->fetch())
117 {
118 $result[$row["CODE"]] = $row;
119 }
120 $cache[$cacheKey] = $result;
121 }
122 return $cache[$cacheKey];
123 }
124
135 {
136 static $cache = array();
137 $iblockId = $entity->getIblockId();
138 if (!isset($cache[$iblockId]))
139 {
140 $templateList = \Bitrix\Iblock\InheritedPropertyTable::getList(array(
141 "select" => array("ID"),
142 "filter" => array(
143 "=IBLOCK_ID" => $iblockId,
144 ),
145 "limit" => 1,
146 ));
147 $cache[$iblockId] = is_array($templateList->fetch());
148 }
149 return $cache[$iblockId];
150 }
151
158 public function delete()
159 {
160 $templateList = \Bitrix\Iblock\InheritedPropertyTable::getList(array(
161 "select" => array("ID"),
162 "filter" => array(
163 "=IBLOCK_ID" => $this->entity->getIblockId(),
164 "=ENTITY_TYPE" => $this->entity->getType(),
165 "=ENTITY_ID" => $this->entity->getId(),
166 ),
167 ));
168
169 while ($row = $templateList->fetch())
170 {
171 \Bitrix\Iblock\InheritedPropertyTable::delete($row["ID"]);
172 }
173 }
174
184 protected function findTemplatesRecursive(BaseValues $entity, array &$templates)
185 {
186 foreach ($this->get($entity) as $CODE => $templateData)
187 {
188 if (!array_key_exists($CODE, $templates))
189 $templates[$CODE] = $templateData;
190 }
191
192 foreach ($entity->getParents() as $parent)
193 {
194 $this->findTemplatesRecursive($parent, $templates);
195 }
196 }
197
204 public function findTemplates()
205 {
206 $templates = array();
207 if ($this->hasTemplates($this->entity))
208 {
209 $this->findTemplatesRecursive($this->entity, $templates);
210 foreach ($templates as $CODE => $row)
211 {
212 if ($row["ENTITY_TYPE"] == $this->entity->getType() && $row["ENTITY_ID"] == $this->entity->getId())
213 $templates[$CODE]["INHERITED"] = "N";
214 else
215 $templates[$CODE]["INHERITED"] = "Y";
216 }
217 }
218 return $templates;
219 }
220}
findTemplatesRecursive(BaseValues $entity, array &$templates)