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