Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
elementvalues.php
1<?php
8
10{
11 protected $sectionId = 0;
12 protected $elementId = 0;
13
19 {
20 parent::__construct($iblockId);
21 $this->elementId = (int)$elementId;
22 $this->queue->addElement($this->iblockId, $this->elementId);
23 }
24
30 public function getValueTableName()
31 {
32 return "b_iblock_section_iprop";
33 }
34
40 public function getType()
41 {
42 return "E";
43 }
44
50 public function getId()
51 {
52 return $this->elementId;
53 }
54
60 public function createTemplateEntity()
61 {
62 return new \Bitrix\Iblock\Template\Entity\Element($this->elementId);
63 }
64
72 public function setParents($sectionId)
73 {
74 if (is_array($sectionId))
75 {
76 if (!empty($sectionId))
77 {
78 $sectionId = array_map("intval", $sectionId);
79 $this->sectionId = min($sectionId);
80 }
81 }
82 else
83 {
84 $this->sectionId = (int)$sectionId;
85 }
86 }
87
94 public function getParents()
95 {
96 $parents = array();
97 if ($this->elementId > 0)
98 {
99 $elementList = \Bitrix\Iblock\ElementTable::getList(array(
100 "select" => array("IBLOCK_SECTION_ID"),
101 "filter" => array("=ID" => $this->elementId),
102 ));
103 $element = $elementList->fetch();
104 if ($element && $element["IBLOCK_SECTION_ID"] > 0)
105 $parents[] = new SectionValues($this->iblockId, $element["IBLOCK_SECTION_ID"]);
106 else
107 $parents[] = new IblockValues($this->iblockId);
108 }
109 elseif ($this->sectionId > 0)
110 {
111 $parents[] = new SectionValues($this->iblockId, $this->sectionId);
112 }
113 else
114 {
115 $parents[] = new IblockValues($this->iblockId);
116 }
117 return $parents;
118 }
119
126 public function queryValues()
127 {
128 $connection = \Bitrix\Main\Application::getConnection();
129 $result = array();
130 if ($this->hasTemplates())
131 {
132 if ($this->queue->getElement($this->iblockId, $this->elementId) === false)
133 {
134 $ids = $this->queue->get($this->iblockId);
135 $query = $connection->query("
136 SELECT
137 P.ID
138 ,P.CODE
139 ,P.TEMPLATE
140 ,P.ENTITY_TYPE
141 ,P.ENTITY_ID
142 ,IP.VALUE
143 ,IP.ELEMENT_ID
144 FROM
145 b_iblock_element_iprop IP
146 INNER JOIN b_iblock_iproperty P ON P.ID = IP.IPROP_ID
147 WHERE
148 IP.IBLOCK_ID = ".$this->iblockId."
149 AND IP.ELEMENT_ID in (".implode(", ", $ids).")
150 ");
151 $result = array();
152 while ($row = $query->fetch())
153 {
154 $result[$row["ELEMENT_ID"]][$row["CODE"]] = $row;
155 }
156 $this->queue->set($this->iblockId, $result);
157 }
158 $result = $this->queue->getElement($this->iblockId, $this->elementId);
159
160 if (empty($result))
161 {
162 $result = parent::queryValues();
163 if (!empty($result))
164 {
165 $sqlHelper = $connection->getSqlHelper();
166 $elementList = \Bitrix\Iblock\ElementTable::getList(array(
167 "select" => array("IBLOCK_SECTION_ID"),
168 "filter" => array("=ID" => $this->elementId),
169 ));
170 $element = $elementList->fetch();
171 $element['IBLOCK_SECTION_ID'] = (int)$element['IBLOCK_SECTION_ID'];
172
173 $fields = array(
174 "IBLOCK_ID",
175 "SECTION_ID",
176 "ELEMENT_ID",
177 "IPROP_ID",
178 "VALUE",
179 );
180 $rows = array();
181 foreach ($result as $CODE => $row)
182 {
183 $rows[] = array(
184 $this->iblockId,
185 $element["IBLOCK_SECTION_ID"],
186 $this->elementId,
187 $row["ID"],
188 $sqlHelper->forSql($row["VALUE"]),
189 );
190 }
191 $this->insertValues("b_iblock_element_iprop", $fields, $rows);
192 }
193 }
194 }
195 return $result;
196 }
197
203 function clearValues()
204 {
205 $connection = \Bitrix\Main\Application::getConnection();
206 $connection->query("
207 DELETE FROM b_iblock_element_iprop
208 WHERE IBLOCK_ID = ".$this->iblockId."
209 AND ELEMENT_ID = ".$this->elementId."
210 ");
211 $this->queue->deleteElement($this->iblockId, $this->elementId);
212 }
213}
insertValues($tableName, $fields, $rows)