1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/organization/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/organization/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\organizations\queries; |
10
|
|
|
|
11
|
|
|
use craft\db\QueryAbortedException; |
12
|
|
|
use craft\helpers\Db; |
13
|
|
|
use flipbox\craft\ember\queries\ActiveQuery; |
14
|
|
|
use flipbox\craft\ember\queries\AuditAttributesTrait; |
15
|
|
|
use flipbox\organizations\records\OrganizationTypeAssociation; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Flipbox Factory <[email protected]> |
19
|
|
|
* @since 1.0.0 |
20
|
|
|
* |
21
|
|
|
* @method OrganizationTypeAssociation one($db = null) |
22
|
|
|
* @method OrganizationTypeAssociation[] all($db = null) |
23
|
|
|
* @method OrganizationTypeAssociation[] getCachedResult($db = null) |
24
|
|
|
*/ |
25
|
|
|
class OrganizationTypeAssociationQuery extends ActiveQuery |
26
|
|
|
{ |
27
|
|
|
use OrganizationTypeAttributeTrait, |
28
|
|
|
OrganizationAttributeTrait, |
29
|
|
|
AuditAttributesTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int|null |
33
|
|
|
*/ |
34
|
|
|
public $sortOrder; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param $sortOrder |
38
|
|
|
* @return $this |
39
|
|
|
*/ |
40
|
|
|
public function sortOrder($sortOrder) |
41
|
|
|
{ |
42
|
|
|
$this->sortOrder = $sortOrder; |
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param $sortOrder |
48
|
|
|
* @return OrganizationTypeAssociationQuery |
49
|
|
|
*/ |
50
|
|
|
public function setSortOrder($sortOrder) |
51
|
|
|
{ |
52
|
|
|
return $this->sortOrder($sortOrder); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritdoc |
57
|
|
|
*/ |
58
|
|
|
public function init() |
59
|
|
|
{ |
60
|
|
|
$this->from([ |
61
|
|
|
OrganizationTypeAssociation::tableName() . ' ' . OrganizationTypeAssociation::tableAlias() |
62
|
|
|
]); |
63
|
|
|
|
64
|
|
|
parent::init(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param $value |
69
|
|
|
* @return static |
70
|
|
|
* @see $this->>organizationType() |
71
|
|
|
*/ |
72
|
|
|
public function type($value) |
73
|
|
|
{ |
74
|
|
|
return $this->organizationType($value); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param $value |
79
|
|
|
* @return static |
80
|
|
|
* @see $this->>organizationType() |
81
|
|
|
*/ |
82
|
|
|
public function typeId($value) |
83
|
|
|
{ |
84
|
|
|
return $this->organizationType($value); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @inheritdoc |
89
|
|
|
* @throws QueryAbortedException |
90
|
|
|
*/ |
91
|
|
|
public function prepare($builder) |
92
|
|
|
{ |
93
|
|
|
$attributes = ['sortOrder']; |
94
|
|
|
|
95
|
|
|
foreach ($attributes as $attribute) { |
96
|
|
|
if (null !== ($value = $this->{$attribute})) { |
97
|
|
|
$this->andWhere( |
98
|
|
|
Db::parseParam($attribute, $value) |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$this->applyAuditAttributeConditions(); |
104
|
|
|
$this->applyOrganizationParam(); |
105
|
|
|
$this->applyOrganizationTypeParam(); |
106
|
|
|
|
107
|
|
|
return parent::prepare($builder); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return void |
112
|
|
|
* @throws QueryAbortedException |
113
|
|
|
*/ |
114
|
|
|
protected function applyOrganizationTypeParam() |
115
|
|
|
{ |
116
|
|
|
// Is the query already doomed? |
117
|
|
|
if ($this->organizationType !== null && empty($this->organizationType)) { |
118
|
|
|
throw new QueryAbortedException(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
if (empty($this->organizationType)) { |
122
|
|
|
return; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$this->andWhere( |
126
|
|
|
Db::parseParam('typeId', $this->parseOrganizationTypeValue($this->organizationType)) |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return void |
132
|
|
|
* @throws QueryAbortedException |
133
|
|
|
*/ |
134
|
|
|
protected function applyOrganizationParam() |
135
|
|
|
{ |
136
|
|
|
// Is the query already doomed? |
137
|
|
|
if ($this->organization !== null && empty($this->organization)) { |
138
|
|
|
throw new QueryAbortedException(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
if (empty($this->organization)) { |
142
|
|
|
return; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$this->andWhere( |
146
|
|
|
Db::parseParam('organizationId', $this->parseOrganizationValue($this->organization)) |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|