22 if (isset($this->lastRes))
25 $this->lastRes =
null;
29 $res = parent::Fetch();
32 if (
$res && isset(
$res[
"USER_TYPE"]) &&
$res[
"USER_TYPE"]!=
"")
34 $arUserType = CIBlockProperty::GetUserType(
$res[
"USER_TYPE"]);
35 if (isset($arUserType[
"ConvertFromDB"]))
37 if(array_key_exists(
"VALUE",
$res))
39 $value =
array(
"VALUE"=>
$res[
"VALUE"],
"DESCRIPTION"=>
"");
40 $value = call_user_func_array($arUserType[
"ConvertFromDB"],
array(
$res,$value));
41 $res[
"VALUE"] = $value[
"VALUE"] ??
null;
44 if(array_key_exists(
"DEFAULT_VALUE",
$res))
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;
51 if(
$res[
"USER_TYPE_SETTINGS"] <>
'')
53 $res[
"USER_TYPE_SETTINGS"] = unserialize(
$res[
"USER_TYPE_SETTINGS"], [
'allowed_classes' =>
false]);
57 if(
$res && !empty($this->arProperties))
59 $this->initPropertiesValues(
$res[
"IBLOCK_ELEMENT_ID"]);
60 if ($this->VERSION == 2)
63 foreach ($this->arProperties as $arProp)
65 $field_name =
"PROPERTY_".$arProp[
"ID"];
66 if ($arProp[
"MULTIPLE"] ==
"Y")
68 $descr_name =
"DESCRIPTION_".$arProp[
"ID"];
69 $value_id_name =
"PROPERTY_VALUE_ID_".$arProp[
"ID"];
71 if(is_object(
$res[$field_name]))
72 $res[$field_name] =
$res[$field_name]->load();
75 if(
$res[$field_name] ==
'')
81 $tmp = unserialize(
$res[$field_name], [
'allowed_classes' =>
false]);
82 if (!isset(
$tmp[
'ID']))
88 SELECT ID, VALUE, DESCRIPTION
89 FROM b_iblock_element_prop_m".$arProp[
"IBLOCK_ID"].
"
91 IBLOCK_ELEMENT_ID = ".(int)
$res[
"IBLOCK_ELEMENT_ID"].
"
92 AND IBLOCK_PROPERTY_ID = ".(
int)$arProp[
"ID"].
"
101 $res[$field_name][] =
$ar[
"VALUE"];
102 $res[$descr_name][] =
$ar[
"DESCRIPTION"];
103 $res[$value_id_name][] =
$ar[
'ID'];
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]));
110 $res[$descr_name] =
$tmp[
"DESCRIPTION"];
116 foreach (
$res[$field_name] as $field_key => $VALUE)
118 $this->addPropertyValue($arProp[
"ID"], $VALUE);
119 $this->addPropertyData($arProp[
"ID"],
$res[$value_id_name][$field_key],
$res[$descr_name][$field_key]);
124 foreach(
$res[$field_name] as $VALUE)
125 $this->addPropertyValue($arProp[
"ID"], $VALUE);
130 if (
$res[$field_name] !=
"")
132 if ($this->extMode && $arProp[
"PROPERTY_TYPE"] == PropertyTable::TYPE_NUMBER)
134 $res[$field_name] = CIBlock::NumberFormat(
$res[$field_name]);
136 $this->addPropertyValue($arProp[
"ID"],
$res[$field_name]);
140 $this->addPropertyData(
142 $res[
"IBLOCK_ELEMENT_ID"].
':'.$arProp[
"ID"],
143 $res[
"DESCRIPTION_".$arProp[
"ID"]] ??
null
148 foreach($arUpdate as $strTable=>
$arFields)
153 $strSql =
"UPDATE ".$strTable.
" SET ".$strUpdate.
" WHERE IBLOCK_ELEMENT_ID = ".intval(
$res[
"IBLOCK_ELEMENT_ID"]);
167 if (isset($this->arProperties[
$res[
"IBLOCK_PROPERTY_ID"]]))
169 if ($this->arProperties[
$res[
"IBLOCK_PROPERTY_ID"]][
"PROPERTY_TYPE"] ==
"N" && !$this->extMode)
170 $this->addPropertyValue(
$res[
"IBLOCK_PROPERTY_ID"],
$res[
"VALUE_NUM"]);
172 $this->addPropertyValue(
$res[
"IBLOCK_PROPERTY_ID"],
$res[
"VALUE"]);
175 $this->addPropertyData(
$res[
"IBLOCK_PROPERTY_ID"],
$res[
'PROPERTY_VALUE_ID'],
$res[
'DESCRIPTION']);
178 $res = parent::Fetch();
179 }
while (
$res && (
$res[
"IBLOCK_ELEMENT_ID"] == $this->arPropertiesValues[
"IBLOCK_ELEMENT_ID"]));
181 $this->lastRes =
$res;
183 $this->arPropertiesValues =
array();
188 $this->arPropertyValuesID =
array();
189 $this->arDescriptions =
array();
197 private function addPropertyValue($IBLOCK_PROPERTY_ID, $VALUE): void
199 if (isset($this->arProperties[$IBLOCK_PROPERTY_ID]))
201 if ($this->arProperties[$IBLOCK_PROPERTY_ID][
"MULTIPLE"] ==
"Y")
202 $this->arPropertiesValues[$IBLOCK_PROPERTY_ID][] = $VALUE;
204 $this->arPropertiesValues[$IBLOCK_PROPERTY_ID] = $VALUE;
208 private function initPropertiesValues($IBLOCK_ELEMENT_ID): void
210 $this->arPropertiesValues[
"IBLOCK_ELEMENT_ID"] = $IBLOCK_ELEMENT_ID;
211 foreach ($this->arProperties as $arProp)
213 if ($arProp[
"MULTIPLE"] ==
"Y")
214 $this->arPropertiesValues[$arProp[
"ID"]] =
array();
216 $this->arPropertiesValues[$arProp[
"ID"]] =
false;
219 if ($arProp[
"MULTIPLE"] ==
"Y")
221 $this->arPropertyValuesID[$arProp[
"ID"]] =
array();
222 $this->arDescriptions[$arProp[
"ID"]] =
array();
226 $this->arPropertyValuesID[$arProp[
"ID"]] =
'';
227 $this->arDescriptions[$arProp[
"ID"]] =
null;
233 private function addPropertyData($IBLOCK_PROPERTY_ID, $VALUE_ID,
$DESCRIPTION): void
235 if (isset($this->arProperties[$IBLOCK_PROPERTY_ID]))
237 if ($this->arProperties[$IBLOCK_PROPERTY_ID][
"MULTIPLE"] ==
"Y")
239 $this->arPropertyValuesID[$IBLOCK_PROPERTY_ID][] = $VALUE_ID;
240 $this->arDescriptions[$IBLOCK_PROPERTY_ID][] =
$DESCRIPTION;
244 $this->arPropertyValuesID[$IBLOCK_PROPERTY_ID] = $VALUE_ID;
245 $this->arDescriptions[$IBLOCK_PROPERTY_ID] =
$DESCRIPTION;
252 $this->VERSION = CIBlockElement::GetIBVersion(
$IBLOCK_ID);
254 if (!empty($propertyID))
256 Collection::normalizeArrayValuesByInt($propertyID);
258 $this->arProperties = [];
267 if (!empty($propertyID))
271 $propertyIterator = PropertyTable::getList([
285 'USER_TYPE_SETTINGS',
295 while ($property = $propertyIterator->fetch())
297 if ($property[
'USER_TYPE'])
299 $userType = CIBlockProperty::GetUserType($property[
'USER_TYPE']);
300 if (isset($userType[
"ConvertFromDB"]))
302 if (array_key_exists(
"DEFAULT_VALUE", $property))
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;
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;
314 unset($property, $propertyIterator);
315 if (empty($propertyID))
322 $this->arProperties = self::$propertiesCache[
$IBLOCK_ID];
329 $this->arPropertyValuesID =
array();
330 $this->arDescriptions =
array();