@@ -40,7 +40,7 @@ |
||
40 | 40 | |
41 | 41 | |
42 | 42 | /** |
43 | - * @param DibiFluent $data_source |
|
43 | + * @param Dibi\Fluent $data_source |
|
44 | 44 | * @param string $primary_key |
45 | 45 | */ |
46 | 46 | public function __construct(\Dibi\Fluent $data_source, $primary_key) |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | \dibi::IDENTIFIER |
172 | 172 | ); |
173 | 173 | |
174 | - if ($filter->isExactSearch()){ |
|
174 | + if ($filter->isExactSearch()) { |
|
175 | 175 | $this->data_source->where("$column = %s", $value); |
176 | 176 | continue; |
177 | 177 | } |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | |
304 | 304 | public function addAggregationColumn($aggregation_type, $column) { |
305 | 305 | |
306 | - $this->aggregation_data_source = $this->aggregation_data_source->select($aggregation_type .'(%n)', $column)->as($column); |
|
306 | + $this->aggregation_data_source = $this->aggregation_data_source->select($aggregation_type.'(%n)', $column)->as($column); |
|
307 | 307 | } |
308 | 308 | |
309 | - public function getAggregationData(){ |
|
309 | + public function getAggregationData() { |
|
310 | 310 | $data = $this->aggregation_data_source->from($this->data_source)->as('data')->fetch(); |
311 | 311 | return $data; |
312 | 312 | } |
@@ -148,17 +148,17 @@ |
||
148 | 148 | /** |
149 | 149 | * @param array |
150 | 150 | */ |
151 | - public function aggregationRow(array $columns){ |
|
151 | + public function aggregationRow(array $columns) { |
|
152 | 152 | $hasAggregation = FALSE; |
153 | 153 | /** @var Column $column */ |
154 | - foreach($columns as $column){ |
|
155 | - if($column->hasAggregationFunction()){ |
|
154 | + foreach ($columns as $column) { |
|
155 | + if ($column->hasAggregationFunction()) { |
|
156 | 156 | $hasAggregation = TRUE; |
157 | 157 | $aggregationFunction = $column->getAggregationFunction(); |
158 | 158 | $this->data_source->addAggregationColumn($aggregationFunction->getAggregationType(), $aggregationFunction->getColumn()); |
159 | 159 | } |
160 | 160 | } |
161 | - if(!$hasAggregation){ |
|
161 | + if (!$hasAggregation) { |
|
162 | 162 | return FALSE; |
163 | 163 | } |
164 | 164 | $this->data_source->getAggregationData(); |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | $date_end = clone $date; |
108 | 108 | |
109 | 109 | $this->data_source = $this->data_source->findBy([ |
110 | - $this->prepareColumn($column) . '>=' => $date->setTime(0, 0, 0), |
|
111 | - $this->prepareColumn($column) . '<=' => $date_end->setTime(23, 59, 59) |
|
110 | + $this->prepareColumn($column).'>=' => $date->setTime(0, 0, 0), |
|
111 | + $this->prepareColumn($column).'<=' => $date_end->setTime(23, 59, 59) |
|
112 | 112 | ]); |
113 | 113 | } |
114 | 114 | |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | $dataCondition = []; |
132 | 132 | if ($value_from) { |
133 | 133 | $date_from = \DateTime::createFromFormat($filter->getPhpFormat(), $value_from); |
134 | - $dataCondition[$this->prepareColumn($filter->getColumn()) . '>='] = $date_from->setTime(0, 0, 0); |
|
134 | + $dataCondition[$this->prepareColumn($filter->getColumn()).'>='] = $date_from->setTime(0, 0, 0); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | if ($value_to) { |
138 | 138 | $date_to = \DateTime::createFromFormat($filter->getPhpFormat(), $value_to); |
139 | - $dataCondition[$this->prepareColumn($filter->getColumn()) . '<='] = $date_to->setTime(23, 59, 59); |
|
139 | + $dataCondition[$this->prepareColumn($filter->getColumn()).'<='] = $date_to->setTime(23, 59, 59); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | if (!empty($dataCondition)) { |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | $dataCondition = []; |
161 | 161 | |
162 | 162 | if ($value_from) { |
163 | - $dataCondition[$this->prepareColumn($filter->getColumn()) . '>='] = $value_from; |
|
163 | + $dataCondition[$this->prepareColumn($filter->getColumn()).'>='] = $value_from; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | if ($value_to) { |
167 | - $dataCondition[$this->prepareColumn($filter->getColumn()) . '<='] = $value_to; |
|
167 | + $dataCondition[$this->prepareColumn($filter->getColumn()).'<='] = $value_to; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | if (!empty($dataCondition)) { |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | $params = []; |
186 | 186 | |
187 | 187 | foreach ($condition as $column => $value) { |
188 | - if($filter->isExactSearch()){ |
|
188 | + if ($filter->isExactSearch()) { |
|
189 | 189 | $expr .= "%column = %s OR "; |
190 | 190 | $params[] = $column; |
191 | 191 | $params[] = "$value"; |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | */ |
308 | 308 | private function prepareColumn($column) { |
309 | 309 | if (Strings::contains($column, '.')) { |
310 | - return 'this->' . str_replace('.', '->', $column); |
|
310 | + return 'this->'.str_replace('.', '->', $column); |
|
311 | 311 | } |
312 | 312 | return $column; |
313 | 313 | } |
@@ -328,15 +328,15 @@ discard block |
||
328 | 328 | */ |
329 | 329 | public function getAggregationData() |
330 | 330 | { |
331 | - if(count($this->aggregations)==0){ |
|
331 | + if (count($this->aggregations) == 0) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | 334 | $sql = 'SELECT '; |
335 | - foreach($this->aggregations as $column => $aggregation_type){ |
|
336 | - $sql .= $aggregation_type . '(' . $column . ') as ' . $column . ','; |
|
335 | + foreach ($this->aggregations as $column => $aggregation_type) { |
|
336 | + $sql .= $aggregation_type.'('.$column.') as '.$column.','; |
|
337 | 337 | } |
338 | 338 | |
339 | - $sql = rtrim($sql, ',') . ' FROM ( ' . $this->data_source->getQueryBuilder()->getQuerySql() . ' ) as data'; |
|
339 | + $sql = rtrim($sql, ',').' FROM ( '.$this->data_source->getQueryBuilder()->getQuerySql().' ) as data'; |
|
340 | 340 | |
341 | 341 | $params = $this->data_source->getQueryBuilder()->getQueryParameters(); |
342 | 342 | array_unshift($params, $sql); |
@@ -389,23 +389,23 @@ discard block |
||
389 | 389 | public function getAggregationData() |
390 | 390 | { |
391 | 391 | $result = []; |
392 | - foreach($this->data as $row){ |
|
393 | - foreach($this->aggregations as $column => $aggregation_type){ |
|
394 | - switch($aggregation_type){ |
|
392 | + foreach ($this->data as $row) { |
|
393 | + foreach ($this->aggregations as $column => $aggregation_type) { |
|
394 | + switch ($aggregation_type) { |
|
395 | 395 | case ColumnAggregationFunction::$aggregation_type_sum: |
396 | 396 | case ColumnAggregationFunction::$aggregation_type_avg: |
397 | - if(!isset($result[$column])){ |
|
397 | + if (!isset($result[$column])) { |
|
398 | 398 | $result[$column] = 0; |
399 | 399 | } |
400 | 400 | $result[$column] += $row[$column]; |
401 | 401 | break; |
402 | 402 | case ColumnAggregationFunction::$aggregation_type_min: |
403 | - if(!isset($result[$column]) || $row[$column] < $result[$column]){ |
|
403 | + if (!isset($result[$column]) || $row[$column] < $result[$column]) { |
|
404 | 404 | $result[$column] = $row[$column]; |
405 | 405 | } |
406 | 406 | break; |
407 | 407 | case ColumnAggregationFunction::$aggregation_type_max: |
408 | - if(!isset($result[$column]) || $row[$column] > $result[$column]){ |
|
408 | + if (!isset($result[$column]) || $row[$column] > $result[$column]) { |
|
409 | 409 | $result[$column] = $row[$column]; |
410 | 410 | } |
411 | 411 | break; |
@@ -413,9 +413,9 @@ discard block |
||
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | - foreach($this->aggregations as $column => $aggregation_type) { |
|
417 | - if($aggregation_type == ColumnAggregationFunction::$aggregation_type_avg){ |
|
418 | - $result[$column] = $result[$column] / count($this->data); |
|
416 | + foreach ($this->aggregations as $column => $aggregation_type) { |
|
417 | + if ($aggregation_type == ColumnAggregationFunction::$aggregation_type_avg) { |
|
418 | + $result[$column] = $result[$column] / count($this->data); |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | return $result; |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @var array |
25 | 25 | */ |
26 | - protected $aggregations =[]; |
|
26 | + protected $aggregations = []; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @var array |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | return $this->data_source->count( |
69 | - $this->data_source->getName() . '.' . (is_array($primary) ? reset($primary) : $primary) |
|
69 | + $this->data_source->getName().'.'.(is_array($primary) ? reset($primary) : $primary) |
|
70 | 70 | ); |
71 | 71 | } |
72 | 72 | |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | $like = '('; |
178 | 178 | $args = []; |
179 | 179 | |
180 | - if($filter->isExactSearch()){ |
|
181 | - $like .= "$column = ? OR "; |
|
180 | + if ($filter->isExactSearch()) { |
|
181 | + $like .= "$column = ? OR "; |
|
182 | 182 | $args[] = "$value"; |
183 | 183 | } else { |
184 | 184 | if ($filter->hasSplitWordsSearch() === FALSE) { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $args[] = "%$word%"; |
192 | 192 | } |
193 | 193 | } |
194 | - $like = substr($like, 0, strlen($like) - 4) . ')'; |
|
194 | + $like = substr($like, 0, strlen($like) - 4).')'; |
|
195 | 195 | |
196 | 196 | $or[] = $like; |
197 | 197 | $big_or .= "$like OR "; |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | |
230 | 230 | foreach ($values as $value) { |
231 | 231 | if ($i == $length) { |
232 | - $or .= $filter->getColumn() . ' = ?)'; |
|
232 | + $or .= $filter->getColumn().' = ?)'; |
|
233 | 233 | } else { |
234 | - $or .= $filter->getColumn() . ' = ? OR '; |
|
234 | + $or .= $filter->getColumn().' = ? OR '; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | $i++; |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | |
242 | 242 | call_user_func_array([$this->data_source, 'where'], $values); |
243 | 243 | } else { |
244 | - $this->data_source->where($filter->getColumn() . ' = ?', reset($values)); |
|
244 | + $this->data_source->where($filter->getColumn().' = ?', reset($values)); |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
@@ -326,8 +326,8 @@ discard block |
||
326 | 326 | { |
327 | 327 | $result = []; |
328 | 328 | //there should really be some better way to do this and get all results in one query, this could be big performance issue on bigger tables |
329 | - foreach($this->aggregations as $column => $aggregation_type){ |
|
330 | - $result[$column] = $this->data_source->aggregation($aggregation_type . '(' . $column . ')'); |
|
329 | + foreach ($this->aggregations as $column => $aggregation_type) { |
|
330 | + $result[$column] = $this->data_source->aggregation($aggregation_type.'('.$column.')'); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | return $result; |