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\domains\db; |
10
|
|
|
|
11
|
|
|
use craft\db\QueryAbortedException; |
12
|
|
|
use craft\helpers\Db; |
13
|
|
|
use flipbox\craft\sortable\associations\db\SortableAssociationQuery; |
14
|
|
|
use flipbox\craft\sortable\associations\db\traits\SiteAttribute; |
15
|
|
|
use flipbox\domains\records\Domain; |
16
|
|
|
use flipbox\ember\db\traits\ElementAttribute; |
17
|
|
|
use flipbox\ember\helpers\QueryHelper; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @method Domain[] getCachedResult() |
21
|
|
|
*/ |
22
|
|
|
class DomainsQuery extends SortableAssociationQuery |
23
|
|
|
{ |
24
|
|
|
use traits\Attributes, |
25
|
|
|
traits\FieldAttribute, |
26
|
|
|
ElementAttribute, |
27
|
|
|
SiteAttribute; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @inheritdoc |
31
|
|
|
*/ |
32
|
|
|
protected function fixedOrderColumn(): string |
33
|
|
|
{ |
34
|
|
|
return 'domain'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array $config |
39
|
|
|
* @return $this |
40
|
|
|
*/ |
41
|
|
|
public function configure(array $config) |
42
|
|
|
{ |
43
|
|
|
QueryHelper::configure( |
44
|
|
|
$this, |
45
|
|
|
$config |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritdoc |
53
|
|
|
* |
54
|
|
|
* @throws QueryAbortedException if it can be determined that there won’t be any results |
55
|
|
|
*/ |
56
|
|
|
public function prepare($builder) |
57
|
|
|
{ |
58
|
|
|
// Is the query already doomed? |
59
|
|
|
if (($this->field !== null && empty($this->field)) || |
60
|
|
|
($this->domain !== null && empty($this->domain)) || |
61
|
|
|
($this->element !== null && empty($this->element)) |
62
|
|
|
) { |
63
|
|
|
throw new QueryAbortedException(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->applyConditions(); |
67
|
|
|
$this->applySiteConditions(); |
68
|
|
|
$this->applyFieldConditions(); |
69
|
|
|
|
70
|
|
|
if ($this->element !== null) { |
71
|
|
|
$this->andWhere(Db::parseParam('elementId', $this->parseElementValue($this->element))); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return parent::prepare($builder); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|