Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basevalues.php
1<?php
8
9abstract class BaseValues
10{
12 protected $iblockId = null;
13
15 protected $values = false;
16
18 protected $queue = null;
19
23 public function __construct($iblockId)
24 {
25 $this->iblockId = (int)$iblockId;
26 $this->queue = ValuesQueue::getInstance(get_called_class());
27 }
28
34 public function getIblockId()
35 {
36 return $this->iblockId;
37 }
38
44 public function getValueTableName()
45 {
46 return "";
47 }
48
54 abstract public function getType();
55
61 abstract public function getId();
62
68 abstract public function createTemplateEntity();
69
75 public function getParents()
76 {
77 return array();
78 }
79
86 public function getParent()
87 {
88 $parents = $this->getParents();
89 if (isset($parents[0]))
90 return $parents[0];
91 else
92 return null;
93 }
94
101 public function getValues()
102 {
103 if ($this->values === false)
104 $this->values = $this->queryValues();
105
106 $result = array();
107 foreach ($this->values as $CODE => $row)
108 {
109 $result[$CODE] = htmlspecialcharsEx($row["VALUE"]);
110 }
111 return $result;
112 }
113
121 public function getValue($propertyCode)
122 {
123 if ($this->values === false)
124 $this->values = $this->queryValues();
125
126 if (isset($this->values[$propertyCode]))
127 return htmlspecialcharsEx($this->values[$propertyCode]["VALUE"]);
128 else
129 return "";
130 }
131
139 public function queryValues()
140 {
141 $templateInstance = new BaseTemplate($this);
142 $templates = $templateInstance->findTemplates();
143 foreach ($templates as $CODE => $row)
144 {
145 $templates[$CODE]["VALUE"] = \Bitrix\Iblock\Template\Engine::process($this->createTemplateEntity(), $row["TEMPLATE"]);
146 }
147 return $templates;
148 }
149
155 public function hasTemplates()
156 {
157 $templateInstance = new BaseTemplate($this);
158 return $templateInstance->hasTemplates($this);
159 }
160
166 abstract function clearValues();
167
175 public function deleteValues($ipropertyId)
176 {
177 $ipropertyId = (int)$ipropertyId;
178 $connection = \Bitrix\Main\Application::getConnection();
179 $connection->query("
180 DELETE FROM b_iblock_iblock_iprop
181 WHERE IPROP_ID = ".$ipropertyId."
182 ");
183 $connection->query("
184 DELETE FROM b_iblock_section_iprop
185 WHERE IPROP_ID = ".$ipropertyId."
186 ");
187 $connection->query("
188 DELETE FROM b_iblock_element_iprop
189 WHERE IPROP_ID = ".$ipropertyId."
190 ");
192 }
193
203 protected function insertValues($tableName, $fields, $rows)
204 {
205 $connection = \Bitrix\Main\Application::getConnection();
206 $head = "REPLACE INTO $tableName (".implode(", ", $fields).") VALUES ";
207 $maxBodySize = 1024*1024; //1 Mb
208 $body = array();
209 $bodySize = 0;
210 foreach ($rows as $row)
211 {
212 $values = "('".implode("', '", $row)."')";
213 $bodySize += mb_strlen($values);
214 $body[] = $values;
215 if ($bodySize > $maxBodySize)
216 {
217 $connection->query($head.implode(", ", $body));
218 $body = array();
219 $bodySize = 0;
220 }
221 }
222 if ($body)
223 {
224 $connection->query($head.implode(", ", $body));
225 }
226 }
227
236 public static function queue($iblockId, $id)
237 {
238 ValuesQueue::getInstance(get_called_class())->addElement($iblockId, $id);
239 }
240}
insertValues($tableName, $fields, $rows)