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\base\FieldInterface; |
12
|
|
|
use craft\helpers\Db; |
13
|
|
|
use yii\db\Expression; |
14
|
|
|
|
15
|
|
|
trait FieldAttribute |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[] |
19
|
|
|
*/ |
20
|
|
|
public $field; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Adds an additional WHERE condition to the existing one. |
24
|
|
|
* The new condition and the existing one will be joined using the `AND` operator. |
25
|
|
|
* @param string|array|Expression $condition the new WHERE condition. Please refer to [[where()]] |
26
|
|
|
* on how to specify this parameter. |
27
|
|
|
* @param array $params the parameters (name => value) to be bound to the query. |
28
|
|
|
* @return $this the query object itself |
29
|
|
|
* @see where() |
30
|
|
|
* @see orWhere() |
31
|
|
|
*/ |
32
|
|
|
abstract public function andWhere($condition, $params = []); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[] $value |
36
|
|
|
* @return static |
37
|
|
|
*/ |
38
|
|
|
public function setField($value) |
39
|
|
|
{ |
40
|
|
|
$this->field = $value; |
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[] $value |
46
|
|
|
* @return static |
47
|
|
|
*/ |
48
|
|
|
public function field($value) |
49
|
|
|
{ |
50
|
|
|
return $this->setField($value); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[] $value |
55
|
|
|
* @return static |
56
|
|
|
*/ |
57
|
|
|
public function fieldId($value) |
58
|
|
|
{ |
59
|
|
|
return $this->setField($value); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[] $value |
64
|
|
|
* @return static |
65
|
|
|
*/ |
66
|
|
|
public function setFieldId($value) |
67
|
|
|
{ |
68
|
|
|
return $this->setField($value); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Apply query specific conditions |
73
|
|
|
*/ |
74
|
|
|
protected function applyFieldConditions() |
75
|
|
|
{ |
76
|
|
|
if ($this->field !== null) { |
77
|
|
|
$this->andWhere(Db::parseParam('fieldId', $this->field)); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|