forked from aternosorg/php-model
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectQuery.php
More file actions
135 lines (121 loc) · 3.11 KB
/
SelectQuery.php
File metadata and controls
135 lines (121 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace Aternos\Model\Query;
/**
* Class SelectQuery
*
* @package Aternos\Model\Query
*/
class SelectQuery extends Query
{
/**
* @var SelectField[]
*/
protected ?array $fields = null;
protected ?array $group = null;
protected ?array $joins = null;
/**
* SelectQuery constructor.
*
* @param array|WhereCondition|WhereGroup|null $where
* @param array|null $order
* @param array|null $fields
* @param array|int|Limit|null $limit
* @param array|GroupField[]|string[]|null $group
*/
/**
* SelectQuery constructor.
*
* @param array|WhereCondition|WhereGroup|null $where
* @param array|null $order
* @param array|null $fields
* @param array|int|Limit|null $limit
* @param array|GroupField[]|string[]|null $group
*/
public function __construct(null|WhereCondition|array|WhereGroup $where = null,
null|array $order = null,
null|array $fields = null,
null|Limit|array|int $limit = null,
null|array $group = null,
null|array $joins = null)
{
if ($where) {
$this->where($where);
}
if ($order) {
$this->orderBy($order);
}
if ($fields) {
$this->fields($fields);
}
if ($limit) {
$this->limit($limit);
}
if ($group) {
$this->groupBy($group);
}
if ($joins) {
$this->joins($joins);
}
}
/**
* Set fields
*
* @param array $fields
* @return $this
*/
public function fields(array $fields): static
{
$this->fields = [];
foreach ($fields as $field) {
if ($field instanceof SelectField) {
$this->fields[] = $field;
} else if (is_string($field)) {
$this->fields[] = new SelectField($field);
}
}
return $this;
}
/**
* Set group by fields
*
* @param array|GroupField[]|string[] $fields
* @return $this
*/
public function groupBy(array $fields): static
{
$this->group = null;
foreach ($fields as $key => $field) {
if ($field instanceof GroupField) {
$this->group[] = $field;
} else if (is_string($field)) {
$this->group[] = new GroupField($field);
}
}
return $this;
}
/**
* @return array|null|GroupField[]
*/
public function getGroup(): ?array
{
return $this->group;
}
/**
* Set joins
*
* @param array $fields
* @return $this
*/
public function joins(array $joins): static
{
$this->joins = $joins;
return $this;
}
/**
* @return array|null
*/
public function getJoins(): ?array
{
return $this->joins;
}
}