1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/scorecard/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/scorecard/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\craft\scorecard\queries; |
10
|
|
|
|
11
|
|
|
use craft\helpers\Db; |
12
|
|
|
use flipbox\craft\ember\queries\CacheableActiveQuery; |
13
|
|
|
use flipbox\craft\ember\queries\AuditAttributesTrait; |
14
|
|
|
use flipbox\craft\ember\queries\ElementAttributeTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Flipbox Factory <[email protected]> |
18
|
|
|
* @since 1.0.0 |
19
|
|
|
*/ |
20
|
|
|
class ElementMetricQuery extends CacheableActiveQuery |
21
|
|
|
{ |
22
|
|
|
use ElementAttributeTrait, |
23
|
|
|
AuditAttributesTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int|int[]|string|string[]|null |
27
|
|
|
*/ |
28
|
|
|
public $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int|int[]|string|string[]|null |
32
|
|
|
*/ |
33
|
|
|
public $parentId = ':empty:'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var float|float[]|string|string[]|null |
37
|
|
|
*/ |
38
|
|
|
public $score; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var float|float[]|string|string[]|null |
42
|
|
|
*/ |
43
|
|
|
public $weight; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string|string[]|null |
47
|
|
|
*/ |
48
|
|
|
public $version; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string|string[]|null |
52
|
|
|
*/ |
53
|
|
|
public $class; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var mixed |
57
|
|
|
*/ |
58
|
|
|
public $dateCalculated; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
public $orderBy = [ |
64
|
|
|
'dateCalculated' => SORT_DESC |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/******************************************* |
69
|
|
|
* ATTRIBUTES |
70
|
|
|
*******************************************/ |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param int|int[]|string|string[]|null $id |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
|
|
public function id($id) |
77
|
|
|
{ |
78
|
|
|
$this->id = $id; |
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param int|int[]|string|string[]|null $id |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function setId($id) |
87
|
|
|
{ |
88
|
|
|
return $this->id($id); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param int|int[]|string|string[]|null $id |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function parentId($id) |
96
|
|
|
{ |
97
|
|
|
$this->parentId = $id; |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param int|int[]|string|string[]|null $id |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
|
|
public function setParentId($id) |
106
|
|
|
{ |
107
|
|
|
return $this->parentId($id); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param float|float[]|string|string[]|null $score |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
|
|
public function score($score) |
115
|
|
|
{ |
116
|
|
|
$this->score = $score; |
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param float|float[]|string|string[]|null $score |
122
|
|
|
* @return $this |
123
|
|
|
*/ |
124
|
|
|
public function setScore($score) |
125
|
|
|
{ |
126
|
|
|
return $this->score($score); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param float|float[]|string|string[]|null $weight |
131
|
|
|
* @return $this |
132
|
|
|
*/ |
133
|
|
|
public function weight($weight) |
134
|
|
|
{ |
135
|
|
|
$this->weight = $weight; |
136
|
|
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param float|float[]|string|string[]|null $weight |
141
|
|
|
* @return $this |
142
|
|
|
*/ |
143
|
|
|
public function setWeight($weight) |
144
|
|
|
{ |
145
|
|
|
return $this->weight($weight); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param string|string[]|null $version |
150
|
|
|
* @return $this |
151
|
|
|
*/ |
152
|
|
|
public function version($version) |
153
|
|
|
{ |
154
|
|
|
$this->version = $version; |
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string|string[]|null $version |
160
|
|
|
* @return $this |
161
|
|
|
*/ |
162
|
|
|
public function setVersion($version) |
163
|
|
|
{ |
164
|
|
|
return $this->version($version); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param string|string[]|null $class |
169
|
|
|
* @return $this |
170
|
|
|
*/ |
171
|
|
|
public function class($class) |
172
|
|
|
{ |
173
|
|
|
$this->class = $class; |
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string|string[]|null $class |
179
|
|
|
* @return $this |
180
|
|
|
*/ |
181
|
|
|
public function setClass($class) |
182
|
|
|
{ |
183
|
|
|
return $this->class($class); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param mixed $value |
188
|
|
|
* @return $this |
189
|
|
|
*/ |
190
|
|
|
public function dateCalculated($value) |
191
|
|
|
{ |
192
|
|
|
$this->dateCalculated = $value; |
193
|
|
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param mixed $value |
198
|
|
|
* @return $this |
199
|
|
|
*/ |
200
|
|
|
public function setDateCalculated($value) |
201
|
|
|
{ |
202
|
|
|
return $this->dateCalculated($value); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/******************************************* |
206
|
|
|
* PREPARE |
207
|
|
|
*******************************************/ |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @inheritdoc |
211
|
|
|
*/ |
212
|
|
|
public function prepare($builder) |
213
|
|
|
{ |
214
|
|
|
// Apply attribute params |
215
|
|
|
$this->prepareParams(); |
216
|
|
|
$this->applyAuditAttributeConditions(); |
217
|
|
|
|
218
|
|
|
return parent::prepare($builder); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/******************************************* |
222
|
|
|
* PREPARE PARAMS |
223
|
|
|
*******************************************/ |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Apply environment params |
227
|
|
|
*/ |
228
|
|
|
protected function prepareParams() |
229
|
|
|
{ |
230
|
|
|
$attributes = ['id', 'parentId', 'score', 'weight', 'version', 'class']; |
231
|
|
|
|
232
|
|
|
foreach ($attributes as $attribute) { |
233
|
|
|
if (($value = $this->{$attribute}) !== null) { |
234
|
|
|
$this->andWhere(Db::parseParam($attribute, $value)); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
if (($value = $this->element) !== null) { |
239
|
|
|
$this->andWhere(Db::parseParam('elementId', $value)); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
if ($this->dateCalculated !== null) { |
243
|
|
|
$this->andWhere(Db::parseDateParam('dateCalculated', $this->dateCalculated)); |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|