1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/patron/license |
6
|
|
|
* @link https://www.flipboxfactory.com/patron/domains/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\patron\queries; |
10
|
|
|
|
11
|
|
|
use craft\db\QueryAbortedException; |
12
|
|
|
use craft\helpers\Db; |
13
|
|
|
use flipbox\patron\records\Provider; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Flipbox Factory <[email protected]> |
17
|
|
|
* @since 1.0.0 |
18
|
|
|
*/ |
19
|
|
|
trait ProviderAttributesTrait |
20
|
|
|
{ |
21
|
|
|
use ProviderClientAttributesTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var bool|null The enabled state |
25
|
|
|
*/ |
26
|
|
|
public $enabled = true; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int|int[]|false|null The model ID(s). Prefix IDs with "not " to exclude them. |
30
|
|
|
*/ |
31
|
|
|
public $id; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string|string[]|null The provider name(s). Prefix IDs with "not " to exclude them. |
35
|
|
|
*/ |
36
|
|
|
public $name; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string|string[]|null The provider handle(s). Prefix IDs with "not " to exclude them. |
40
|
|
|
*/ |
41
|
|
|
public $handle; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string|string[]|null The provider classes(s). Prefix IDs with "not " to exclude them. |
45
|
|
|
*/ |
46
|
|
|
public $class; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $enabled |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
public function enabled($enabled) |
53
|
|
|
{ |
54
|
|
|
$this->enabled = $enabled; |
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param $id |
60
|
|
|
* @return $this |
61
|
|
|
*/ |
62
|
|
|
public function id($id) |
63
|
|
|
{ |
64
|
|
|
$this->id = $id; |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param $name |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function name($name) |
73
|
|
|
{ |
74
|
|
|
$this->name = $name; |
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param $handle |
80
|
|
|
* @return $this |
81
|
|
|
*/ |
82
|
|
|
public function handle($handle) |
83
|
|
|
{ |
84
|
|
|
$this->handle = $handle; |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param $class |
90
|
|
|
* @return $this |
91
|
|
|
*/ |
92
|
|
|
public function class($class) |
93
|
|
|
{ |
94
|
|
|
$this->class = $class; |
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @throws QueryAbortedException |
100
|
|
|
*/ |
101
|
|
|
protected function applyProviderConditions() |
102
|
|
|
{ |
103
|
|
|
// Is the query already doomed? |
104
|
|
|
if ($this->id !== null && empty($this->id)) { |
105
|
|
|
throw new QueryAbortedException(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ($this->enabled !== null) { |
109
|
|
|
$this->andWhere(Db::parseParam('enabled', $this->enabled)); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$attributes = ['id', 'name', 'handle', 'class']; |
113
|
|
|
|
114
|
|
|
foreach ($attributes as $attribute) { |
115
|
|
|
if (($value = $this->{$attribute}) !== null) { |
116
|
|
|
$this->andWhere(Db::parseParam(Provider::tableAlias() . '.' . $attribute, $value)); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$this->applyClientConditions(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|