Skip to content
This repository has been archived by the owner on Sep 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from aertmann/master
Browse files Browse the repository at this point in the history
A couple improvements to conditions
  • Loading branch information
Bastian Waidelich authored Aug 9, 2017
2 parents 82d1db4 + 1097d59 commit 4421159
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Query\Filter\SQLFilter as DoctrineSqlFilter;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;

/**
Expand Down Expand Up @@ -40,7 +41,9 @@ public function __construct($collectionTitle)
*/
public function getSql(DoctrineSqlFilter $sqlFilter, ClassMetadata $targetEntity, $targetTableAlias)
{
$quotedCollectionTitle = $this->entityManager->getConnection()->quote($this->collectionTitle);
$propertyConditionGenerator = new PropertyConditionGenerator('');
$collectionTitle = $propertyConditionGenerator->getValueForOperand($this->collectionTitle);
$quotedCollectionTitle = $this->entityManager->getConnection()->quote($collectionTitle);
return $targetTableAlias . '.persistence_object_identifier IN (
SELECT ' . $targetTableAlias . '_a.persistence_object_identifier
FROM typo3_media_domain_model_asset AS ' . $targetTableAlias . '_a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,19 @@ public function isTagged($tagLabel)

/**
* @param string $collectionTitle
* @return AssetTagConditionGenerator
* @return AssetAssetCollectionConditionGenerator
*/
public function isInCollection($collectionTitle)
{
return new AssetAssetCollectionConditionGenerator($collectionTitle);
}

/**
* @return AssetWithoutAssetCollectionConditionGenerator
*/
public function isWithoutCollection()
{
return new AssetWithoutAssetCollectionConditionGenerator();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Query\Filter\SQLFilter as DoctrineSqlFilter;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;

/**
Expand Down Expand Up @@ -40,7 +41,9 @@ public function __construct($tagLabel)
*/
public function getSql(DoctrineSqlFilter $sqlFilter, ClassMetadata $targetEntity, $targetTableAlias)
{
$quotedTagLabel = $this->entityManager->getConnection()->quote($this->tagLabel);
$propertyConditionGenerator = new PropertyConditionGenerator('');
$tagLabel = $propertyConditionGenerator->getValueForOperand($this->tagLabel);
$quotedTagLabel = $this->entityManager->getConnection()->quote($tagLabel);
return $targetTableAlias . '.persistence_object_identifier IN (
SELECT ' . $targetTableAlias . '_a.persistence_object_identifier
FROM typo3_media_domain_model_asset AS ' . $targetTableAlias . '_a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace Wwwision\AssetConstraints\Security\Authorization\Privilege\Doctrine;

use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Query\Filter\SQLFilter as DoctrineSqlFilter;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\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 ObjectManager
*/
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 typo3_media_domain_model_asset AS ' . $targetTableAlias . '_a
LEFT JOIN typo3_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;
}
}

0 comments on commit 4421159

Please sign in to comment.