Example #1
0
 public static function CheckFields($ACTION, &$arFields, $statusId = '')
 {
     if ((is_set($arFields, "SORT") || $ACTION == "ADD") && IntVal($arFields["SORT"]) <= 0) {
         $arFields["SORT"] = 100;
     }
     if ((is_set($arFields, "ID") || $ACTION == "ADD") && strlen($arFields["ID"]) <= 0) {
         return false;
     }
     if (is_set($arFields, "ID") && strlen($statusId) > 0 && $statusId != $arFields["ID"]) {
         return false;
     }
     if (is_set($arFields, "ID") && !preg_match("#[A-Za-z]#i", $arFields["ID"]) || strlen($statusId) > 0 && !preg_match("#[A-Za-z]#i", $statusId)) {
         $GLOBALS["APPLICATION"]->ThrowException(Loc::getMessage("SKGS_ID_NOT_SYMBOL"), "ERROR_ID_NOT_SYMBOL");
         return false;
     }
     $result = new Result();
     if (!self::$statusFields) {
         self::$statusFields = StatusTable::getEntity()->getScalarFields();
         self::$langFields = StatusLangTable::getEntity()->getScalarFields();
         self::$taskFields = StatusGroupTaskTable::getEntity()->getScalarFields();
     }
     switch ($ACTION) {
         case 'ADD':
             $statusId = $arFields['ID'];
             StatusTable::checkFields($result, null, array_intersect_key($arFields, self::$statusFields));
             break;
         case 'UPDATE':
             StatusTable::checkFields($result, $statusId, array_intersect_key(array_diff_key($arFields, array('ID' => 1)), self::$statusFields));
             break;
         default:
             throw new SystemException('Invalid action: ' . $ACTION, 0, __FILE__, __LINE__);
     }
     if (isset($arFields['LANG']) && is_array($arFields['LANG']) && !empty($arFields['LANG'])) {
         $availableLanguages = array_map('current', LanguageTable::getList(array('select' => array('LID'), 'filter' => array('=ACTIVE' => 'Y')))->fetchAll());
         foreach ($arFields['LANG'] as $data) {
             if ($data['NAME'] && in_array($data['LID'], $availableLanguages)) {
                 StatusLangTable::checkFields($result, null, array('STATUS_ID' => $statusId) + array_intersect_key($data, self::$langFields));
             } else {
                 return false;
             }
         }
     }
     return $result->isSuccess();
 }