Completed
Push — master ( 8386c2...ffd2be )
by Simonas
61:26
created

FieldValue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 6 1
A getState() 0 7 1
A modifySearch() 0 4 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\Filter\Widget\Search;
13
14
use ONGR\ElasticsearchDSL\Filter\TermFilter;
15
use ONGR\ElasticsearchDSL\Query\MatchQuery;
16
use ONGR\ElasticsearchDSL\Query\TermQuery;
17
use ONGR\ElasticsearchDSL\Search;
18
use ONGR\FilterManagerBundle\Filter\FilterState;
19
use ONGR\FilterManagerBundle\Filter\Relation\RelationAwareInterface;
20
use ONGR\FilterManagerBundle\Filter\Relation\RelationAwareTrait;
21
use ONGR\FilterManagerBundle\Search\SearchRequest;
22
use Symfony\Component\HttpFoundation\Request;
23
24
/**
25
 * Filter for filtering on exact value in specified field.
26
 */
27
class FieldValue extends AbstractSingleValue implements RelationAwareInterface
28
{
29
    use RelationAwareTrait;
30
31
    /**
32
     * @var string
33
     */
34
    protected $value;
35
36
    /**
37
     * Setter for field value.
38
     *
39
     * @param $value
40
     *
41
     * @return $this
42
     */
43
    public function setValue($value)
44
    {
45
        $this->value = $value;
46
47
        return $this;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getState(Request $request)
54
    {
55
        $state = new FilterState();
56
        $state->setActive(true);
57
58
        return $state;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null)
65
    {
66
        $search->addPostFilter(new TermQuery($this->getField(), $this->value));
67
    }
68
}
69