Completed
Push — master ( f9a038...cc9983 )
by Kamil
22:34
created

ExpressionBuilder::comparison()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
13
14
use Sylius\Component\Grid\Data\ExpressionBuilderInterface;
15
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
16
use Doctrine\Common\Collections\ExpressionBuilder as CollectionsExpressionBuilder;
17
use Sylius\Bundle\GridBundle\Doctrine\PHPCRODM\ExtraComparison;
18
use Doctrine\Common\Collections\Expr\Comparison;
19
20
/**
21
 * Creates an object graph (using Doctrine\Commons\Collections\Expr\*) which we
22
 * can then walk in order to build up the PHPCR-ODM query builder.
23
 */
24
class ExpressionBuilder implements ExpressionBuilderInterface
25
{
26
    /**
27
     * @var CollectionsExpressionBuilder
28
     */
29
    private $expressionBuilder;
30
31
    /**
32
     * @var array
33
     */
34
    private $orderBys = [];
35
36
    public function __construct(CollectionsExpressionBuilder $expressionBuilder = null)
37
    {
38
        $this->expressionBuilder = $expressionBuilder ?: new CollectionsExpressionBuilder();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function andX($expressions)
45
    {
46
        return $this->expressionBuilder->andX($expressions);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function orX($expressions)
53
    {
54
        return $this->expressionBuilder->orX($expressions);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function comparison($field, $operator, $value)
61
    {
62
        throw new \BadMethodCallException('Not supported yet.');
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function equals($field, $value)
69
    {
70
        return $this->expressionBuilder->eq($field, $value);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function notEquals($field, $value)
77
    {
78
        return $this->expressionBuilder->neq($field, $value);
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function lessThan($field, $value)
85
    {
86
        return $this->expressionBuilder->lt($field, $value);
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function lessThanOrEqual($field, $value)
93
    {
94
        return $this->expressionBuilder->lte($field, $value);
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function greaterThan($field, $value)
101
    {
102
        return $this->expressionBuilder->gt($field, $value);
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function greaterThanOrEqual($field, $value)
109
    {
110
        return $this->expressionBuilder->gte($field, $value);
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function in($field, array $values)
117
    {
118
        return $this->expressionBuilder->in($field, $values);
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124
    public function notIn($field, array $values)
125
    {
126
        return $this->expressionBuilder->notIn($field, $values);
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132
    public function isNull($field)
133
    {
134
        return new Comparison($field, ExtraComparison::IS_NULL, null);
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140
    public function isNotNull($field)
141
    {
142
        return new Comparison($field, ExtraComparison::IS_NOT_NULL, null);
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148
    public function like($field, $pattern)
149
    {
150
        return $this->expressionBuilder->contains($field, $pattern);
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156
    public function notLike($field, $pattern)
157
    {
158
        return new Comparison($field, ExtraComparison::NOT_CONTAINS, $pattern);
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     */
164
    public function orderBy($field, $direction)
165
    {
166
        $this->orderBys = [ $field => $direction ];
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172
    public function addOrderBy($field, $direction)
173
    {
174
        $this->orderBys[$field] = $direction;
175
    }
176
177
    /**
178
     * {@inheritdoc}
179
     */
180
    public function getOrderBys()
181
    {
182
        return $this->orderBys;
183
    }
184
}
185