/
AssetWithoutAssetCollectionConditionGenerator.php
48 lines (43 loc) · 1.86 KB
/
AssetWithoutAssetCollectionConditionGenerator.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
<?php
namespace Neos\Media\Security\Authorization\Privilege\Doctrine;
/*
* This file is part of the Neos.Media package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\Filter\SQLFilter as DoctrineSqlFilter;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;
/**
* Condition generator covering Asset >-< AssetCollection relations (M:M relations are not supported by the Flow
* PropertyConditionGenerator yet)
*/
class AssetWithoutAssetCollectionConditionGenerator implements SqlGeneratorInterface
{
/**
* @Flow\Inject
* @var EntityManagerInterface
*/
protected $entityManager;
/**
* @param DoctrineSqlFilter $sqlFilter
* @param ClassMetadata $targetEntity Metadata object for the target entity to create the constraint for
* @param string $targetTableAlias The target table alias used in the current query
* @return string
*/
public function getSql(DoctrineSqlFilter $sqlFilter, ClassMetadata $targetEntity, $targetTableAlias)
{
$sql = $targetTableAlias . '.persistence_object_identifier IN (
SELECT ' . $targetTableAlias . '_a.persistence_object_identifier
FROM neos_media_domain_model_asset AS ' . $targetTableAlias . '_a
LEFT JOIN neos_media_domain_model_assetcollection_assets_join ' . $targetTableAlias . '_acj ON ' . $targetTableAlias . '_a.persistence_object_identifier = ' . $targetTableAlias . '_acj.media_asset
WHERE ' . $targetTableAlias . '_acj.media_asset IS NULL)';
return $sql;
}
}