|
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 eZ\Publish\API\Repository\Values\URL\Query\Criterion; |
|
10
|
|
|
use eZ\Publish\Core\Persistence\Legacy\URL\Query\CriteriaConverter; |
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\URL\Query\CriterionHandler; |
|
12
|
|
|
use eZ\Publish\Core\Persistence\Database\SelectQuery; |
|
13
|
|
|
use PDO; |
|
14
|
|
|
|
|
15
|
|
|
class VisibleOnly implements CriterionHandler |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public function accept(Criterion $criterion) |
|
21
|
|
|
{ |
|
22
|
|
|
return $criterion instanceof Criterion\VisibleOnly; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion) |
|
29
|
|
|
{ |
|
30
|
|
|
return $query->expr->in('ezurl.id', $this->getVisibleOnlySubQuery($query)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Generate query that selects ids of visible URLs. |
|
35
|
|
|
* |
|
36
|
|
|
* @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query |
|
37
|
|
|
* @return \eZ\Publish\Core\Persistence\Database\SelectQuery |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function getVisibleOnlySubQuery(SelectQuery $query) |
|
40
|
|
|
{ |
|
41
|
|
|
// TODO: The following query requires optimization |
|
42
|
|
|
$subSelect = $query->subSelect(); |
|
43
|
|
|
$subSelect |
|
44
|
|
|
->selectDistinct('ezurl_object_link.url_id') |
|
45
|
|
|
->from('ezurl_object_link') |
|
46
|
|
|
->innerJoin( |
|
47
|
|
|
'ezcontentobject_attribute', |
|
48
|
|
|
$query->expr->lAnd( |
|
49
|
|
|
$query->expr->eq('ezurl_object_link.contentobject_attribute_id', 'ezcontentobject_attribute.id'), |
|
50
|
|
|
$query->expr->eq('ezurl_object_link.contentobject_attribute_version', 'ezcontentobject_attribute.version') |
|
51
|
|
|
) |
|
52
|
|
|
) |
|
53
|
|
|
->innerJoin( |
|
54
|
|
|
'ezcontentobject_tree', |
|
55
|
|
|
$query->expr->lAnd( |
|
56
|
|
|
$query->expr->eq('ezcontentobject_tree.contentobject_id', 'ezcontentobject_attribute.contentobject_id'), |
|
57
|
|
|
$query->expr->eq('ezcontentobject_tree.contentobject_version', 'ezcontentobject_attribute.version') |
|
58
|
|
|
) |
|
59
|
|
|
) |
|
60
|
|
|
->where( |
|
61
|
|
|
$query->expr->eq( |
|
62
|
|
|
'ezcontentobject_tree.is_invisible', |
|
63
|
|
|
$query->bindValue(0, null, PDO::PARAM_INT) |
|
64
|
|
|
) |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
return $subSelect; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|