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

IsUserBased   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 33
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
A handle() 0 25 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 IsUserBased extends CriterionHandler
17
{
18
    public function accept(Criterion $criterion): bool
19
    {
20
        return $criterion instanceof Criterion\IsUserBased;
21
    }
22
23
    public function handle(
24
        CriteriaConverter $converter,
25
        SelectQuery $query,
26
        Criterion $criterion,
27
        array $languageSettings
28
    ) {
29
        $isUserBased = (bool) reset($criterion->value);
30
31
        $subSelect = $query->subSelect();
32
        $subSelect
33
            ->select(
34
                $this->dbHandler->quoteColumn('contentobject_id')
35
            )->from(
36
                $this->dbHandler->quoteTable('ezuser')
37
            );
38
39
        $queryExpression = $query->expr->in(
40
            $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
41
            $subSelect
42
        );
43
44
        return $isUserBased
45
            ? $queryExpression
46
            : $query->expr->not($queryExpression);
47
    }
48
}
49