src/Controller/BaseController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\FormUser;
  4. use App\Repository\FormRepository;
  5. use App\Repository\FormUserRepository;
  6. use App\Repository\SlideRepository;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Nette\Utils\DateTime;
  9. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Mime\Address;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use App\Security\EmailVerifier;
  17. class BaseController extends AbstractController
  18. {
  19.     #[Route('/'name'front')]
  20.     public function front(FormRepository $formRepositorySlideRepository $slideRepository): Response
  21.     {
  22.         $slides $slideRepository->findAll();
  23.         return $this->renderForm('front/index.html.twig', [
  24.             'Formulaires' => $formRepository->getPublishedNotEndedWithLimit),
  25.             'slides' => $slides,
  26.         ]);
  27.     }
  28.     public function VerificationAccount()
  29.     {
  30.         if ($this->getUser()) {
  31.             if (!$this->getUser()->isVerified()) {
  32.                 $this->addFlash('VerifAccount''Vous devez vérifier votre compte !');
  33.                 return $this->redirectToRoute('app_logout');
  34.             }
  35.             if (!$this->getUser()->getCompleted()) {
  36.                 $this->addFlash('VerifAccount''Vous devez compléter votre profil !');
  37.                 return $this->redirectToRoute('app_profil');
  38.             }
  39.             if (!$this->getUser()->isActive()) {
  40.                 $this->addFlash('VerifAccount''Votre compte est désactivé !');
  41.                 return $this->redirectToRoute('app_logout');
  42.             }
  43.             return null;
  44.         } else {
  45.             return $this->redirectToRoute('login');
  46.         }
  47.     }
  48.     #[Route('/cron/notification/demand/treatment/{days}'name'cron_notification_demand_treatment')]
  49.     public function cronNotificationDemandTreatmentEntityManagerInterface $entityManagerEmailVerifier $emailVerifier$days )
  50.     {
  51.         $demandes $entityManager->getRepository(FormUser::class)->findBy( [ "Etat" => FormUser::STATUS_ARRAY'WAITING' ] ] );
  52.         $date_now = new \DateTime();
  53.         foreach ( $demandes as $demande ){
  54.             $date_notif = ( new \DateTime$demande->getCreatedAt()->format('Y-m-d') ) )->add( new \DateInterval('P' $days 'D') );
  55.             if ( $date_now >= $date_notif ){
  56.                 foreach ( $demande->getResponsables() as $responsable ){
  57.                     $emailVerifier->sendEmailConfirmation(
  58.                         'app_verify_email',
  59.                         $responsable,
  60.                         (new TemplatedEmail())
  61.                             ->from(new Address($this->getParameter('EmailAdmin'), 'IGPPP'))
  62.                             ->to($responsable->getEmail())
  63.                             ->subject('Rappel des délais de traitement des demandes !')
  64.                             ->htmlTemplate('email/email_notification_demande_treatment.html.twig')
  65.                             ->context([
  66.                                 'demande' => $demande,
  67.                             ])
  68.                     );
  69. //                    // push notification
  70. //                    $notification_message = 'Rappel des délais de traitement des demandes !';
  71. //                    $this->notificationManager->pushMessage('Rappel des délais de traitement des demandes !', $notification_message, $responsable, $demande_url);
  72.                 }
  73.             }
  74.         }
  75.         return new JsonResponse('ok');
  76.     }
  77.     #[Route('/changeLocale/{_locale}'name'app_change_locale')]
  78.     public function changeLocale(Request $request)
  79.     {
  80.         if ($locale $request->attributes->get('_locale')) {
  81.             $request->getSession()->set('_locale'$locale);
  82.         }
  83.         $referer $request->headers->get('referer');
  84.         return $this->redirect($referer);
  85.     }
  86. }