Completed
Pull Request — master (#137)
by Mantas
65:39
created

FieldValue::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
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 ONGR\FilterManagerBundle\Filters\Widget\Search;
13
14
use ONGR\ElasticsearchDSL\Filter\TermFilter;
15
use ONGR\ElasticsearchDSL\Query\MatchQuery;
16
use ONGR\ElasticsearchDSL\Search;
17
use ONGR\FilterManagerBundle\Filters\FilterState;
18
use ONGR\FilterManagerBundle\Filters\Relations\RelationsAwareInterface;
19
use ONGR\FilterManagerBundle\Filters\Relations\RelationsAwareTrait;
20
use ONGR\FilterManagerBundle\Search\SearchRequest;
21
use Symfony\Component\HttpFoundation\Request;
22
23
/**
24
 * Filter for filtering on exact value in specified field.
25
 */
26
class FieldValue extends AbstractSingleValue implements RelationsAwareInterface
27
{
28
    use RelationsAwareTrait;
29
30
        /**
31
     * @var string
32
     */
33
    protected $value;
34
35
    /**
36
     * Setter for field value.
37
     *
38
     * @param $value
39
     *
40
     * @return $this
41
     */
42
    public function setValue($value)
43
    {
44
        $this->value = $value;
45
46
        return $this;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getState(Request $request)
53
    {
54
        $state = new FilterState();
55
        $state->setActive(true);
56
57
        return $state;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null)
64
    {
65
        $search->addPostFilter(new TermFilter($this->getField(), $this->value));
66
    }
67
}
68