- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/classes/general/tasks_report_helper.php
- Класс: CTasksReportHelper
- Вызов: CTasksReportHelper::rewriteMoneyFilter
static function rewriteMoneyFilter(&$filter, &$runtime)
{
static $operationCodes = null;
static $moneyFieldRegExp = null;
static $sqlHelper = null;
static $allowedOperations = null;
if ($operationCodes === null)
{
$operationCodes = array_flip(CReport::$iBlockCompareVariations);
}
if ($sqlHelper === null)
{
$sqlHelper = MainApplication::getConnection()->getSqlHelper();
}
if ($allowedOperations === null)
{
$allowedOperations = ['EQUAL', 'GREATER', 'LESS', 'NOT_EQUAL', 'GREATER_OR_EQUAL', 'LESS_OR_EQUAL'];
}
if ($moneyFieldRegExp === null)
{
$moneyFieldRegExp = '';
if (is_array(self::$userFieldMoneyList) && !empty(self::$userFieldMoneyList))
{
$moneyFieldRegExp .= '(';
$number = 0;
foreach (self::$userFieldMoneyList as $fieldName)
{
if ($number++ > 0)
{
$moneyFieldRegExp .= '|';
}
$moneyFieldRegExp .= preg_quote($fieldName);
}
unset($number);
$moneyFieldRegExp .= ')';
}
}
if ($moneyFieldRegExp !== '')
{
$newFilter = [];
foreach ($filter as $k => &$v)
{
$skipFilterElement = false;
if (is_array($v))
{
self::rewriteMoneyFilter($v, $runtime);
}
else if ($k !== 'LOGIC' && !is_numeric($k))
{
$matches = array();
if (preg_match('/^(>=|<=|=|>|<|!)?(.*'.$moneyFieldRegExp.')$/', $k, $matches))
{
if (is_string($v) && $v !== '')
{
if (!isset($matches[1]))
{
$matches[1] = '=';
}
$operationCode = $operationCodes[$matches[1]];
$valueParts = explode('|', $v);
if (is_array($valueParts) && isset($valueParts[0])
&& is_string($valueParts[0]) && $valueParts[0] !== '')
{
$numberFieldName = $matches[2].self::UF_MONEY_NUMBER_POSTFIX;
$currencyFieldName = $matches[2].self::UF_MONEY_CURRENCY_POSTFIX;
$numberValue = (double)$valueParts[0];
$currencyValue = '';
if (isset($valueParts[1]) && is_string($valueParts[1]) && $valueParts[1] !== '')
{
$currencyValue = $valueParts[1];
}
if (in_array($operationCode, $allowedOperations, true))
{
$filterOperation = CReport::$iBlockCompareVariations[$operationCode];
if ($currencyValue === '')
{
$newFilter[$filterOperation.$numberFieldName] = $numberValue;
}
else
{
if ($filterOperation === '!')
{
$newFilter[] = [
'LOGIC' => 'OR',
$filterOperation.$numberFieldName => $numberValue,
'!'.$currencyFieldName => $currencyValue
];
}
else
{
$newFilter[] = [
'LOGIC' => 'AND',
$filterOperation.$numberFieldName => $numberValue,
'='.$currencyFieldName => $currencyValue
];
}
}
}
}
}
$skipFilterElement = true;
}
}
if (!$skipFilterElement)
{
if (is_numeric($k))
{
$newFilter[] = $v;
}
else
{
$newFilter[$k] = $v;
}
}
}
unset($v);
$filter = $newFilter;
}
}