9namespace Bitrix\Main\ORM\Fields;
11use Bitrix\Main\DB\SqlExpression;
12use Bitrix\Main\ORM\Entity;
13use Bitrix\Main\ORM\Query\Chain;
14use Bitrix\Main\ORM\Data\Result;
15use Bitrix\Main\NotImplementedException;
16use Bitrix\Main\SystemException;
59 'GROUP_CONCAT',
'MAX',
'MIN',
'STD',
'STDDEV_POP',
'STDDEV_SAMP',
60 'STDDEV',
'SUM',
'VAR_POP',
'VAR_SAMP',
'VARIANCE',
'ANY_VALUE'
63 'ROWCOUNT_BIG',
'COUNT_BIG',
'STDEV',
'GROUPING',
'STDEVP',
64 'GROUPING_ID',
'SUM',
'MAX',
'VAR',
'VARP'
67 'COUNT',
'COVAR_POP',
'COVAR_SAMP',
'CUME_DIST',
'DENSE_RANK',
'FIRST',
68 'GROUP_ID',
'GROUPING',
'GROUPING_ID',
'LAST',
'MAX',
'MEDIAN',
'MIN',
69 'PERCENTILE_CONT',
'PERCENTILE_DISC',
'PERCENT_RANK',
'RANK',
70 'REGR_SLOPE',
'REGR_INTERCEPT',
'REGR_COUNT',
'REGR_R2',
'REGR_AVGX',
71 'REGR_AVGY',
'REGR_SXX',
'REGR_SYY',
'REGR_SXY',
'STATS_BINOMIAL_TEST',
72 'STATS_CROSSTAB',
'STATS_F_TEST',
'STATS_KS_TEST',
'STATS_MODE',
73 'STATS_MW_TEST',
'STATS_ONE_WAY_ANOVA',
'STATS_T_TEST_ONE',
74 'STATS_T_TEST_PAIRED',
'STATS_T_TEST_INDEP',
'STATS_T_TEST_INDEPU',
75 'STATS_WSR_TEST',
'STDDEV',
'STDDEV_POP',
'STDDEV_SAMP',
'SUM',
76 'VAR_POP',
'VAR_SAMP',
'VARIANCE'
79 'AVG',
'ARRAY_AGG',
'BOOL_AND',
'BOOL_OR',
'COUNT',
'STRING_AGG',
'SUM',
97 if (!isset($parameters[
'data_type']))
99 $parameters[
'data_type'] =
'string';
101 $this->valueType = StringField::class;
104 parent::__construct(
$name, $parameters);
122 return call_user_func_array(
array($this->valueField,
$name), $arguments);
140 $this->valueType = $class;
150 $this->valueField = $field;
151 $this->valueType = get_class($field);
167 unset($parameters[
'expression']);
169 if ($this->valueType !==
null)
171 if ($this->valueField ===
null)
174 $valueField =
new $this->valueType($this->name, $parameters);
175 $this->valueField = $this->entity->initializeField($this->name,
$valueField);
181 $this->valueField = $this->entity->initializeField($this->name, $parameters);
182 $this->valueType = get_class($this->valueField);
185 if (!($this->valueField instanceof ScalarField))
187 throw new SystemException(
'expression field can only be a scalar type.');
208 public function getFullExpression()
210 if (!isset($this->fullExpression))
212 $SQLBuildFrom =
array();
215 foreach ($this->buildFrom as $element)
217 if ($element instanceof \Closure)
223 $SQLBuildFrom[] =
'';
231 $SQLBuildFrom[] = $chain->getLastElement()->getValue()->getFullExpression();
235 $SQLBuildFrom[] =
'%s';
240 $this->fullExpression = call_user_func_array(
'sprintf', array_merge(
array($this->expression), $SQLBuildFrom));
254 $this->
isAggregated = (bool) self::checkAggregation($this->getFullExpression());
268 $this->
hasSubquery = (bool) self::checkSubquery($this->getFullExpression());
276 return empty($this->buildFrom);
286 if (is_null($this->buildFromChains))
288 $this->buildFromChains =
array();
290 foreach ($this->buildFrom as $elem)
292 if (!($elem instanceof \Closure))
295 $chain = Chain::getChainByDefinition($this->entity, $elem);
296 $field = $chain->getLastElement()->getValue();
300 $this->buildFromChains[] = $chain;
305 'Expected ScalarField or ExpressionField in `%s` build_from, but `%s` was given.',
306 $this->name, is_object($field) ? get_class($field).
':'.$field->getName() : gettype($field)
318 if (empty(self::$aggrFunctions))
320 self::$aggrFunctions = array_unique(array_merge(
321 self::$aggrFunctionsMYSQL, self::$aggrFunctionsMSSQL, self::$aggrFunctionsORACLE, self::$aggrFunctionsPGSQL
329 preg_match_all(
'/(?:^|[^a-z0-9_])('.join(
'|', self::$aggrFunctions).
')[\s\(]+/i',
$expression,
$matches);
336 return (preg_match(
'/(?:^|[^a-zA-Z0-9_])EXISTS\s*\(/i',
$expression) || preg_match(
'/(?:^|[^a-zA_Z0-9_])\(\s*SELECT/i',
$expression));
373 $subqPattern =
'\(\s*SELECT\s+';
382 $subqPosition = mb_strpos(
$query, $substring);
383 $subqStartPosition = $subqPosition + mb_strlen($substring);
386 $currentPosition = $subqStartPosition;
389 while ($bracketsCount > 0)
391 $symbol = mb_substr(
$query, $currentPosition, 1);
423 return $this->valueField->getDataType();
444 $this->buildFromChains =
null;
445 $this->fullExpression =
null;
__construct($name, $expression, $buildFrom=null, $parameters=array())
static removeStrings($quote, $expression)
configureValueType($class)
__call($name, $arguments)
static $aggrFunctionsMSSQL
static removeSubqueries($expression)
static checkAggregation($expression)
validateValue($value, $primary, $row, Result $result)
static $aggrFunctionsORACLE
static removeSubqueryBody($query)
convertValueFromDb($value)
configureValueField($field)
static checkSubquery($expression)
static $aggrFunctionsPGSQL
static $aggrFunctionsMYSQL
setEntity(Entity $entity)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)