Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sectionvalues.php
1<?php
8
10{
11 protected $sectionId = 0;
13 protected $queue = null;
14
20 {
21 parent::__construct($iblockId);
22 $this->sectionId = (int)$sectionId;
23 $this->queue->addElement($this->iblockId, $this->sectionId);
24 }
25
31 public function getValueTableName()
32 {
33 return "b_iblock_section_iprop";
34 }
35
41 public function getType()
42 {
43 return "S";
44 }
45
51 public function getId()
52 {
53 return $this->sectionId;
54 }
55
61 public function createTemplateEntity()
62 {
63 return new \Bitrix\Iblock\Template\Entity\Section($this->sectionId);
64 }
65
72 public function getParents()
73 {
74 $parents = array();
75 $sectionList = \Bitrix\Iblock\SectionTable::getList(array(
76 "select" => array("IBLOCK_SECTION_ID"),
77 "filter" => array("=ID" => $this->sectionId),
78 ));
79 $section = $sectionList->fetch();
80 if ($section && $section["IBLOCK_SECTION_ID"] > 0)
81 $parents[] = new SectionValues($this->iblockId, $section["IBLOCK_SECTION_ID"]);
82 else
83 $parents[] = new IblockValues($this->iblockId);
84 return $parents;
85 }
86
93 public function queryValues()
94 {
95 $connection = \Bitrix\Main\Application::getConnection();
96 $result = array();
97 if ($this->hasTemplates())
98 {
99 if ($this->queue->getElement($this->iblockId, $this->sectionId) === false)
100 {
101 $ids = $this->queue->get($this->iblockId);
102 $query = $connection->query("
103 SELECT
104 P.ID
105 ,P.CODE
106 ,P.TEMPLATE
107 ,P.ENTITY_TYPE
108 ,P.ENTITY_ID
109 ,IP.VALUE
110 ,IP.SECTION_ID
111 FROM
112 b_iblock_section_iprop IP
113 INNER JOIN b_iblock_iproperty P ON P.ID = IP.IPROP_ID
114 WHERE
115 IP.IBLOCK_ID = ".$this->iblockId."
116 AND IP.SECTION_ID in (".implode(", ", $ids).")
117 ");
118 $result = array();
119 while ($row = $query->fetch())
120 {
121 $result[$row["SECTION_ID"]][$row["CODE"]] = $row;
122 }
123 $this->queue->set($this->iblockId, $result);
124 }
125 $result = $this->queue->getElement($this->iblockId, $this->sectionId);
126
127 if (empty($result))
128 {
129 $sqlHelper = $connection->getSqlHelper();
130 $fields = array(
131 "IBLOCK_ID",
132 "SECTION_ID",
133 "IPROP_ID",
134 "VALUE",
135 );
136 $rows = array();
137 $result = parent::queryValues();
138 foreach ($result as $row)
139 {
140 $rows[] = array(
141 $this->iblockId,
142 $this->sectionId,
143 $row["ID"],
144 $sqlHelper->forSql($row["VALUE"]),
145 );
146 }
147 $this->insertValues("b_iblock_section_iprop", $fields, $rows);
148 }
149 }
150 return $result;
151 }
152
158 function clearValues()
159 {
160 $connection = \Bitrix\Main\Application::getConnection();
161 $sectionList = \Bitrix\Iblock\SectionTable::getList(array(
162 "select" => array("LEFT_MARGIN", "RIGHT_MARGIN"),
163 "filter" => array("=ID" => $this->sectionId),
164 ));
165 $section = $sectionList->fetch();
166 if ($section)
167 {
168 $connection->query("
169 DELETE FROM b_iblock_element_iprop
170 WHERE IBLOCK_ID = ".$this->iblockId."
171 AND ELEMENT_ID in (
172 SELECT BSE.IBLOCK_ELEMENT_ID
173 FROM b_iblock_section_element BSE
174 INNER JOIN b_iblock_section BS ON BSE.IBLOCK_SECTION_ID = BS.ID AND BSE.ADDITIONAL_PROPERTY_ID IS NULL
175 WHERE BS.IBLOCK_ID = ".$this->iblockId."
176 AND BS.LEFT_MARGIN <= ".$section["RIGHT_MARGIN"]."
177 AND BS.RIGHT_MARGIN >= ".$section["LEFT_MARGIN"]."
178 )
179 ");
180 $connection->query("
181 DELETE FROM b_iblock_section_iprop
182 WHERE IBLOCK_ID = ".$this->iblockId."
183 AND SECTION_ID in (
184 SELECT BS.ID
185 FROM b_iblock_section BS
186 WHERE BS.IBLOCK_ID = ".$this->iblockId."
187 AND BS.LEFT_MARGIN <= ".$section["RIGHT_MARGIN"]."
188 AND BS.RIGHT_MARGIN >= ".$section["LEFT_MARGIN"]."
189 )
190 ");
191 }
193 }
194}
insertValues($tableName, $fields, $rows)