|
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\traits; |
|
10
|
|
|
|
|
11
|
|
|
use craft\helpers\Db; |
|
12
|
|
|
use yii\db\Expression; |
|
13
|
|
|
|
|
14
|
|
|
trait Attributes |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string|string[]|false|null The domain(s). Prefix domains with "not " to exclude them. |
|
18
|
|
|
*/ |
|
19
|
|
|
public $domain; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var int|int[]|false|null The element ID(s). Prefix IDs with "not " to exclude them. |
|
23
|
|
|
*/ |
|
24
|
|
|
public $elementId; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var int|int[]|false|null The field ID(s). Prefix IDs with "not " to exclude them. |
|
28
|
|
|
*/ |
|
29
|
|
|
public $fieldId; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Adds an additional WHERE condition to the existing one. |
|
33
|
|
|
* The new condition and the existing one will be joined using the `AND` operator. |
|
34
|
|
|
* @param string|array|Expression $condition the new WHERE condition. Please refer to [[where()]] |
|
35
|
|
|
* on how to specify this parameter. |
|
36
|
|
|
* @param array $params the parameters (name => value) to be bound to the query. |
|
37
|
|
|
* @return $this the query object itself |
|
38
|
|
|
* @see where() |
|
39
|
|
|
* @see orWhere() |
|
40
|
|
|
*/ |
|
41
|
|
|
abstract public function andWhere($condition, $params = []); |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param $value |
|
45
|
|
|
* @return static |
|
46
|
|
|
*/ |
|
47
|
|
|
public function fieldId($value) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->fieldId = $value; |
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param $value |
|
55
|
|
|
* @return static |
|
56
|
|
|
*/ |
|
57
|
|
|
public function field($value) |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->fieldId($value); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param $value |
|
64
|
|
|
* @return static |
|
65
|
|
|
*/ |
|
66
|
|
|
public function elementId($value) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->elementId = $value; |
|
69
|
|
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param $value |
|
74
|
|
|
* @return static |
|
75
|
|
|
*/ |
|
76
|
|
|
public function element($value) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->elementId($value); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param $value |
|
83
|
|
|
* @return static |
|
84
|
|
|
*/ |
|
85
|
|
|
public function domain($value) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->domain = $value; |
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Apply attribute conditions |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function applyConditions() |
|
95
|
|
|
{ |
|
96
|
|
|
if ($this->fieldId !== null) { |
|
97
|
|
|
$this->andWhere(Db::parseParam('fieldId', $this->fieldId)); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if ($this->domain !== null) { |
|
101
|
|
|
$this->andWhere(Db::parseParam('domain', $this->domain)); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
if ($this->elementId !== null) { |
|
105
|
|
|
$this->andWhere(Db::parseParam('elementId', $this->elementId)); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|