1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Objects; |
4
|
|
|
|
5
|
|
|
use Mado\QueryBundle\Objects\Operator; |
6
|
|
|
use Mado\QueryBundle\Objects\Salt; |
7
|
|
|
|
8
|
|
|
class WhereCondition |
9
|
|
|
{ |
10
|
|
|
private $entityAlias; |
11
|
|
|
|
12
|
|
|
private $operator; |
13
|
|
|
|
14
|
|
|
private $salt; |
15
|
|
|
|
16
|
|
|
private $filtering; |
17
|
|
|
|
18
|
|
|
private $value; |
19
|
|
|
|
20
|
|
|
private $fieldName; |
21
|
|
|
|
22
|
|
|
private $relationEntityAlias; |
23
|
|
|
|
24
|
4 |
|
public function setEntityAlias(string $entityAlias) |
25
|
|
|
{ |
26
|
4 |
|
$this->entityAlias = $entityAlias; |
27
|
4 |
|
} |
28
|
|
|
|
29
|
5 |
|
public function setOperator(Operator $operator) |
30
|
|
|
{ |
31
|
5 |
|
$this->operator = $operator; |
32
|
5 |
|
} |
33
|
|
|
|
34
|
5 |
|
public function setSalt(Salt $salt) |
35
|
|
|
{ |
36
|
5 |
|
$this->salt = $salt; |
37
|
5 |
|
} |
38
|
|
|
|
39
|
5 |
|
public function setFiltering(FilteringObject $filtering) |
40
|
|
|
{ |
41
|
5 |
|
$this->filtering = $filtering; |
42
|
5 |
|
} |
43
|
|
|
|
44
|
3 |
|
public function setValue(string $value) |
45
|
|
|
{ |
46
|
3 |
|
$this->value = $value; |
47
|
3 |
|
} |
48
|
|
|
|
49
|
5 |
|
public function setFieldName(string $fieldName) |
50
|
|
|
{ |
51
|
5 |
|
$this->fieldName = $fieldName; |
52
|
5 |
|
} |
53
|
|
|
|
54
|
4 |
|
private function isListOperator() |
55
|
|
|
{ |
56
|
4 |
|
return $this->filtering->isListOperator(); |
57
|
|
|
} |
58
|
|
|
|
59
|
4 |
|
public function getCondition() : string |
60
|
|
|
{ |
61
|
4 |
|
if ($this->filtering->hasOperator()) { |
62
|
3 |
|
if ($this->isListOperator()) { |
63
|
1 |
|
return $this->entityAlias . '.' . $this->fieldName . ' ' . |
64
|
1 |
|
$this->operator->getMeta() . ' ' . |
65
|
1 |
|
$this->getListFieldName(); |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
if ($this->filtering->isFieldEqualsOperator()) { |
69
|
1 |
|
return $this->entityAlias . '.' . $this->fieldName . ' ' . |
70
|
1 |
|
$this->operator->getMeta() . ' ' . |
71
|
1 |
|
$this->entityAlias . '.' . $this->value; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
2 |
|
return $this->entityAlias . '.' . $this->fieldName . ' ' . |
76
|
2 |
|
$this->operator->getMeta() . ' ' . |
77
|
2 |
|
$this->getFieldName(); |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
public function setRelationEntityAlias(string $relationEntityAlias) |
81
|
|
|
{ |
82
|
1 |
|
$this->relationEntityAlias = $relationEntityAlias; |
83
|
1 |
|
} |
84
|
|
|
|
85
|
1 |
|
public function getEmbeddedCondition() : string |
86
|
|
|
{ |
87
|
1 |
|
$fieldName = $this->isListOperator() |
88
|
1 |
|
? $this->getListFieldName() |
89
|
1 |
|
: $this->getFieldName(); |
90
|
|
|
|
91
|
1 |
|
return $this->relationEntityAlias . '.' . $this->fieldName . |
92
|
1 |
|
' ' . $this->operator->getMeta() . |
93
|
1 |
|
' ' . $fieldName; |
94
|
|
|
} |
95
|
|
|
|
96
|
4 |
|
private function getFieldName() : string |
97
|
|
|
{ |
98
|
4 |
|
return ':field_' . $this->fieldName . $this->salt->getSalt(); |
99
|
|
|
} |
100
|
|
|
|
101
|
2 |
|
private function getListFieldName() : string |
102
|
|
|
{ |
103
|
2 |
|
return '(' . $this->getFieldName() . ')'; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|