<?php
namespace App\Service;
use App\Entity\Bandeau;
use App\Repository\BandeauRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class BandeauService extends AbstractController
{
protected $requestStack;
public function __construct(
RequestStack $requestStack
) {
$this->requestStack = $requestStack;
}
public function displayPopup()
{
//on va chercher s'il existe un cookie à afficher
//attention on ne l'affiche que si le user est connecté
$request = $this->requestStack->getCurrentRequest();
$bandeau = $this->getDoctrine()->getManager()->getRepository(Bandeau::class)->findOneByActive();
//maintenant on check s'il existe déjà un cookie
$cookie = $request->cookies->get('mbe_' . $bandeau->getToken());
if (!isset($cookie) and $this->getUser()) {
return $bandeau;
}
return null;
}
}