Completed
Push — master ( e36c6b...c46352 )
by Łukasz
14:01
created

ObjectStateIdentifier   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A accept() 0 4 1
B handle() 0 55 2
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler;
10
11
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler;
12
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
13
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
14
use eZ\Publish\Core\Persistence\Database\SelectQuery;
15
16
class ObjectStateIdentifier extends CriterionHandler
17
{
18
    public function accept(Criterion $criterion): bool
19
    {
20
        return $criterion instanceof Criterion\ObjectStateIdentifier;
21
    }
22
23
    public function handle(
24
        CriteriaConverter $converter,
25
        SelectQuery $query,
26
        Criterion $criterion,
27
        array $languageSettings
28
    ) {
29
        $matchStateIdentifier = $query->expr->in(
30
            $this->dbHandler->quoteColumn('identifier', 't2'),
31
            $criterion->value
32
        );
33
34
        $subSelect = $query->subSelect();
35
        $subSelect
36
            ->select(
37
                $this->dbHandler->quoteColumn('contentobject_id', 't1')
38
            )->from(
39
                $query->alias(
40
                    $this->dbHandler->quoteTable('ezcobj_state_link'),
41
                    't1'
42
                )
43
            )->leftJoin(
44
                $query->alias(
45
                    $this->dbHandler->quoteTable('ezcobj_state'),
46
                    't2'
47
                ),
48
                $query->expr->eq(
49
                    $this->dbHandler->quoteColumn('contentobject_state_id', 't1'),
50
                    $this->dbHandler->quoteColumn('id', 't2')
51
                )
52
            )->leftJoin(
53
                $query->alias(
54
                    $this->dbHandler->quoteTable('ezcobj_state_group'),
55
                    't3'
56
                ),
57
                $query->expr->eq(
58
                    $this->dbHandler->quoteColumn('group_id', 't2'),
59
                    $this->dbHandler->quoteColumn('id', 't3')
60
                )
61
            )->where(
62
                null !== $criterion->target
63
                    ? $query->expr->lAnd(
64
                            $query->expr->in(
65
                                $this->dbHandler->quoteColumn('identifier', 't3'),
66
                                $criterion->target
67
                            ),
68
                            $matchStateIdentifier
69
                        )
70
                    : $matchStateIdentifier
71
        );
72
73
        return $query->expr->in(
74
            $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
75
            $subSelect
76
        );
77
    }
78
}
79