static function DoSaveUserProfile($userId, $profileId, $profileName, $personTypeId, $orderProps, &$arErrors) { $profileId = intval($profileId); $arIDs = array(); if ($profileId > 0) { $dbProfile = CSaleOrderUserProps::GetList(array(), array("ID" => $profileId), false, false, array("ID", "NAME", "USER_ID", "PERSON_TYPE_ID")); $arProfile = $dbProfile->Fetch(); if (!$arProfile) { $arErrors[] = array("CODE" => "PROFILE_NOT_FOUND", "TEXT" => GetMessage('SKGOUP_PROFILE_NOT_FOUND')); return false; } if ($arProfile["USER_ID"] != $userId || $arProfile["PERSON_TYPE_ID"] != $personTypeId) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => GetMessage('SKGOUP_PARRAMS_ERROR')); return false; } //if (strlen($profileName) > 0 && $profileName != $arProfile["NAME"]) if (strlen($profileName) > 0) { $arFields = array("NAME" => $profileName, "USER_ID" => $userId); CSaleOrderUserProps::Update($profileId, $arFields); } $dbUserPropsValues = CSaleOrderUserPropsValue::GetList(array(), array("USER_PROPS_ID" => $profileId), false, false, array("ID", "ORDER_PROPS_ID")); while ($arUserPropsValue = $dbUserPropsValues->Fetch()) { $arIDs[$arUserPropsValue["ORDER_PROPS_ID"]] = $arUserPropsValue["ID"]; } } if (!is_array($orderProps)) { $dbOrderPropsValues = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => intval($orderProps)), false, false, array("ORDER_PROPS_ID", "VALUE")); $orderProps = array(); while ($arOrderPropsValue = $dbOrderPropsValues->Fetch()) { $orderProps[$arOrderPropsValue["ORDER_PROPS_ID"]] = $arOrderPropsValue["VALUE"]; } } $dbOrderProperties = CSaleOrderProps::GetList(array(), array("PERSON_TYPE_ID" => $personTypeId, "ACTIVE" => "Y", "UTIL" => "N", "USER_PROPS" => "Y"), false, false, array("ID", "TYPE", "NAME", "CODE")); while ($arOrderProperty = $dbOrderProperties->Fetch()) { $curVal = $orderProps[$arOrderProperty["ID"]]; if ($arOrderProperty["TYPE"] == "MULTISELECT" && is_array($curVal)) { $curVal = implode(",", $curVal); } if (strlen($curVal) > 0) { if ($profileId <= 0) { if (strlen($profileName) <= 0) { $profileName = GetMessage("SOA_PROFILE") . " " . Date("Y-m-d"); } $arFields = array("NAME" => $profileName, "USER_ID" => $userId, "PERSON_TYPE_ID" => $personTypeId); $profileId = CSaleOrderUserProps::Add($arFields); } if (array_key_exists($arOrderProperty["ID"], $arIDs)) { $arFields = array("NAME" => $arOrderProperty["NAME"], "VALUE" => $curVal); CSaleOrderUserPropsValue::Update($arIDs[$arOrderProperty["ID"]], $arFields); unset($arIDs[$arOrderProperty["ID"]]); } else { $arFields = array("USER_PROPS_ID" => $profileId, "ORDER_PROPS_ID" => $arOrderProperty["ID"], "NAME" => $arOrderProperty["NAME"], "VALUE" => $curVal); CSaleOrderUserPropsValue::Add($arFields); } } } foreach ($arIDs as $id) { CSaleOrderUserPropsValue::Delete($id); } }
static function DoSaveUserProfile($userId, $profileId, $profileName, $personTypeId, $orderProps, &$arErrors) { $profileId = intval($profileId); $arIDs = array(); if ($profileId > 0) { $dbProfile = CSaleOrderUserProps::GetList(array(), array("ID" => $profileId), false, false, array("ID", "NAME", "USER_ID", "PERSON_TYPE_ID")); $arProfile = $dbProfile->Fetch(); if (!$arProfile) { $arErrors[] = array("CODE" => "PROFILE_NOT_FOUND", "TEXT" => GetMessage('SKGOUP_PROFILE_NOT_FOUND')); return false; } if ($arProfile["USER_ID"] != $userId || $arProfile["PERSON_TYPE_ID"] != $personTypeId) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => GetMessage('SKGOUP_PARRAMS_ERROR')); return false; } //if (strlen($profileName) > 0 && $profileName != $arProfile["NAME"]) if (strlen($profileName) > 0) { $arFields = array("NAME" => $profileName, "USER_ID" => $userId); CSaleOrderUserProps::Update($profileId, $arFields); } $dbUserPropsValues = CSaleOrderUserPropsValue::GetList(array(), array("USER_PROPS_ID" => $profileId), false, false, array("ID", "ORDER_PROPS_ID")); while ($arUserPropsValue = $dbUserPropsValues->Fetch()) { $arIDs[$arUserPropsValue["ORDER_PROPS_ID"]] = $arUserPropsValue["ID"]; } } if (!is_array($orderProps)) { $dbOrderPropsValues = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => intval($orderProps)), false, false, array("ORDER_PROPS_ID", "VALUE")); $orderProps = array(); while ($arOrderPropsValue = $dbOrderPropsValues->Fetch()) { $orderProps[$arOrderPropsValue["ORDER_PROPS_ID"]] = $arOrderPropsValue["VALUE"]; } } /* TRANSLATION_CUT_OFF else { // map location ID to CODE, if taken from parameters static::TranslateLocationPropertyValues($personTypeId, $orderProps); } */ $utilPropertyList = array(); $dbOrderProperties = CSaleOrderProps::GetList(array(), array("PERSON_TYPE_ID" => $personTypeId, "ACTIVE" => "Y", "USER_PROPS" => "Y"), false, false, array("ID", "TYPE", "NAME", "CODE", "UTIL")); while ($arOrderProperty = $dbOrderProperties->Fetch()) { if ($arOrderProperty['UTIL'] == "Y") { $utilPropertyList[] = $arIDs[$arOrderProperty["ID"]]; continue; } $curVal = $orderProps[$arOrderProperty["ID"]]; if ($arOrderProperty["TYPE"] == "MULTISELECT" && is_array($curVal)) { $curVal = implode(",", $curVal); } if ($arOrderProperty["TYPE"] == "FILE" && is_array($curVal)) { $fileList = array(); foreach ($curVal as $fileDat) { $fileList[] = $fileDat['ID']; } $curVal = serialize($fileList); } if (strlen($curVal) > 0) { if ($profileId <= 0) { if (strlen($profileName) <= 0) { $profileName = GetMessage("SOA_PROFILE") . " " . Date("Y-m-d"); } $arFields = array("NAME" => $profileName, "USER_ID" => $userId, "PERSON_TYPE_ID" => $personTypeId); $profileId = CSaleOrderUserProps::Add($arFields); } if (array_key_exists($arOrderProperty["ID"], $arIDs)) { $arFields = array("NAME" => $arOrderProperty["NAME"], "VALUE" => $curVal); CSaleOrderUserPropsValue::Update($arIDs[$arOrderProperty["ID"]], $arFields); unset($arIDs[$arOrderProperty["ID"]]); } else { $arFields = array("USER_PROPS_ID" => $profileId, "ORDER_PROPS_ID" => $arOrderProperty["ID"], "NAME" => $arOrderProperty["NAME"], "VALUE" => $curVal); CSaleOrderUserPropsValue::Add($arFields); } } } foreach ($arIDs as $id) { if (!empty($utilPropertyList) && in_array($id, $utilPropertyList)) { continue; } CSaleOrderUserPropsValue::Delete($id); } }