1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/domains/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/domains/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\craft\domains\queries; |
10
|
|
|
|
11
|
|
|
use craft\db\QueryAbortedException; |
12
|
|
|
use craft\helpers\Db; |
13
|
|
|
use flipbox\craft\ember\helpers\QueryHelper; |
14
|
|
|
use flipbox\craft\ember\queries\CacheableActiveQuery; |
15
|
|
|
use flipbox\craft\ember\queries\ElementAttributeTrait; |
16
|
|
|
use flipbox\craft\ember\queries\FieldAttributeTrait; |
17
|
|
|
use flipbox\craft\ember\queries\SiteAttributeTrait; |
18
|
|
|
use flipbox\craft\domains\records\Domain; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @method Domain[] getCachedResult() |
22
|
|
|
*/ |
23
|
|
|
class DomainsQuery extends CacheableActiveQuery |
24
|
|
|
{ |
25
|
|
|
use FieldAttributeTrait, |
26
|
|
|
ElementAttributeTrait, |
27
|
|
|
SiteAttributeTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string|string[]|false|null The domain(s). Prefix with "not " to exclude them. |
31
|
|
|
*/ |
32
|
|
|
public $domain; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string|string[]|false|null The status(es). Prefix with "not " to exclude them. |
36
|
|
|
*/ |
37
|
|
|
public $status; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param array $config |
41
|
|
|
* @return $this |
42
|
|
|
*/ |
43
|
|
|
public function configure(array $config) |
44
|
|
|
{ |
45
|
|
|
QueryHelper::configure( |
46
|
|
|
$this, |
47
|
|
|
$config |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param $value |
55
|
|
|
* @return static |
56
|
|
|
*/ |
57
|
|
|
public function domain($value) |
58
|
|
|
{ |
59
|
|
|
$this->domain = $value; |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param $value |
65
|
|
|
* @return static |
66
|
|
|
*/ |
67
|
|
|
public function setDomain($value) |
68
|
|
|
{ |
69
|
|
|
return $this->domain($value); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param $value |
74
|
|
|
* @return static |
75
|
|
|
*/ |
76
|
|
|
public function status($value) |
77
|
|
|
{ |
78
|
|
|
$this->status = $value; |
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param $value |
84
|
|
|
* @return static |
85
|
|
|
*/ |
86
|
|
|
public function setStatus($value) |
87
|
|
|
{ |
88
|
|
|
return $this->status($value); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritdoc |
93
|
|
|
* |
94
|
|
|
* @throws QueryAbortedException if it can be determined that there won’t be any results |
95
|
|
|
*/ |
96
|
|
|
public function prepare($builder) |
97
|
|
|
{ |
98
|
|
|
// Is the query already doomed? |
99
|
|
|
if (($this->field !== null && empty($this->field)) || |
100
|
|
|
($this->domain !== null && empty($this->domain)) || |
101
|
|
|
($this->element !== null && empty($this->element)) |
102
|
|
|
) { |
103
|
|
|
throw new QueryAbortedException(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->applyConditions(); |
107
|
|
|
$this->applySiteConditions(); |
108
|
|
|
$this->applyFieldConditions(); |
109
|
|
|
$this->applyElementConditions(); |
110
|
|
|
|
111
|
|
|
return parent::prepare($builder); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Apply attribute conditions |
116
|
|
|
*/ |
117
|
|
|
protected function applyConditions() |
118
|
|
|
{ |
119
|
|
|
$attributes = ['domain', 'status']; |
120
|
|
|
|
121
|
|
|
foreach ($attributes as $attribute) { |
122
|
|
|
if (null !== ($value = $this->{$attribute})) { |
123
|
|
|
$this->andWhere(Db::parseParam($attribute, $value)); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Apply query specific conditions |
130
|
|
|
*/ |
131
|
|
|
protected function applyElementConditions() |
132
|
|
|
{ |
133
|
|
|
if ($this->element !== null) { |
134
|
|
|
$this->andWhere(Db::parseParam('elementId', $this->parseElementValue($this->element))); |
|
|
|
|
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Apply query specific conditions |
140
|
|
|
*/ |
141
|
|
|
protected function applyFieldConditions() |
142
|
|
|
{ |
143
|
|
|
if ($this->field !== null) { |
144
|
|
|
$this->andWhere(Db::parseParam('fieldId', $this->parseFieldValue($this->field))); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Apply query specific conditions |
150
|
|
|
*/ |
151
|
|
|
protected function applySiteConditions() |
152
|
|
|
{ |
153
|
|
|
if ($this->site !== null) { |
154
|
|
|
$this->andWhere(Db::parseParam('siteId', $this->parseSiteValue($this->site))); |
|
|
|
|
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.