|
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\Query\TermQuery; |
|
15
|
|
|
use ONGR\ElasticsearchDSL\Search; |
|
16
|
|
|
use ONGR\FilterManagerBundle\Filter\FilterState; |
|
17
|
|
|
use ONGR\FilterManagerBundle\Filter\Relation\RelationAwareInterface; |
|
18
|
|
|
use ONGR\FilterManagerBundle\Filter\Relation\RelationAwareTrait; |
|
19
|
|
|
use ONGR\FilterManagerBundle\Search\SearchRequest; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Filter for filtering on exact value in specified field. |
|
24
|
|
|
*/ |
|
25
|
|
|
class DocumentValue extends AbstractSingleValue |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @return string |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getValue() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->getOption('value', null); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getField() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->getOption('field', null); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getState(Request $request) |
|
47
|
|
|
{ |
|
48
|
|
|
$state = new FilterState(); |
|
49
|
|
|
$document = $request->get('document'); |
|
50
|
|
|
|
|
51
|
|
|
if ($document) { |
|
52
|
|
|
$this->addOption('value', $document->{$this->getDocumentField()}); |
|
53
|
|
|
$state->setActive(true); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $state; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) |
|
63
|
|
|
{ |
|
64
|
|
|
$search->addPostFilter(new TermQuery($this->getField(), $this->getValue())); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|