CCrmInvoiceRestService::prepareFilter

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmInvoiceRestService
  4. prepareFilter
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice_invoice.php
  • Класс: \CCrmInvoiceRestService
  • Вызов: CCrmInvoiceRestService::prepareFilter
static function prepareFilter($arFilter)
{
	if(!is_array($arFilter))
	{
		$arFilter = array();
	}
	else
	{
		$fieldsInfo = self::getFieldsInfo();
		$arAllowedFilterFields = array();
		foreach ($fieldsInfo as $fieldName => $fieldInfo)
		{
			if ($fieldInfo['filter'] === true)
				$arAllowedFilterFields[] = $fieldName;
		}
		$userFields = CCrmInvoice::GetUserFields();
		if (!is_array($userFields))
			$userFields = array();
		foreach (array_keys($userFields) as $fieldName)
			$arAllowedFilterFields[] = $fieldName;

		if (count($arFilter) > 0)
		{
			$arFilter = array_change_key_case($arFilter, CASE_UPPER);
			foreach ($arFilter as $key => $value)
			{
				$matches = array();
				if(preg_match('/^([^a-zA-Z]*)(.*)/', $key, $matches))
				{
					$operation = $matches[1];
					$field = $matches[2];

					if(!in_array($field, $arAllowedFilterFields, true)
						|| !in_array($operation, self::getAllowedFilterOperations(), true))
					{
						unset($arFilter[$key]);
					}
					else
					{
						switch ($fieldsInfo[$field]['type'])
						{
							case 'datetime':
								if ($value === '')
								{
									$arFilter[$key] = '';
								}
								else
								{
									$datetimeValue = CRestUtil::unConvertDateTime($value, true);
									if (is_string($datetimeValue))
									{
										$arFilter[$key] = $datetimeValue;
									}
									else
									{
										unset($arFilter[$key]);
									}
								}
								break;

							case 'date':
								if ($value === '')
								{
									$arFilter[$key] = '';
								}
								else
								{
									$dateValue = CRestUtil::unConvertDate($value);
									if (is_string($dateValue))
									{
										$arFilter[$key] = $dateValue;
									}
									else
									{
										unset($arFilter[$key]);
									}
								}
								break;

							default:
								break;
						}

						switch($field)
						{
							case 'CHECK_PERMISSIONS':
								unset($arFilter[$key]);
								break;

							default:
								break;
						}
					}
				}
				else
				{
					unset($arFilter[$key]);
				}
			}
		}
	}

	$userType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], CCrmInvoice::$sUFEntityID);
	$userType->ListPrepareFilter($arFilter);

	return $arFilter;
}

Добавить комментарий