/** * Stores templates for entity into database. * * @param array $templates Templates to be stored to DB. * * @return void * @throws \Bitrix\Main\ArgumentException */ public function set(array $templates) { $templateList = \Bitrix\Iblock\InheritedPropertyTable::getList(array("select" => array("ID", "CODE", "TEMPLATE"), "filter" => array("=IBLOCK_ID" => $this->entity->getIblockId(), "=ENTITY_TYPE" => $this->entity->getType(), "=ENTITY_ID" => $this->entity->getId()))); array_map("trim", $templates); while ($row = $templateList->fetch()) { $CODE = $row["CODE"]; if (array_key_exists($CODE, $templates)) { if ($templates[$CODE] !== $row["TEMPLATE"]) { if ($templates[$CODE] != "") { \Bitrix\Iblock\InheritedPropertyTable::update($row["ID"], array("TEMPLATE" => $templates[$CODE])); } else { \Bitrix\Iblock\InheritedPropertyTable::delete($row["ID"]); } $this->entity->deleteValues($row["ID"]); } unset($templates[$CODE]); } } if (!empty($templates)) { foreach ($templates as $CODE => $TEMPLATE) { if ($TEMPLATE != "") { \Bitrix\Iblock\InheritedPropertyTable::add(array("IBLOCK_ID" => $this->entity->getIblockId(), "CODE" => $CODE, "ENTITY_TYPE" => $this->entity->getType(), "ENTITY_ID" => $this->entity->getId(), "TEMPLATE" => $TEMPLATE)); } } $this->entity->clearValues(); } }