1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.6.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Libraries\Database\Idiorm\Statements; |
16
|
|
|
|
17
|
|
|
use Quantum\Libraries\Database\DbalInterface; |
18
|
|
|
use RecursiveIteratorIterator; |
19
|
|
|
use RecursiveArrayIterator; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Trait Modifier |
23
|
|
|
* @package Quantum\Libraries\Database\Idiorm\Statements |
24
|
|
|
*/ |
25
|
|
|
trait Reducer |
26
|
|
|
{ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @inheritDoc |
30
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
31
|
|
|
*/ |
32
|
|
|
public function select(...$columns): DbalInterface |
33
|
|
|
{ |
34
|
|
|
array_walk($columns, function (&$column) { |
35
|
|
|
if (is_array($column)) { |
36
|
|
|
$column = array_flip($column); |
37
|
|
|
} |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($columns)); |
41
|
|
|
$columns = iterator_to_array($iterator, true); |
42
|
|
|
|
43
|
|
|
$this->getOrmModel()->select_many($columns); |
|
|
|
|
44
|
|
|
return $this; |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritDoc |
49
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
50
|
|
|
*/ |
51
|
|
|
public function groupBy(string $column): DbalInterface |
52
|
|
|
{ |
53
|
|
|
$this->getOrmModel()->group_by($column); |
54
|
|
|
return $this; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritDoc |
59
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
60
|
|
|
*/ |
61
|
|
|
public function orderBy(string $column, string $direction): DbalInterface |
62
|
|
|
{ |
63
|
|
|
switch (strtolower($direction)) { |
64
|
|
|
case 'asc': |
65
|
|
|
$this->getOrmModel()->order_by_asc($column); |
66
|
|
|
break; |
67
|
|
|
case 'desc': |
68
|
|
|
$this->getOrmModel()->order_by_desc($column); |
69
|
|
|
break; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $this; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritDoc |
77
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
78
|
|
|
*/ |
79
|
|
|
public function offset(int $offset): DbalInterface |
80
|
|
|
{ |
81
|
|
|
$this->getOrmModel()->offset($offset); |
82
|
|
|
return $this; |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @inheritDoc |
87
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
88
|
|
|
*/ |
89
|
|
|
public function limit(int $limit): DbalInterface |
90
|
|
|
{ |
91
|
|
|
$this->getOrmModel()->limit($limit); |
92
|
|
|
return $this; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |