src/Products/NotificationsBundle/Util/ListBuilder/DistrictListBuilder.php line 61

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\DistrictList;
  7. use Products\NotificationsBundle\Service\Query\NotificationsConditionQueryBuilder;
  8. /**
  9.  *
  10.  */
  11. final class DistrictListBuilder 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 DistrictList
  31.      */
  32.     public function getList(): AbstractList
  33.     {
  34.         $list parent::getList();
  35.         if ( ! $list instanceof DistrictList) {
  36.             throw new \LogicException();
  37.         }
  38.         return $list;
  39.     }
  40.     /**
  41.      * {@inheritDoc}
  42.      */
  43.     public static function supports($list): bool
  44.     {
  45.         return ($list === DistrictList::class || $list instanceof DistrictList);
  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 DistrictList) {
  66.             throw new \Exception();
  67.         }
  68.         return [
  69.             'types' => $list->getTypes(),
  70.             'district' => $list->getOneRosterId(),
  71.         ];
  72.     }
  73.     /**
  74.      * {@inheritDoc}
  75.      * @return DistrictList
  76.      */
  77.     public function unserialize(array $serialized): DistrictList
  78.     {
  79.         return (new DistrictList())
  80.             ->setTypes($serialized['types'])
  81.             ->setOneRosterId($serialized['district']);
  82.     }
  83. }