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\ember\db\CacheableActiveQuery; |
13
|
|
|
use flipbox\ember\db\traits\AuditAttributes; |
14
|
|
|
use flipbox\ember\db\traits\ElementAttribute; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Flipbox Factory <[email protected]> |
18
|
|
|
* @since 1.0.0 |
19
|
|
|
*/ |
20
|
|
|
class ElementMetricQuery extends CacheableActiveQuery |
21
|
|
|
{ |
22
|
|
|
use ElementAttribute, |
23
|
|
|
AuditAttributes; |
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
|
|
|
* return static |
62
|
|
|
*/ |
63
|
|
|
public function dateCalculated($value) |
64
|
|
|
{ |
65
|
|
|
$this->dateCalculated = $value; |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/******************************************* |
70
|
|
|
* ATTRIBUTES |
71
|
|
|
*******************************************/ |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param int|int[]|string|string[]|null $id |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function id($id) |
78
|
|
|
{ |
79
|
|
|
$this->id = $id; |
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param int|int[]|string|string[]|null $id |
85
|
|
|
* @return $this |
86
|
|
|
*/ |
87
|
|
|
public function setId($id) |
88
|
|
|
{ |
89
|
|
|
return $this->id($id); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param int|int[]|string|string[]|null $id |
94
|
|
|
* @return $this |
95
|
|
|
*/ |
96
|
|
|
public function parentId($id) |
97
|
|
|
{ |
98
|
|
|
$this->parentId = $id; |
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param int|int[]|string|string[]|null $id |
104
|
|
|
* @return $this |
105
|
|
|
*/ |
106
|
|
|
public function setParentId($id) |
107
|
|
|
{ |
108
|
|
|
return $this->parentId($id); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param float|float[]|string|string[]|null $score |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
|
|
public function score($score) |
116
|
|
|
{ |
117
|
|
|
$this->score = $score; |
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param float|float[]|string|string[]|null $score |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
|
|
public function setScore($score) |
126
|
|
|
{ |
127
|
|
|
return $this->score($score); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param float|float[]|string|string[]|null $weight |
132
|
|
|
* @return $this |
133
|
|
|
*/ |
134
|
|
|
public function weight($weight) |
135
|
|
|
{ |
136
|
|
|
$this->weight = $weight; |
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param float|float[]|string|string[]|null $weight |
142
|
|
|
* @return $this |
143
|
|
|
*/ |
144
|
|
|
public function setWeight($weight) |
145
|
|
|
{ |
146
|
|
|
return $this->weight($weight); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param string|string[]|null $version |
151
|
|
|
* @return $this |
152
|
|
|
*/ |
153
|
|
|
public function version($version) |
154
|
|
|
{ |
155
|
|
|
$this->version = $version; |
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param string|string[]|null $version |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
|
|
public function setVersion($version) |
164
|
|
|
{ |
165
|
|
|
return $this->version($version); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param string|string[]|null $class |
170
|
|
|
* @return $this |
171
|
|
|
*/ |
172
|
|
|
public function class($class) |
173
|
|
|
{ |
174
|
|
|
$this->class = $class; |
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string|string[]|null $class |
180
|
|
|
* @return $this |
181
|
|
|
*/ |
182
|
|
|
public function setClass($class) |
183
|
|
|
{ |
184
|
|
|
return $this->class($class); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/******************************************* |
188
|
|
|
* PREPARE |
189
|
|
|
*******************************************/ |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @inheritdoc |
193
|
|
|
*/ |
194
|
|
|
public function prepare($builder) |
195
|
|
|
{ |
196
|
|
|
// Apply attribute params |
197
|
|
|
$this->prepareParams(); |
198
|
|
|
$this->applyAuditAttributeConditions(); |
199
|
|
|
|
200
|
|
|
return parent::prepare($builder); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/******************************************* |
204
|
|
|
* PREPARE PARAMS |
205
|
|
|
*******************************************/ |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Apply environment params |
209
|
|
|
*/ |
210
|
|
|
protected function prepareParams() |
211
|
|
|
{ |
212
|
|
|
$attributes = ['id', 'parentId', 'score', 'weight', 'version', 'class']; |
213
|
|
|
|
214
|
|
|
foreach ($attributes as $attribute) { |
215
|
|
|
if (($value = $this->{$attribute}) !== null) { |
216
|
|
|
$this->andWhere(Db::parseParam($attribute, $value)); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
if (($value = $this->element) !== null) { |
221
|
|
|
$this->andWhere(Db::parseParam('elementId', $value)); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
if ($this->dateCalculated !== null) { |
225
|
|
|
$this->andWhere(Db::parseDateParam('dateCalculated', $this->dateCalculated)); |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|