Поддержка серверов

CGlobalCondCtrl::CheckAtoms: метод Битрикс

Постоянная ссылка: http://bxapi.ru/src/?id=169848

//    CGlobalCondCtrl::CheckAtoms()
//    /bitrix/modules/catalog/general/catalog_cond.php:1186

    public static function CheckAtoms($arOneCondition, $arParams, $arControl, $boolShow)
    {
        $boolShow = (true === $boolShow);
        $boolError = false;
        $boolFatalError = false;
        $arMsg = array();

        $arValues = array();
        $arLabels = array();

        static $intTimeOffset = false;
        if ($intTimeOffset === false)
            $intTimeOffset = CTimeZone::GetOffset();

        if (!isset($arControl['ATOMS']) || empty($arControl['ATOMS']) || !is_array($arControl['ATOMS']))
        {
            $boolFatalError = true;
            $boolError = true;
            $arMsg[] = Loc::getMessage('BT_GLOBAL_COND_ERR_ATOMS_ABSENT');
        }
        if (!$boolError)
        {
            $boolValidate = false;
            if ($boolShow)
            {
                foreach ($arControl['ATOMS'] as &$arOneAtom)
                {
                    $boolAtomError = false;
                    $strID = $arOneAtom['ATOM']['ID'];
                    $boolMulti = false;
                    if (!isset($arOneCondition[$strID]))
                    {
                        $boolAtomError = true;
                    }
                    else
                    {
                        $boolMulti = is_array($arOneCondition[$strID]);
                        switch ($arOneAtom['ATOM']['FIELD_TYPE'])
                        {
                            case 'int':
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strID] as &$intOneValue)
                                    {
                                        $intOneValue = (int)$intOneValue;
                                    }
                                    if (isset($intOneValue))
                                        unset($intOneValue);
                                }
                                else
                                {
                                    $arOneCondition[$strID] = (int)$arOneCondition[$strID];
                                }
                                break;
                            case 'double':
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strID] as &$dblOneValue)
                                    {
                                        $dblOneValue = (float)$dblOneValue;
                                    }
                                    if (isset($dblOneValue))
                                        unset($dblOneValue);
                                }
                                else
                                {
                                    $arOneCondition[$strID] = doubleval($arOneCondition[$strID]);
                                }
                                break;
                            case 'strdouble':
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strID] as &$dblOneValue)
                                    {
                                        if ($dblOneValue !== '')
                                            $dblOneValue = (float)$dblOneValue;
                                    }
                                    if (isset($dblOneValue))
                                        unset($dblOneValue);
                                }
                                else
                                {
                                    if ($arOneCondition[$strID] !== '')
                                        $arOneCondition[$strID] = (float)$arOneCondition[$strID];
                                }
                                break;
                            case 'char':
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strID] as &$strOneValue)
                                    {
                                        $strOneValue = substr($strOneValue, 0, 1);
                                    }
                                    if (isset($strOneValue))
                                        unset($strOneValue);
                                }
                                else
                                {
                                    $arOneCondition[$strID] = substr($arOneCondition[$strID], 0, 1);
                                }
                                break;
                            case 'string':
                                $intMaxLen = (int)(isset($arOneAtom['ATOM']['FIELD_LENGTH']) ? $arOneAtom['ATOM']['FIELD_LENGTH'] : 255);
                                if ($intMaxLen <= 0)
                                    $intMaxLen = 255;
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strID] as &$strOneValue)
                                    {
                                        $strOneValue = substr($strOneValue, 0, $intMaxLen);
                                    }
                                    if (isset($strOneValue))
                                        unset($strOneValue);
                                }
                                else
                                {
                                    $arOneCondition[$strID] = substr($arOneCondition[$strID], 0, $intMaxLen);
                                }
                                break;
                            case 'text':
                                break;
                            case 'date':
                            case 'datetime':
                                if ($arOneAtom['ATOM']['FIELD_TYPE'] == 'date')
                                {
                                    $strFormat = 'SHORT';
                                    $intOffset = 0;
                                }
                                else
                                {
                                    $strFormat = 'FULL';
                                    $intOffset = $intTimeOffset;
                                }
                                $boolAtomError = static::ConvertInt2DateTime($arOneCondition[$strID], $strFormat, $intOffset);
                                break;
                            default:
                                $boolAtomError = true;
                        }
                    }
                    if (!$boolAtomError)
                    {
                        if ($boolMulti)
                            $arOneCondition[$strID] = array_values(array_unique($arOneCondition[$strID]));
                        $arValues[$strID] = $arOneCondition[$strID];
                        if (isset($arOneAtom['ATOM']['VALIDATE']) && !empty($arOneAtom['ATOM']['VALIDATE']))
                            $boolValidate = true;
                    }
                    else
                    {
                        $arValues[$strID] = '';
                    }
                    if ($boolAtomError)
                        $boolError = true;
                }
                if (isset($arOneAtom))
                    unset($arOneAtom);

                if (!$boolError)
                {
                    if ($boolValidate)
                    {
                        $arValidate = static::ValidateAtoms($arValues, $arParams, $arControl, $boolShow);
                        if ($arValidate === false)
                        {
                            $boolError = true;
                        }
                        else
                        {
                            if (isset($arValidate['err_cond']) && $arValidate['err_cond'] == 'Y')
                            {
                                $boolError = true;
                                if (isset($arValidate['err_cond_mess']) && !empty($arValidate['err_cond_mess']))
                                    $arMsg = array_merge($arMsg, $arValidate['err_cond_mess']);
                            }
                            else
                            {
                                $arValues = $arValidate['values'];
                                if (isset($arValidate['labels']))
                                    $arLabels = $arValidate['labels'];
                            }
                        }
                    }
                }
            }
            else
            {
                foreach ($arControl['ATOMS'] as &$arOneAtom)
                {
                    $boolAtomError = false;
                    $strID = $arOneAtom['ATOM']['ID'];
                    $strName = $arOneAtom['JS']['name'];
                    $boolMulti = false;
                    if (!isset($arOneCondition[$strName]))
                    {
                        $boolAtomError = true;
                    }
                    else
                    {
                        $boolMulti = is_array($arOneCondition[$strName]);
                    }
                    if (!$boolAtomError)
                    {
                        switch ($arOneAtom['ATOM']['FIELD_TYPE'])
                        {
                            case 'int':
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strName] as &$intOneValue)
                                    {
                                        $intOneValue = (int)$intOneValue;
                                    }
                                    if (isset($intOneValue))
                                        unset($intOneValue);
                                }
                                else
                                {
                                    $arOneCondition[$strName] = (int)$arOneCondition[$strName];
                                }
                                break;
                            case 'double':
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strName] as &$dblOneValue)
                                    {
                                        $dblOneValue = (float)$dblOneValue;
                                    }
                                    if (isset($dblOneValue))
                                        unset($dblOneValue);
                                }
                                else
                                {
                                    $arOneCondition[$strName] = (float)$arOneCondition[$strName];
                                }
                                break;
                            case 'strdouble':
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strName] as &$dblOneValue)
                                    {
                                        if ($dblOneValue !== '')
                                            $dblOneValue = (float)$dblOneValue;
                                    }
                                    if (isset($dblOneValue))
                                        unset($dblOneValue);
                                }
                                else
                                {
                                    if ($arOneCondition[$strName] !== '')
                                    {
                                        $arOneCondition[$strName] = (float)$arOneCondition[$strName];
                                    }
                                }
                                break;
                            case 'char':
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strName] as &$strOneValue)
                                    {
                                        $strOneValue = substr($strOneValue, 0, 1);
                                    }
                                    if (isset($strOneValue))
                                        unset($strOneValue);
                                }
                                else
                                {
                                    $arOneCondition[$strName] = substr($arOneCondition[$strName], 0, 1);
                                }
                                break;
                            case 'string':
                                $intMaxLen = (int)(isset($arOneAtom['ATOM']['FIELD_LENGTH']) ? $arOneAtom['ATOM']['FIELD_LENGTH'] : 255);
                                if ($intMaxLen <= 0)
                                    $intMaxLen = 255;
                                if ($boolMulti)
                                {
                                    foreach ($arOneCondition[$strName] as &$strOneValue)
                                    {
                                        $strOneValue = substr($strOneValue, 0, $intMaxLen);
                                    }
                                    if (isset($strOneValue))
                                        unset($strOneValue);
                                }
                                else
                                {
                                    $arOneCondition[$strName] = substr($arOneCondition[$strName], 0, $intMaxLen);
                                }
                                break;
                            case 'text':
                                break;
                            case 'date':
                            case 'datetime':
                                if ($arOneAtom['ATOM']['FIELD_TYPE'] == 'date')
                                {
                                    $strFormat = 'SHORT';
                                    $intOffset = 0;
                                }
                                else
                                {
                                    $strFormat = 'FULL';
                                    $intOffset = $intTimeOffset;
                                }
                                $boolAtomError = static::ConvertDateTime2Int($arOneCondition[$strName], $strFormat, $intOffset);
                                break;
                            default:
                                $boolAtomError = true;
                        }
                        if (!$boolAtomError)
                        {
                            if ($boolMulti)
                                $arOneCondition[$strName] = array_values(array_unique($arOneCondition[$strName]));
                            $arValues[$strID] = $arOneCondition[$strName];
                            if (isset($arOneAtom['ATOM']['VALIDATE']) && !empty($arOneAtom['ATOM']['VALIDATE']))
                                $boolValidate = true;
                        }
                        else
                        {
                            $arValues[$strID] = '';
                        }
                    }
                    if ($boolAtomError)
                        $boolError = true;
                }
                if (isset($arOneAtom))
                    unset($arOneAtom);

                if (!$boolError)
                {
                    if ($boolValidate)
                    {
                        $arValidate = static::ValidateAtoms($arValues, $arParams, $arControl, $boolShow);
                        if ($arValidate === false)
                        {
                            $boolError = true;
                        }
                        else
                        {
                            $arValues = $arValidate['values'];
                            if (isset($arValidate['labels']))
                                $arLabels = $arValidate['labels'];
                        }
                    }
                }
            }
        }

        if ($boolShow)
        {
            $arResult = array(
                'id' => $arParams['COND_NUM'],
                'controlId' => $arControl['ID'],
                'values' => $arValues
            );
            if (!empty($arLabels))
                $arResult['labels'] = $arLabels;
            if ($boolError)
            {
                $arResult['err_cond'] = 'Y';
                if ($boolFatalError)
                    $arResult['fatal_err_cond'] = 'Y';
                if (!empty($arMsg))
                    $arResult['err_cond_mess'] = implode('. ', $arMsg);
            }
            return $arResult;
        }
        else
        {
            return (!$boolError ? $arValues : false);
        }
    }

Блог разработчика

9 Августа 2016 ResizeImageGet и простой водяной знак налету

Сегодня поговорим о том как проще всего воткнуть водяной знак на картинки в Битрикс. Например, на все изображения каталога.

21 Июля 2016 Добавление вкладки в CRM коробки Битрикс24

В этом посте я покажу, как легко и просто добавить вкладку в сущность CRM. И не просто добавить, а вывести там свой контент.

21 Июля 2016 Как просто обращаться из коробки Битрикс24 на сайт на базе Битрикс

К примеру вам хочется внутренним скриптом дернуть с сайта-магазина информацию, которая там, в свою очередь, закрыта некоторыми правами. Например, админскими. Можно конечно мутить свой REST, или иной формат общения, но проще всего воспользоваться штатным инструментом:

Текст сообщения*
Загрузить изображение