<?php
namespace App\Controller;
use App\Entity\FormUser;
use App\Repository\FormRepository;
use App\Repository\FormUserRepository;
use App\Repository\SlideRepository;
use Doctrine\ORM\EntityManagerInterface;
use Nette\Utils\DateTime;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mime\Address;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Security\EmailVerifier;
class BaseController extends AbstractController
{
#[Route('/', name: 'front')]
public function front(FormRepository $formRepository, SlideRepository $slideRepository): Response
{
$slides = $slideRepository->findAll();
return $this->renderForm('front/index.html.twig', [
'Formulaires' => $formRepository->getPublishedNotEndedWithLimit( 8 ),
'slides' => $slides,
]);
}
public function VerificationAccount()
{
if ($this->getUser()) {
if (!$this->getUser()->isVerified()) {
$this->addFlash('VerifAccount', 'Vous devez vérifier votre compte !');
return $this->redirectToRoute('app_logout');
}
if (!$this->getUser()->getCompleted()) {
$this->addFlash('VerifAccount', 'Vous devez compléter votre profil !');
return $this->redirectToRoute('app_profil');
}
if (!$this->getUser()->isActive()) {
$this->addFlash('VerifAccount', 'Votre compte est désactivé !');
return $this->redirectToRoute('app_logout');
}
return null;
} else {
return $this->redirectToRoute('login');
}
}
#[Route('/cron/notification/demand/treatment/{days}', name: 'cron_notification_demand_treatment')]
public function cronNotificationDemandTreatment( EntityManagerInterface $entityManager, EmailVerifier $emailVerifier, $days )
{
$demandes = $entityManager->getRepository(FormUser::class)->findBy( [ "Etat" => FormUser::STATUS_ARRAY[ 'WAITING' ] ] );
$date_now = new \DateTime();
foreach ( $demandes as $demande ){
$date_notif = ( new \DateTime( $demande->getCreatedAt()->format('Y-m-d') ) )->add( new \DateInterval('P' . $days . 'D') );
if ( $date_now >= $date_notif ){
foreach ( $demande->getResponsables() as $responsable ){
$emailVerifier->sendEmailConfirmation(
'app_verify_email',
$responsable,
(new TemplatedEmail())
->from(new Address($this->getParameter('EmailAdmin'), 'IGPPP'))
->to($responsable->getEmail())
->subject('Rappel des délais de traitement des demandes !')
->htmlTemplate('email/email_notification_demande_treatment.html.twig')
->context([
'demande' => $demande,
])
);
// // push notification
// $notification_message = 'Rappel des délais de traitement des demandes !';
// $this->notificationManager->pushMessage('Rappel des délais de traitement des demandes !', $notification_message, $responsable, $demande_url);
}
}
}
return new JsonResponse('ok');
}
#[Route('/changeLocale/{_locale}', name: 'app_change_locale')]
public function changeLocale(Request $request)
{
if ($locale = $request->attributes->get('_locale')) {
$request->getSession()->set('_locale', $locale);
}
$referer = $request->headers->get('referer');
return $this->redirect($referer);
}
}