Completed
Push — master ( e16616...2d6e36 )
by
unknown
19:26 queued 03:33
created

VisibleOnly::getVisibleOnlySubQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 30
rs 9.44
c 0
b 0
f 0
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
namespace eZ\Publish\Core\Persistence\Legacy\URL\Query\CriterionHandler;
8
9
use Doctrine\DBAL\ParameterType;
10
use eZ\Publish\API\Repository\Values\URL\Query\Criterion;
11
use eZ\Publish\Core\Persistence\Database\SelectQuery;
12
use eZ\Publish\Core\Persistence\Legacy\URL\Query\CriteriaConverter;
13
14
class VisibleOnly extends Base
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function accept(Criterion $criterion)
20
    {
21
        return $criterion instanceof Criterion\VisibleOnly;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion)
28
    {
29
        $this->joinContentObjectLink($query);
30
        $this->joinContentObjectAttribute($query);
31
32
        $currentQuery = $query->getQuery();
33
        if (strpos($currentQuery, 'INNER JOIN ezcontentobject_tree') === false) {
34
            $query->innerJoin('ezcontentobject_tree', $query->expr->lAnd(
35
                $query->expr->eq(
36
                    'ezcontentobject_tree.contentobject_id',
37
                    'ezcontentobject_attribute.contentobject_id'
38
                ),
39
                $query->expr->eq(
40
                    'ezcontentobject_tree.contentobject_version',
41
                    'ezcontentobject_attribute.version'
42
                )
43
            ));
44
        }
45
46
        return $query->expr->eq(
47
            'ezcontentobject_tree.is_invisible',
48
            $query->bindValue(0, null, ParameterType::INTEGER)
49
        );
50
    }
51
}
52