public static function Add($arFields) { //d($arFields); global $DB, $USER; unset($arFields["ID"]); Event::Run('catalog', 'OnBeforeCatalogElementAdd', $arFields); if (!isset($arFields["CATALOG_ID"]) || intval($arFields["CATALOG_ID"]) == 0) { dbError("Не указан идентификатор каталога!"); return false; } $arProps = $arFields["PROPERTIES"]; unset($arFields["PROPERTIES"]); $arFields['DATE_CREATE'] = date("Y-m-d H:i:s"); $arFields['TIMESTAMP_X'] = date("Y-m-d H:i:s"); $arFields['CREATED_BY'] = empty($arFields['CREATED_BY']) ? $USER->GetID() : $arFields['CREATED_BY']; if (is_array($arFields['PREVIEW_PICTURE']) and !empty($arFields['PREVIEW_PICTURE'])) { if ($arFields['PREVIEW_PICTURE']['tmp_name'] != '') { $fileID = File::SaveFile($arFields['PREVIEW_PICTURE'], array('MODULE_ID' => 'catalog')); unset($arFields['PREVIEW_PICTURE']); $arFields['PREVIEW_PICTURE'] = $fileID; } } if (is_array($arFields['DETAIL_PICTURE']) and !empty($arFields['DETAIL_PICTURE'])) { if ($arFields['DETAIL_PICTURE']['tmp_name'] != '') { $fileID = File::SaveFile($arFields['DETAIL_PICTURE'], array('MODULE_ID' => 'catalog')); unset($arFields['DETAIL_PICTURE']); $arFields['DETAIL_PICTURE'] = $fileID; } } $sql = addSql(self::$table, $arFields); if ($DB->Query($sql)) { self::$lastID = $DB->LastID(); if (!empty($arProps)) { $arPropFields = array(); foreach ($arProps as $propCODE => $propValue) { if (is_numeric($propCODE)) { $propID = intVal($propCODE); } else { $propID = self::GetPropIDByCODE($propCODE); } $arPropFields = array("CATALOG_PROPERTY_ID" => intVal($propID), "CATALOG_ELEMENT_ID" => self::$lastID, "VALUE" => $propValue); if (is_array($propValue) and !empty($propValue)) { if ($propValue['tmp_name'] != '') { $fileID = File::SaveFile($propValue, array('MODULE_ID' => 'catalog')); if (intVal($fileID) > 0) { $arPropFields['VALUE'] = $fileID; $arPropFields['VALUE_TYPE'] = 'file'; $sqlProps = addSql(self::$table_props_values, $arPropFields); $DB->Query($sqlProps); } } else { foreach ($propValue as $propVal) { if (is_array($propVal)) { if ($propVal['tmp_name'] != '') { $fileID = File::SaveFile($propVal, array('MODULE_ID' => 'catalog')); if (intVal($fileID) > 0) { $arPropFields['VALUE'] = $fileID; $arPropFields['VALUE_TYPE'] = 'file'; $sqlProps = addSql(self::$table_props_values, $arPropFields); $DB->Query($sqlProps); } } } else { if ($propVal != '') { $arPropFields['VALUE'] = $propVal; $sqlProps = addSql(self::$table_props_values, $arPropFields); $DB->Query($sqlProps); } } } } } else { if (!empty($propValue)) { $sqlProps = addSql(self::$table_props_values, $arPropFields); $DB->Query($sqlProps); } } } } Event::Run('catalog', 'OnAfterCatalogElementAdd', $arFields); return self::$lastID; } else { dbError($DB->Error()); return false; } }