|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the jquery-querybuilder-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2019 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\JQuery\QueryBuilderBundle\API; |
|
13
|
|
|
|
|
14
|
|
|
use UnexpectedValueException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* QueryBuilder rule set. |
|
18
|
|
|
* |
|
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
20
|
|
|
* @package WBW\Bundle\JQuery\QueryBuilderBundle\API |
|
21
|
|
|
*/ |
|
22
|
|
|
class QueryBuilderRuleSet implements QueryBuilderConditionInterface, QueryBuilderRuleSetInterface { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Condition. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $condition; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Filter set. |
|
33
|
|
|
* |
|
34
|
|
|
* @var QueryBuilderFilterSetInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $filterSet; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Rules. |
|
40
|
|
|
* |
|
41
|
|
|
* @var array |
|
42
|
|
|
*/ |
|
43
|
|
|
private $rules; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Valid. |
|
47
|
|
|
* |
|
48
|
|
|
* @var bool |
|
49
|
|
|
*/ |
|
50
|
|
|
private $valid; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Constructor. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct() { |
|
56
|
|
|
$this->setRules([]); |
|
57
|
|
|
$this->setValid(false); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Add a rule. |
|
62
|
|
|
* |
|
63
|
|
|
* @param QueryBuilderRuleInterface $rule The rule. |
|
64
|
|
|
* @return QueryBuilderRuleSetInterface Returns this rule set. |
|
65
|
|
|
*/ |
|
66
|
|
|
public function addRule(QueryBuilderRuleInterface $rule) { |
|
67
|
|
|
$this->rules[] = $rule; |
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Add a rule set. |
|
73
|
|
|
* |
|
74
|
|
|
* @param QueryBuilderRuleSetInterface $rule The rule. |
|
75
|
|
|
* @return QueryBuilderRuleSetInterface Returns this rule set. |
|
76
|
|
|
*/ |
|
77
|
|
|
public function addRuleSet(QueryBuilderRuleSetInterface $rule) { |
|
78
|
|
|
$this->rules[] = $rule; |
|
79
|
|
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get the condition. |
|
84
|
|
|
* |
|
85
|
|
|
* @return string Returns the condition. |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getCondition() { |
|
88
|
|
|
return $this->condition; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get the filter set. |
|
93
|
|
|
* |
|
94
|
|
|
* @return QueryBuilderFilterSetInterface Returns the filter set. |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getFilterSet() { |
|
97
|
|
|
return $this->filterSet; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get the rules. |
|
102
|
|
|
* |
|
103
|
|
|
* @return array Returns the rules. |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getRules() { |
|
106
|
|
|
return $this->rules; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Get the valid. |
|
111
|
|
|
* |
|
112
|
|
|
* @return bool Returns the valid. |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getValid() { |
|
115
|
|
|
return $this->valid; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Set the condition. |
|
120
|
|
|
* |
|
121
|
|
|
* @param string $condition The condition. |
|
122
|
|
|
* @return QueryBuilderRuleSetInterface Returns this rule set. |
|
123
|
|
|
* @throws UnexpectedValueException Throws an unexpected value exception if the condition is invalid. |
|
124
|
|
|
*/ |
|
125
|
|
|
public function setCondition($condition) { |
|
126
|
|
|
if (null !== $condition && false === in_array($condition, QueryBuilderEnumerator::enumConditions())) { |
|
127
|
|
|
throw new UnexpectedValueException(sprintf("The condition \"%s\" is invalid", $condition)); |
|
128
|
|
|
} |
|
129
|
|
|
$this->condition = $condition; |
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Set the filter set. |
|
135
|
|
|
* |
|
136
|
|
|
* @param QueryBuilderFilterSetInterface $filterSet The filter set. |
|
137
|
|
|
* @return QueryBuilderRuleSet Returns this rule set. |
|
138
|
|
|
*/ |
|
139
|
|
|
protected function setFilterSet(QueryBuilderFilterSetInterface $filterSet) { |
|
140
|
|
|
$this->filterSet = $filterSet; |
|
141
|
|
|
return $this; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Set the rules. |
|
146
|
|
|
* |
|
147
|
|
|
* @param array $rules The rules. |
|
148
|
|
|
* @return QueryBuilderRuleSet Returns this rule set. |
|
149
|
|
|
*/ |
|
150
|
|
|
protected function setRules(array $rules) { |
|
151
|
|
|
$this->rules = $rules; |
|
152
|
|
|
return $this; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Set the valid. |
|
157
|
|
|
* |
|
158
|
|
|
* @param bool $valid The valid. |
|
159
|
|
|
* @return QueryBuilderRuleSetInterface Returns this rule set. |
|
160
|
|
|
*/ |
|
161
|
|
|
public function setValid($valid) { |
|
162
|
|
|
$this->valid = $valid; |
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|