/
SectionIdIn.php
65 lines (60 loc) · 2 KB
/
SectionIdIn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* File containing the SectionId criterion visitor class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor;
use eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher as Dispatcher;
use eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator;
/**
* Visits the SectionId criterion.
*/
class SectionIdIn extends CriterionVisitor
{
/**
* Check if visitor is applicable to current criterion.
*
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
*
* @return bool
*/
public function canVisit(Criterion $criterion)
{
return
$criterion instanceof Criterion\SectionId &&
(
($criterion->operator ?: Operator::IN) === Operator::IN ||
$criterion->operator === Operator::EQ
);
}
/**
* Map field value to a proper Elasticsearch filter representation.
*
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
* @param \eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher $dispatcher
* @param array $languageFilter
*
* @return mixed
*/
public function visitFilter(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter)
{
if (count($criterion->value) > 1) {
$filter = array(
'terms' => array(
'section_id' => $criterion->value,
),
);
} else {
$filter = array(
'term' => array(
'section_id' => $criterion->value[0],
),
);
}
return $filter;
}
}