|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://www.flipboxfactory.com/software/element-lists/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/element-lists/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\meta\db\traits; |
|
10
|
|
|
|
|
11
|
|
|
use craft\helpers\Db; |
|
12
|
|
|
use yii\base\Exception; |
|
13
|
|
|
use yii\db\Expression; |
|
14
|
|
|
use yii\db\QueryInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Flipbox Factory <[email protected]> |
|
18
|
|
|
* @since 1.0.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
trait Attributes |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var int|int[]|false|null The field ID(s). Prefix IDs with "not " to exclude them. |
|
24
|
|
|
*/ |
|
25
|
|
|
public $fieldId; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var int|int[]|false|null The owner Id(s). Prefix Ids with "not " to exclude them. |
|
29
|
|
|
*/ |
|
30
|
|
|
public $ownerId; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var int|int[]|false|null The owner site ID(s). Prefix IDs with "not " to exclude them. |
|
34
|
|
|
*/ |
|
35
|
|
|
public $ownerSiteId; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Adds an additional WHERE condition to the existing one. |
|
39
|
|
|
* The new condition and the existing one will be joined using the `AND` operator. |
|
40
|
|
|
* @param string|array|Expression $condition the new WHERE condition. Please refer to [[where()]] |
|
41
|
|
|
* on how to specify this parameter. |
|
42
|
|
|
* @param array $params the parameters (name => value) to be bound to the query. |
|
43
|
|
|
* @return $this the query object itself |
|
44
|
|
|
* @see where() |
|
45
|
|
|
* @see orWhere() |
|
46
|
|
|
*/ |
|
47
|
|
|
abstract public function andWhere($condition, $params = []); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param $value |
|
51
|
|
|
* @return static |
|
52
|
|
|
*/ |
|
53
|
|
|
public function fieldId($value) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->fieldId = $value; |
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param $value |
|
61
|
|
|
* @return static |
|
62
|
|
|
*/ |
|
63
|
|
|
public function field($value) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->fieldId($value); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @inheritdoc |
|
70
|
|
|
* @throws Exception if $value is an invalid site handle |
|
71
|
|
|
* return static |
|
72
|
|
|
*/ |
|
73
|
|
|
public function owner($value) |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->ownerId($value); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @inheritdoc |
|
80
|
|
|
* return static |
|
81
|
|
|
*/ |
|
82
|
|
|
public function ownerId($value) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->ownerId = $value; |
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @inheritdoc |
|
90
|
|
|
* return static |
|
91
|
|
|
*/ |
|
92
|
|
|
public function ownerSite($value) |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->ownerSiteId($value); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @inheritdoc |
|
99
|
|
|
* return static |
|
100
|
|
|
*/ |
|
101
|
|
|
public function ownerSiteId($value) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->ownerSiteId = $value; |
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param QueryInterface $query |
|
109
|
|
|
*/ |
|
110
|
|
|
protected function applyConditions(QueryInterface $query) |
|
111
|
|
|
{ |
|
112
|
|
|
if ($this->fieldId !== null) { |
|
113
|
|
|
$query->andWhere(Db::parseParam('fieldId', $this->fieldId)); |
|
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
if ($this->ownerId !== null) { |
|
117
|
|
|
$query->andWhere(Db::parseParam('ownerId', $this->ownerId)); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
if ($this->ownerSiteId !== null) { |
|
121
|
|
|
$query->andWhere(Db::parseParam('ownerSiteId', $this->ownerSiteId)); |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
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.