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\Decorator\Operator; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderDecoratorInterface; |
15
|
|
|
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderEnumerator; |
16
|
|
|
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderOperatorInterface; |
17
|
|
|
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderRuleInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Abstract QueryBuilder operator. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\JQuery\QueryBuilderBundle\Decorator\Operator |
24
|
|
|
* @abstract |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractQueryBuilderOperator implements QueryBuilderDecoratorInterface, QueryBuilderOperatorInterface { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Operator. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $operator; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor. |
37
|
|
|
* |
38
|
|
|
* @param string $operator The operator. |
39
|
|
|
*/ |
40
|
|
|
protected function __construct($operator) { |
41
|
|
|
$this->setOperator($operator); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the operator. |
46
|
|
|
* |
47
|
|
|
* @return string Returns the operator. |
48
|
|
|
*/ |
49
|
|
|
public function getOperator() { |
50
|
|
|
return $this->operator; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Set the operator. |
55
|
|
|
* |
56
|
|
|
* @param string $operator The operator |
57
|
|
|
* @return AbstractQueryBuilderOperator Returns this operator. |
58
|
|
|
*/ |
59
|
|
|
protected function setOperator($operator) { |
60
|
|
|
$this->operator = $operator; |
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
|
|
public function toSQL(QueryBuilderRuleInterface $rule, $wrap = false) { |
68
|
|
|
$sql = [ |
69
|
|
|
$rule->getField(), |
70
|
|
|
QueryBuilderEnumerator::enumOperators()[$this->getOperator()], |
71
|
|
|
]; |
72
|
|
|
return implode(" ", $sql); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|