src/Products/NotificationsBundle/Util/ListBuilder/SchoolListBuilder.php line 59

Open in your IDE?
  1. <?php
  2. namespace Products\NotificationsBundle\Util\ListBuilder;
  3. use Doctrine\ORM\QueryBuilder;
  4. use Cms\CoreBundle\Util\Doctrine\EntityManager;
  5. use Products\NotificationsBundle\Entity\AbstractList;
  6. use Products\NotificationsBundle\Entity\Lists\SchoolList;
  7. use Products\NotificationsBundle\Service\Query\NotificationsConditionQueryBuilder;
  8. /**
  9.  *
  10.  */
  11. final class SchoolListBuilder extends AbstractListBuilder
  12. {
  13.     private NotificationsConditionQueryBuilder $notificationsConditionQueryBuilder;
  14.     /**
  15.      * @param EntityManager $em
  16.      * @param NotificationsConditionQueryBuilder $notificationsConditionQueryBuilder
  17.      * @param AbstractList|null $list
  18.      */
  19.     public function __construct(
  20.         EntityManager $em,
  21.         NotificationsConditionQueryBuilder $notificationsConditionQueryBuilder,
  22.         ?AbstractList $list
  23.     )
  24.     {
  25.         parent::__construct($em$list);
  26.         $this->notificationsConditionQueryBuilder $notificationsConditionQueryBuilder;
  27.     }
  28.     /**
  29.      * {@inheritDoc}
  30.      * @return SchoolList
  31.      */
  32.     public function getList(): AbstractList
  33.     {
  34.         $list parent::getList();
  35.         if ( ! $list instanceof SchoolList) {
  36.             throw new \LogicException();
  37.         }
  38.         return $list;
  39.     }
  40.     /**
  41.      * {@inheritDoc}
  42.      */
  43.     public static function supports($list): bool
  44.     {
  45.         return ($list === SchoolList::class || $list instanceof SchoolList);
  46.     }
  47.     /**
  48.      * {@inheritDoc}
  49.      */
  50.     public function build(): QueryBuilder
  51.     {
  52.         return $this->notificationsConditionQueryBuilder->build(
  53.             $this->getList()->getConditionQuery()
  54.                 ->setConditionConfig($this->getConfig())
  55.                 ->setConditionContext($this->getList()),
  56.             $this->identify(),
  57.         );
  58.     }
  59.     /**
  60.      * {@inheritDoc}
  61.      */
  62.     public function serialize(?AbstractList $list null): array
  63.     {
  64.         $list $list ?: $this->getList();
  65.         if ( ! $list instanceof SchoolList) {
  66.             throw new \Exception();
  67.         }
  68.         return [
  69.             'types' => $list->getTypes(),
  70.             'school' => $list->getOneRosterId(),
  71.         ];
  72.     }
  73.     /**
  74.      * {@inheritDoc}
  75.      * @return SchoolList
  76.      */
  77.     public function unserialize(array $serialized): SchoolList
  78.     {
  79.         return (new SchoolList())
  80.             ->setTypes($serialized['types'])
  81.             ->setOneRosterId($serialized['school']);
  82.     }
  83. }