src/Cms/ModuleBundle/Util/ModuleProxyPlaceholderDoctrineFilter.php line 24

Open in your IDE?
  1. <?php
  2. namespace Cms\ModuleBundle\Util;
  3. use Cms\ModuleBundle\Entity\Proxy;
  4. use Doctrine\ORM\Mapping\ClassMetadata;
  5. use Doctrine\ORM\Query\Filter\SQLFilter;
  6. /**
  7.  * Class ModuleProxyPlaceholderDoctrineFilter
  8.  * @package Cms\ModuleBundle\Util
  9.  */
  10. class ModuleProxyPlaceholderDoctrineFilter extends SQLFilter
  11. {
  12.     const FILTER 'module_proxy_placeholder_filter';
  13.     const MODES__ANY null;
  14.     const MODES__NO_PLACEHOLDERS 0;
  15.     const MODES__ONLY_PLACEHOLDERS 1;
  16.     /**
  17.      * {@inheritdoc}
  18.      */
  19.     public function addFilterConstraint(ClassMetadata $targetEntity$targetTableAlias): string
  20.     {
  21.         // make sure we are in fact an entity that tracks tenant stuff
  22.         if ( ! $targetEntity->getReflectionClass()->isSubclassOf(Proxy::class)) {
  23.             return '';
  24.         }
  25.         // obtain our param
  26.         if ( ! $this->hasParameter('mode')) {
  27.             $this->setParameter('mode'self::MODES__ANY);
  28.         }
  29.         $mode trim($this->getParameter('mode'), '\'');
  30.         // fix the mode, sql filters suck to work with
  31.         if (preg_match('/^[0-9]+$/'strval($mode)) === 1) {
  32.             $mode intval($mode);
  33.         } else {
  34.             $mode null;
  35.         }
  36.         // if in any mode, do nothing
  37.         if ($mode === self::MODES__ANY) {
  38.             return '';
  39.         }
  40.         // calculate the necessary dql to filter this
  41.         return sprintf(
  42.             '%s.placeholder = %s',
  43.             $targetTableAlias,
  44.             $mode
  45.         );
  46.     }
  47. }