src/Doctrine/Filter/SatisfactionSurveyFilter.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Doctrine\Filter;
  3. use App\Annotation\SatisfactionSurveyAware;
  4. use Doctrine\Common\Annotations\Reader;
  5. use Doctrine\ORM\Mapping\ClassMetadata;
  6. use Doctrine\ORM\Query\Filter\SQLFilter;
  7. use InvalidArgumentException;
  8. class SatisfactionSurveyFilter extends SQLFilter
  9. {
  10.     private Reader $reader;
  11.     public function addFilterConstraint(ClassMetadata $targetEntity$targetTableAlias): string
  12.     {
  13.         if (empty($this->reader)) {
  14.             return '';
  15.         }
  16.         $satisfactionSurveyAware $this->reader->getClassAnnotation(
  17.             $targetEntity->getReflectionClass(),
  18.             SatisfactionSurveyAware::class
  19.         );
  20.         if (!$satisfactionSurveyAware) {
  21.             return '';
  22.         }
  23.         $fieldName $satisfactionSurveyAware->satisfactionSurveyFieldName;
  24.         try {
  25.             $survey $this->getParameter('survey');
  26.         } catch (InvalidArgumentException $e) {
  27.             return '';
  28.         }
  29.         if (empty($fieldName) || empty($survey)) {
  30.             return '';
  31.         }
  32.         return sprintf('%s.%s = %s'$targetTableAlias$fieldName$survey);
  33.     }
  34.     public function setAnnotationReader(Reader $reader): void
  35.     {
  36.         $this->reader $reader;
  37.     }
  38. }