<?php
/**
* Created by simpson <simpsonwork@gmail.com>
* Date: 2019-05-06
* Time: 15:27
*/
namespace App\EventSubscriber;
use App\Entity\Location\City;
use App\Service\ProfilePaidPlacementRotator;
use Carbon\CarbonImmutable;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* @deprecated
*/
class ProfileListOrderingSubscriber implements EventSubscriberInterface
{
public function __construct(
protected ProfilePaidPlacementRotator $paidPlacementRotator
) {}
public function generateListingOrder(ControllerArgumentsEvent $event): void
{
return; // turn off deprecated rotation
$request = $event->getRequest();
$currentCity = $request->attributes->get('city');
if (!$currentCity instanceof City) {
return;
}
$session = $request->getSession();
if (null === $session) {
return;
}
$orderingKey = sprintf('_profile_order.city_%d', $currentCity->getId());
$listOrderCache = $session->get($orderingKey);
if (!isset($listOrderCache['date'], $listOrderCache['list'])) {
$listOrderCache = null;
}
if (null === $listOrderCache || $this->paidPlacementRotator->isOrderChanged($currentCity, $listOrderCache['date'])) {
$listOrderCache = [
'date' => CarbonImmutable::now(),
'list' => $this->paidPlacementRotator->getOrderedIdList($currentCity),
];
$session->set($orderingKey, $listOrderCache);
}
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER_ARGUMENTS => 'generateListingOrder',
];
}
}