Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
expression.php
1
<?php
9
namespace
Bitrix\Main\ORM\Query
;
10
use
Bitrix\Main\Application
;
11
use
Bitrix\Main\ORM\Fields\ExpressionField
;
12
use
Bitrix\Main\ORM\Query\Filter\ConditionTree
;
13
use
Bitrix\Main\Security\Random
;
14
22
class
Expression
23
{
31
public
function
count
($columnName)
32
{
33
$alias = static::getTmpName(
'COUNT'
);
34
return
new
ExpressionField
($alias,
'COUNT(%s)'
, $columnName);
35
}
36
44
public
function
countDistinct
($columnName)
45
{
46
$alias = static::getTmpName(
'COUNT_DISTINCT'
);
47
return
new
ExpressionField
($alias,
'COUNT(DISTINCT %s)'
, $columnName);
48
}
49
57
public
function
sum
($columnName)
58
{
59
$alias = static::getTmpName(
'SUM'
);
60
return
new
ExpressionField
($alias,
'SUM(%s)'
, $columnName);
61
}
62
70
public
function
min
($columnName)
71
{
72
$alias = static::getTmpName(
'MIN'
);
73
return
new
ExpressionField
($alias,
'MIN(%s)'
, $columnName);
74
}
75
83
public
function
avg
($columnName)
84
{
85
$alias = static::getTmpName(
'AVG'
);
86
return
new
ExpressionField
($alias,
'AVG(%s)'
, $columnName);
87
}
88
96
public
function
max
($columnName)
97
{
98
$alias = static::getTmpName(
'MAX'
);
99
return
new
ExpressionField
($alias,
'MAX(%s)'
, $columnName);
100
}
101
109
public
function
length
($columnName)
110
{
111
$helper =
Application::getConnection
()->getSqlHelper();
112
$alias = static::getTmpName(
'LENGTH'
);
113
114
return
new
ExpressionField
($alias, $helper->getLengthFunction(
'%s'
), $columnName);
115
}
116
124
public
function
lower
($columnName)
125
{
126
$alias = static::getTmpName(
'LOWER'
);
127
return
new
ExpressionField
($alias,
'LOWER(%s)'
, $columnName);
128
}
129
137
public
function
upper
($columnName)
138
{
139
$alias = static::getTmpName(
'UPPER'
);
140
return
new
ExpressionField
($alias,
'UPPER(%s)'
, $columnName);
141
}
142
150
public
function
concat
()
151
{
152
$helper =
Application::getConnection
()->getSqlHelper();
153
$columns = func_get_args();
154
$alias = static::getTmpName(
'CONCAT'
);
155
156
// get ... format as well as single array
157
if
(
count
($columns) == 1 && is_array($columns[0]))
158
{
159
$columns = $columns[0];
160
}
161
162
$holders = array_fill(0,
count
($columns),
'%s'
);
163
$expr = call_user_func_array([$helper,
'getConcatFunction'
], $holders);
164
165
return
new
ExpressionField
($alias, $expr, $columns);
166
}
167
175
protected
static
function
getTmpName
($postfix)
176
{
177
return
'A'
.strtoupper(Random::getString(6).
'_'
.$postfix);
178
}
179
}
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getConnection
static getConnection($name="")
Definition
application.php:611
Bitrix\Main\ORM\Fields\ExpressionField
Definition
expressionfield.php:25
Bitrix\Main\ORM\Query\Expression
Definition
expression.php:23
Bitrix\Main\ORM\Query\Expression\upper
upper($columnName)
Definition
expression.php:137
Bitrix\Main\ORM\Query\Expression\max
max($columnName)
Definition
expression.php:96
Bitrix\Main\ORM\Query\Expression\concat
concat()
Definition
expression.php:150
Bitrix\Main\ORM\Query\Expression\min
min($columnName)
Definition
expression.php:70
Bitrix\Main\ORM\Query\Expression\avg
avg($columnName)
Definition
expression.php:83
Bitrix\Main\ORM\Query\Expression\getTmpName
static getTmpName($postfix)
Definition
expression.php:175
Bitrix\Main\ORM\Query\Expression\sum
sum($columnName)
Definition
expression.php:57
Bitrix\Main\ORM\Query\Expression\lower
lower($columnName)
Definition
expression.php:124
Bitrix\Main\ORM\Query\Expression\length
length($columnName)
Definition
expression.php:109
Bitrix\Main\ORM\Query\Expression\countDistinct
countDistinct($columnName)
Definition
expression.php:44
Bitrix\Main\ORM\Query\Expression\count
count($columnName)
Definition
expression.php:31
Bitrix\Main\ORM\Query\Filter\ConditionTree
Definition
conditiontree.php:28
Bitrix\Main\Security\Random
Definition
random.php:6
Bitrix\Main\ORM\Query
Definition
chain.php:3
modules
main
lib
orm
query
expression.php
Создано системой
1.10.0