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\organizations\records\UserTypeAssociation; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Flipbox Factory <[email protected]> |
18
|
|
|
* @since 1.0.0 |
19
|
|
|
* |
20
|
|
|
* @method UserTypeAssociation one($db = null) |
21
|
|
|
* @method UserTypeAssociation[] all($db = null) |
22
|
|
|
* @method UserTypeAssociation[] getCachedResult($db = null) |
23
|
|
|
*/ |
24
|
|
|
class UserTypeAssociationQuery extends ActiveQuery |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var int|int[]|false|null The user Id(s). Prefix Ids with "not " to exclude them. |
28
|
|
|
*/ |
29
|
|
|
public $userId; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int|int[]|false|null The type Id(s). Prefix Ids with "not " to exclude them. |
33
|
|
|
*/ |
34
|
|
|
public $typeId; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritdoc |
38
|
|
|
* return static |
39
|
|
|
*/ |
40
|
|
|
public function type($value) |
41
|
|
|
{ |
42
|
|
|
return $this->typeId($value); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritdoc |
47
|
|
|
* return static |
48
|
|
|
*/ |
49
|
|
|
public function typeId($value) |
50
|
|
|
{ |
51
|
|
|
$this->typeId = $value; |
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritdoc |
57
|
|
|
* return static |
58
|
|
|
*/ |
59
|
|
|
public function user($value) |
60
|
|
|
{ |
61
|
|
|
return $this->userId($value); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritdoc |
66
|
|
|
* return static |
67
|
|
|
*/ |
68
|
|
|
public function userId($value) |
69
|
|
|
{ |
70
|
|
|
$this->userId = $value; |
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @inheritdoc |
76
|
|
|
* @throws QueryAbortedException |
77
|
|
|
*/ |
78
|
|
|
public function prepare($builder) |
79
|
|
|
{ |
80
|
|
|
// Is the query already doomed? |
81
|
|
|
if ($this->userId !== null && empty($this->userId)) { |
82
|
|
|
throw new QueryAbortedException(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->applyUserParam(); |
86
|
|
|
$this->applyTypeParam(); |
87
|
|
|
|
88
|
|
|
return parent::prepare($builder); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return void |
93
|
|
|
* @throws QueryAbortedException |
94
|
|
|
*/ |
95
|
|
|
protected function applyUserParam() |
96
|
|
|
{ |
97
|
|
|
// Is the query already doomed? |
98
|
|
|
if ($this->userId !== null && empty($this->userId)) { |
99
|
|
|
throw new QueryAbortedException(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if (empty($this->userId)) { |
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->andWhere( |
107
|
|
|
Db::parseParam('userId', $this->userId) |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return void |
113
|
|
|
* @throws QueryAbortedException |
114
|
|
|
*/ |
115
|
|
|
protected function applyTypeParam() |
116
|
|
|
{ |
117
|
|
|
// Is the query already doomed? |
118
|
|
|
if ($this->typeId !== null && empty($this->typeId)) { |
119
|
|
|
throw new QueryAbortedException(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if (empty($this->typeId)) { |
123
|
|
|
return; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$this->andWhere( |
127
|
|
|
Db::parseParam('typeId', $this->typeId) |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|