1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipboxfactory/craft-integration/blob/master/LICENSE |
6
|
|
|
* @link https://github.com/flipboxfactory/craft-integration/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\craft\integration\queries; |
10
|
|
|
|
11
|
|
|
use craft\helpers\Db; |
12
|
|
|
use yii\db\Expression; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Flipbox Factory <[email protected]> |
16
|
|
|
* @since 2.0.0 |
17
|
|
|
*/ |
18
|
|
|
trait ObjectAttributeTrait |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string|string[]|null |
22
|
|
|
*/ |
23
|
|
|
public $object; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Adds an additional WHERE condition to the existing one. |
27
|
|
|
* The new condition and the existing one will be joined using the `AND` operator. |
28
|
|
|
* @param string|array|Expression $condition the new WHERE condition. Please refer to [[where()]] |
29
|
|
|
* on how to specify this parameter. |
30
|
|
|
* @param array $params the parameters (name => value) to be bound to the query. |
31
|
|
|
* @return $this the query object itself |
32
|
|
|
* @see where() |
33
|
|
|
* @see orWhere() |
34
|
|
|
*/ |
35
|
|
|
abstract public function andWhere($condition, $params = []); |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string|string[]|null $value |
39
|
|
|
* @return static |
40
|
|
|
*/ |
41
|
|
|
public function setObjectId($value) |
42
|
|
|
{ |
43
|
|
|
return $this->setObject($value); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string|string[]|null $value |
48
|
|
|
* @return static |
49
|
|
|
*/ |
50
|
|
|
public function objectId($value) |
51
|
|
|
{ |
52
|
|
|
return $this->setObject($value); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string|string[]|null $value |
57
|
|
|
* @return static |
58
|
|
|
*/ |
59
|
|
|
public function setObject($value) |
60
|
|
|
{ |
61
|
|
|
$this->object = $value; |
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string|string[]|null $value |
67
|
|
|
* @return static |
68
|
|
|
*/ |
69
|
|
|
public function object($value) |
70
|
|
|
{ |
71
|
|
|
return $this->setObject($value); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Apply query specific conditions |
76
|
|
|
*/ |
77
|
|
|
protected function applyObjectConditions() |
78
|
|
|
{ |
79
|
|
|
if ($this->object !== null) { |
80
|
|
|
$this->andWhere(Db::parseParam('objectId', $this->object)); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|