src/EventSubscriber/ProfileListOrderingSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-05-06
  5.  * Time: 15:27
  6.  */
  7. namespace App\EventSubscriber;
  8. use App\Entity\Location\City;
  9. use App\Service\ProfilePaidPlacementRotator;
  10. use Carbon\CarbonImmutable;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. /**
  15.  * @deprecated
  16.  */
  17. class ProfileListOrderingSubscriber implements EventSubscriberInterface
  18. {
  19.     public function __construct(
  20.         protected ProfilePaidPlacementRotator $paidPlacementRotator
  21.     ) {}
  22.     public function generateListingOrder(ControllerArgumentsEvent $event): void
  23.     {
  24.         return; // turn off deprecated rotation
  25.         $request $event->getRequest();
  26.         $currentCity $request->attributes->get('city');
  27.         if (!$currentCity instanceof City) {
  28.             return;
  29.         }
  30.         $session $request->getSession();
  31.         if (null === $session) {
  32.             return;
  33.         }
  34.         $orderingKey sprintf('_profile_order.city_%d'$currentCity->getId());
  35.         $listOrderCache $session->get($orderingKey);
  36.         if (!isset($listOrderCache['date'], $listOrderCache['list'])) {
  37.             $listOrderCache null;
  38.         }
  39.         if (null === $listOrderCache || $this->paidPlacementRotator->isOrderChanged($currentCity$listOrderCache['date'])) {
  40.             $listOrderCache = [
  41.                 'date' => CarbonImmutable::now(),
  42.                 'list' => $this->paidPlacementRotator->getOrderedIdList($currentCity),
  43.             ];
  44.             $session->set($orderingKey$listOrderCache);
  45.         }
  46.     }
  47.     /**
  48.      * @inheritDoc
  49.      */
  50.     public static function getSubscribedEvents()
  51.     {
  52.         return [
  53.             KernelEvents::CONTROLLER_ARGUMENTS => 'generateListingOrder',
  54.         ];
  55.     }
  56. }