• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/template/entity/elementproperty.php
  • Класс: BitrixIblockTemplateEntityElementProperty
  • Вызов: ElementProperty::setFields
public function setFields(array $fields)
{
	parent::setFields($fields);
	if (
		is_array($this->fields)
		&& $this->iblockId > 0
	)
	{
		$properties = array();
		$propertyList = BitrixIblockPropertyTable::getList(array(
			"select" => array("*"),
			"filter" => array("=IBLOCK_ID" => $this->iblockId),
		));
		while ($row = $propertyList->fetch())
		{
			if ($row["USER_TYPE_SETTINGS"])
			{
				$row["USER_TYPE_SETTINGS"] = unserialize(
					$row["USER_TYPE_SETTINGS"],
					array('allowed_classes' => false)
				);
			}

			$properties[$row["ID"]] = $row;
			if ($row["CODE"] != "")
				$properties[$row["CODE"]] = &$properties[$row["ID"]];
		}

		foreach ($fields as $propertyCode => $propertyValues)
		{
			if (is_array($propertyValues))
			{
				foreach ($propertyValues as $i => $propertyValue)
				{
					if (is_array($propertyValue) && array_key_exists("VALUE", $propertyValue))
					{
						if ($propertyValue["VALUE"] != "")
							$propertyValues[$i] = $propertyValue["VALUE"];
						else
							unset($propertyValues[$i]);
					}
				}
			}

			if (isset($properties[$propertyCode]))
			{
				$property = $properties[$propertyCode];
				$fieldCode = mb_strtolower($propertyCode);

				if ($property["PROPERTY_TYPE"] === "L")
				{
					if (is_numeric($propertyValues))
					{
						$value = new ElementPropertyEnum($propertyValues);
					}
					elseif (is_array($propertyValues))
					{
						$value = array();
						foreach ($propertyValues as $propertyValue)
						{
							if (is_numeric($propertyValue))
								$value[] = new ElementPropertyEnum($propertyValue);
						}
					}
					else
					{
						$value = $propertyValues;
					}
				}
				elseif ($property["PROPERTY_TYPE"] === "E")
				{
					if ($propertyValues instanceof Element)
					{
						$this->elementLinkProperties[$fieldCode] = $propertyValues;
						$value = $propertyValues->getField("name");
					}
					elseif (is_numeric($propertyValues))
					{
						$this->elementLinkProperties[$fieldCode] = $propertyValues;
						$value = new ElementPropertyElement($propertyValues);
					}
					elseif (is_array($propertyValues))
					{
						$value = array();
						foreach ($propertyValues as $propertyValue)
						{
							if (is_numeric($propertyValue))
								$value[] = new ElementPropertyElement($propertyValue);
						}
					}
					else
					{
						$value = $propertyValues;
					}
				}
				elseif ($property["PROPERTY_TYPE"] === "G")
				{
					if ($propertyValues instanceof Section)
					{
						$this->sectionLinkProperties[$fieldCode] = $propertyValues;
						$value = $propertyValues->getField("name");
					}
					elseif (is_numeric($propertyValues))
					{
						$this->sectionLinkProperties[$fieldCode] = $propertyValues;
						$value = new ElementPropertySection($propertyValues);
					}
					elseif (is_array($propertyValues))
					{
						$value = array();
						foreach ($propertyValues as $propertyValue)
						{
							if (is_numeric($propertyValue))
								$value[] = new ElementPropertySection($propertyValue);
						}
					}
					else
					{
						$value = $propertyValues;
					}
				}
				else
				{
					if($property["USER_TYPE"] <> '')
					{
						if(is_array($propertyValues))
						{
							$value = array();
							foreach($propertyValues as $propertyValue)
							{
								$value[] = new ElementPropertyUserField($propertyValue, $property);
							}
						}
						else
						{
							$value = new ElementPropertyUserField($propertyValues, $property);
						}
					}
					else
					{
						$value = $propertyValues;
					}
				}

				$this->fieldMap[$fieldCode] = $property["ID"];
				$this->fieldMap[$property["ID"]] = $property["ID"];
				if ($property["CODE"] != "")
					$this->fieldMap[mb_strtolower($property["CODE"])] = $property["ID"];

				$this->fields[$property["ID"]] = $value;
			}
		}
	}
}