1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
iblockpropresult.php
См. документацию.
1<?php
2
5
7{
8 protected $IBLOCK_ID = 0;
9 protected $VERSION = 0;
10 protected array $arProperties = [];
11 protected static array $propertiesCache = [];
13 protected $lastRes = null;
14 protected $extMode = false;
16 protected $arDescriptions = array();
17
18 public function Fetch()
19 {
20 global $DB;
21
22 if (isset($this->lastRes))
23 {
25 $this->lastRes = null;
26 }
27 else
28 {
29 $res = parent::Fetch();
30 }
31
32 if ($res && isset($res["USER_TYPE"]) && $res["USER_TYPE"]!="")
33 {
34 $arUserType = CIBlockProperty::GetUserType($res["USER_TYPE"]);
35 if (isset($arUserType["ConvertFromDB"]))
36 {
37 if(array_key_exists("VALUE", $res))
38 {
39 $value = array("VALUE"=>$res["VALUE"],"DESCRIPTION"=>"");
40 $value = call_user_func_array($arUserType["ConvertFromDB"],array($res,$value));
41 $res["VALUE"] = $value["VALUE"] ?? null;
42 }
43
44 if(array_key_exists("DEFAULT_VALUE", $res))
45 {
46 $value = array("VALUE"=>$res["DEFAULT_VALUE"],"DESCRIPTION"=>"");
47 $value = call_user_func_array($arUserType["ConvertFromDB"],array($res,$value));
48 $res["DEFAULT_VALUE"] = $value["VALUE"] ?? null;
49 }
50 }
51 if($res["USER_TYPE_SETTINGS"] <> '')
52 {
53 $res["USER_TYPE_SETTINGS"] = unserialize($res["USER_TYPE_SETTINGS"], ['allowed_classes' => false]);
54 }
55 }
56
57 if($res && !empty($this->arProperties))
58 {
59 $this->initPropertiesValues($res["IBLOCK_ELEMENT_ID"]);
60 if ($this->VERSION == 2)
61 {
62 $arUpdate = array();
63 foreach ($this->arProperties as $arProp)
64 {
65 $field_name = "PROPERTY_".$arProp["ID"];
66 if ($arProp["MULTIPLE"] == "Y")
67 {
68 $descr_name = "DESCRIPTION_".$arProp["ID"];
69 $value_id_name = "PROPERTY_VALUE_ID_".$arProp["ID"];
70
71 if(is_object($res[$field_name]))
72 $res[$field_name] = $res[$field_name]->load();
73
74 $update = false;
75 if($res[$field_name] == '')
76 {
77 $update = true;
78 }
79 else
80 {
81 $tmp = unserialize($res[$field_name], ['allowed_classes' => false]);
82 if (!isset($tmp['ID']))
83 $update = true;
84 }
85 if ($update)
86 {
87 $strSql = "
88 SELECT ID, VALUE, DESCRIPTION
89 FROM b_iblock_element_prop_m".$arProp["IBLOCK_ID"]."
90 WHERE
91 IBLOCK_ELEMENT_ID = ".(int)$res["IBLOCK_ELEMENT_ID"]."
92 AND IBLOCK_PROPERTY_ID = ".(int)$arProp["ID"]."
93 ORDER BY ID
94 ";
95 $rs = $DB->Query($strSql);
96 $res[$field_name] = array();
97 $res[$descr_name] = array();
98 $res[$value_id_name] = array();
99 while($ar=$rs->Fetch())
100 {
101 $res[$field_name][] = $ar["VALUE"];
102 $res[$descr_name][] = $ar["DESCRIPTION"];
103 $res[$value_id_name][] = $ar['ID'];
104 }
105 $arUpdate["b_iblock_element_prop_s".$arProp["IBLOCK_ID"]]["PROPERTY_".$arProp["ID"]] = serialize(array("VALUE"=>$res[$field_name],"DESCRIPTION"=>$res[$descr_name],"ID"=>$res[$value_id_name]));
106 }
107 else
108 {
109 $res[$field_name] = $tmp["VALUE"];
110 $res[$descr_name] = $tmp["DESCRIPTION"];
111 $res[$value_id_name] = $tmp["ID"];
112 }
113
114 if ($this->extMode)
115 {
116 foreach ($res[$field_name] as $field_key => $VALUE)
117 {
118 $this->addPropertyValue($arProp["ID"], $VALUE);
119 $this->addPropertyData($arProp["ID"], $res[$value_id_name][$field_key], $res[$descr_name][$field_key]);
120 }
121 }
122 else
123 {
124 foreach($res[$field_name] as $VALUE)
125 $this->addPropertyValue($arProp["ID"], $VALUE);
126 }
127 }
128 else
129 {
130 if ($res[$field_name] != "")
131 {
132 if ($this->extMode && $arProp["PROPERTY_TYPE"] == PropertyTable::TYPE_NUMBER)
133 {
134 $res[$field_name] = CIBlock::NumberFormat($res[$field_name]);
135 }
136 $this->addPropertyValue($arProp["ID"], $res[$field_name]);
137 }
138 if ($this->extMode)
139 {
140 $this->addPropertyData(
141 $arProp["ID"],
142 $res["IBLOCK_ELEMENT_ID"].':'.$arProp["ID"],
143 $res["DESCRIPTION_".$arProp["ID"]] ?? null
144 );
145 }
146 }
147 }
148 foreach($arUpdate as $strTable=>$arFields)
149 {
150 $strUpdate = $DB->PrepareUpdate($strTable, $arFields);
151 if($strUpdate!="")
152 {
153 $strSql = "UPDATE ".$strTable." SET ".$strUpdate." WHERE IBLOCK_ELEMENT_ID = ".intval($res["IBLOCK_ELEMENT_ID"]);
154 $DB->QueryBind($strSql, $arFields);
155 }
156 }
158 if ($this->extMode)
159 {
160 $res['PROPERTY_VALUE_ID'] = $this->arPropertyValuesID;
161 $res['DESCRIPTION'] = $this->arDescriptions;
162 }
163 }
164 else
165 {
166 do {
167 if (isset($this->arProperties[$res["IBLOCK_PROPERTY_ID"]]))
168 {
169 if ($this->arProperties[$res["IBLOCK_PROPERTY_ID"]]["PROPERTY_TYPE"] == "N" && !$this->extMode)
170 $this->addPropertyValue($res["IBLOCK_PROPERTY_ID"], $res["VALUE_NUM"]);
171 else
172 $this->addPropertyValue($res["IBLOCK_PROPERTY_ID"], $res["VALUE"]);
173 if ($this->extMode)
174 {
175 $this->addPropertyData($res["IBLOCK_PROPERTY_ID"], $res['PROPERTY_VALUE_ID'], $res['DESCRIPTION']);
176 }
177 }
178 $res = parent::Fetch();
179 } while ($res && ($res["IBLOCK_ELEMENT_ID"] == $this->arPropertiesValues["IBLOCK_ELEMENT_ID"]));
180
181 $this->lastRes = $res;
183 $this->arPropertiesValues = array();
184 if ($this->extMode)
185 {
186 $res['PROPERTY_VALUE_ID'] = $this->arPropertyValuesID;
187 $res['DESCRIPTION'] = $this->arDescriptions;
188 $this->arPropertyValuesID = array();
189 $this->arDescriptions = array();
190 }
191 }
192 }
193
194 return $res;
195 }
196
197 private function addPropertyValue($IBLOCK_PROPERTY_ID, $VALUE): void
198 {
199 if (isset($this->arProperties[$IBLOCK_PROPERTY_ID]))
200 {
201 if ($this->arProperties[$IBLOCK_PROPERTY_ID]["MULTIPLE"] == "Y")
202 $this->arPropertiesValues[$IBLOCK_PROPERTY_ID][] = $VALUE;
203 else
204 $this->arPropertiesValues[$IBLOCK_PROPERTY_ID] = $VALUE;
205 }
206 }
207
208 private function initPropertiesValues($IBLOCK_ELEMENT_ID): void
209 {
210 $this->arPropertiesValues["IBLOCK_ELEMENT_ID"] = $IBLOCK_ELEMENT_ID;
211 foreach ($this->arProperties as $arProp)
212 {
213 if ($arProp["MULTIPLE"] == "Y")
214 $this->arPropertiesValues[$arProp["ID"]] = array();
215 else
216 $this->arPropertiesValues[$arProp["ID"]] = false;
217 if ($this->extMode)
218 {
219 if ($arProp["MULTIPLE"] == "Y")
220 {
221 $this->arPropertyValuesID[$arProp["ID"]] = array();
222 $this->arDescriptions[$arProp["ID"]] = array();
223 }
224 else
225 {
226 $this->arPropertyValuesID[$arProp["ID"]] = '';
227 $this->arDescriptions[$arProp["ID"]] = null;
228 }
229 }
230 }
231 }
232
233 private function addPropertyData($IBLOCK_PROPERTY_ID, $VALUE_ID, $DESCRIPTION): void
234 {
235 if (isset($this->arProperties[$IBLOCK_PROPERTY_ID]))
236 {
237 if ($this->arProperties[$IBLOCK_PROPERTY_ID]["MULTIPLE"] == "Y")
238 {
239 $this->arPropertyValuesID[$IBLOCK_PROPERTY_ID][] = $VALUE_ID;
240 $this->arDescriptions[$IBLOCK_PROPERTY_ID][] = $DESCRIPTION;
241 }
242 else
243 {
244 $this->arPropertyValuesID[$IBLOCK_PROPERTY_ID] = $VALUE_ID;
245 $this->arDescriptions[$IBLOCK_PROPERTY_ID] = $DESCRIPTION;
246 }
247 }
248 }
249
250 public function setIBlock($IBLOCK_ID, $propertyID = [])
251 {
252 $this->VERSION = CIBlockElement::GetIBVersion($IBLOCK_ID);
253
254 if (!empty($propertyID))
255 {
256 Collection::normalizeArrayValuesByInt($propertyID);
257 }
258 $this->arProperties = [];
259 if (
260 !empty($propertyID)
261 || !isset(self::$propertiesCache[$IBLOCK_ID])
262 )
263 {
264 $filter = [
265 "IBLOCK_ID" => $IBLOCK_ID,
266 ];
267 if (!empty($propertyID))
268 {
269 $filter['ID'] = $propertyID;
270 }
271 $propertyIterator = PropertyTable::getList([
272 'select' => [
273 'ID',
274 'IBLOCK_ID',
275 'NAME',
276 'ACTIVE',
277 'SORT',
278 'CODE',
279 'DEFAULT_VALUE',
280 'PROPERTY_TYPE',
281 'MULTIPLE',
282 'LINK_IBLOCK_ID',
283 'VERSION',
284 'USER_TYPE',
285 'USER_TYPE_SETTINGS',
286 ],
287 'filter' => $filter,
288 'order' => [
289 'ID' => 'ASC',
290 ],
291 'cache' => [
292 'ttl' => 86400,
293 ],
294 ]);
295 while ($property = $propertyIterator->fetch())
296 {
297 if ($property['USER_TYPE'])
298 {
299 $userType = CIBlockProperty::GetUserType($property['USER_TYPE']);
300 if (isset($userType["ConvertFromDB"]))
301 {
302 if (array_key_exists("DEFAULT_VALUE", $property))
303 {
304 $value = array("VALUE" => $property["DEFAULT_VALUE"], "DESCRIPTION" => "");
305 $value = call_user_func_array($userType["ConvertFromDB"], array($property, $value));
306 $property["DEFAULT_VALUE"] = $value["VALUE"] ?? null;
307 }
308 }
309 }
310 if ($property['USER_TYPE_SETTINGS'] !== '' && $property['USER_TYPE_SETTINGS'] !== null)
311 $property['USER_TYPE_SETTINGS'] = unserialize($property['USER_TYPE_SETTINGS'], ['allowed_classes' => false]);
312 $this->arProperties[$property['ID']] = $property;
313 }
314 unset($property, $propertyIterator);
315 if (empty($propertyID))
316 {
317 self::$propertiesCache[$IBLOCK_ID] = $this->arProperties;
318 }
319 }
320 else
321 {
322 $this->arProperties = self::$propertiesCache[$IBLOCK_ID];
323 }
324 }
325
326 public function setMode($extMode)
327 {
328 $this->extMode = $extMode;
329 $this->arPropertyValuesID = array();
330 $this->arDescriptions = array();
331 }
332}
$DB
Определения dbresult.php:40
Определения dbresult.php:88
setIBlock($IBLOCK_ID, $propertyID=[])
Определения iblockpropresult.php:250
static array $propertiesCache
Определения iblockpropresult.php:11
array $arProperties
Определения iblockpropresult.php:10
setMode($extMode)
Определения iblockpropresult.php:326
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$filter
Определения iblock_catalog_list.php:54
$DESCRIPTION
Определения menu_edit.php:224
$ar
Определения options.php:199
$rs
Определения action.php:82