Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
expression.php
1<?php
14
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}
static getConnection($name="")