src/Controller/Front/RequestController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\User\User;
  4. use App\Service\LanguagesManager;
  5. use App\Entity\Request\RequestForm;
  6. use App\Service\Manager\AdminManager;
  7. use App\Entity\Request\RequestComment;
  8. use App\Controller\Admin\CoreController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use App\Repository\Configuration\SurveyRepository;
  13. use App\Repository\Request\RequestCommentRepository;
  14. use App\Service\Manager\RequestForm\RequestFormManager;
  15. use App\Service\Manager\TemplateEmail\TagsManager;
  16. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  17. use App\Service\Manager\TemplateMailerManager;
  18. use App\Repository\Request\RequestFormRepository;
  19. use App\Entity\TemplateEmail\Template;
  20. use App\Service\Mailer\Mailer;
  21. #[Route('/request')]
  22. class RequestController extends CoreController
  23. {
  24.     #[Route('/index/{refSuffix}'name'front_request_index')]
  25.     public function index($refSuffix
  26.                             SurveyRepository $surveyRepository
  27.                             Request $request
  28.                             LanguagesManager $languagesManager,
  29.                             RequestFormManager $requestFormManager
  30.                             ): Response
  31.     {
  32.         $language $languagesManager->getLanguageUser($request);
  33.         $survey =  "";
  34.         $user $this->getUser();
  35.         $parametres = [
  36.             'refSuffix' => $refSuffix,
  37.             'deletedAt' => null,
  38.             'isEnable' => 1,
  39.             'isDisplay' => 1
  40.         ];
  41.         if ($user && (!in_array($user->getRoles(), [User::ROLE_ADMIN]))) {
  42.             unset($parametres['isEnable']);
  43.             unset($parametres['isDisplay']);
  44.         }
  45.         $survey $surveyRepository->getAllQb([
  46.             'refSuffix' => $refSuffix,
  47.             'fk' => ['survey.label'],
  48.             'id_language' => $language->getId()
  49.             ])->getOneOrNullResult();
  50.       
  51.         $response =  $requestFormManager->getForm($survey);
  52.         if($response instanceof Response) return $response
  53.         return $this->render('front/request/index.html.twig', (!empty($response['paramsTemplate'])) ? $response['paramsTemplate'] : [] );
  54.     }
  55.     #[Route('/save_comment/{id}'name'front_request_form_save_comment')]
  56.     public function saveComment(Request $request,RequestForm $requestForm,RequestCommentRepository $requestCommentRepositoryAdminManager $adminManagerTemplateMailerManager $templateMailerUrlGeneratorInterface $urlGenerator): Response
  57.     {
  58.         $requestComment = new RequestComment();
  59.         $requestComment->setComment($request->request->get('comment'));
  60.         $requestComment->setCreatedDate(new \DateTime());
  61.         $requestComment->setSupportUser($requestForm->getSupportUser());
  62.         $requestComment->setShare(1);
  63.         $requestComment->setRequestForm($requestForm);
  64.         $adminManager->saveEntity($requestComment);
  65.         $comments $requestCommentRepository->getCommentByRequest($requestForm);
  66.         $this->sendEmail($requestComment$templateMailer$urlGenerator);
  67.         return $this->render('front/request/requestComment.html.twig', [
  68.             'comments' => $comments,
  69.             'modeFront' => true
  70.         ]);
  71.     }
  72.     /**
  73.      * sendEmail
  74.      *
  75.      * @param  TagsManager $tagsManager
  76.      * @param  Mailer $mailer
  77.      * @return bool
  78.      */
  79.     private function sendEmail(
  80.         $requestComment,
  81.         TemplateMailerManager $templateMailer,
  82.         UrlGeneratorInterface $urlGenerator,
  83.         $data = []
  84.     )
  85.     { 
  86.         $recipients = [];
  87.         $requestForm $requestComment->getRequestForm();
  88.         if($requestForm->getUser()){
  89.             $recipients[] = $requestForm->getUser()->getEmail();
  90.         }
  91.         $token $requestComment->getSupportUser()->getClient() ? $requestComment->getSupportUser()->getClient()->getToken() : $requestComment->getSupportUser()->getToken();
  92.         $send $templateMailer->selectTemplateAndSendEmail(
  93.             Template::TYPE_NEW_COMMENT
  94.             null
  95.             [
  96.                 'name' => $requestForm $requestForm->getName() : '--',
  97.                 'email' => $requestForm->getUser() ? $requestForm->getUser()->getEmail() : '--',
  98.                 'company' => $requestForm $requestForm->getCompany() : '--',
  99.                 'phone' => $requestForm $requestForm->getTelephone() : '--',
  100.                 'idRequest' => $requestForm $requestForm->getRequestNum() : '--',
  101.                 'user_not_connected' => true,
  102.                 'url' =>  $urlGenerator->generate('admin_request_form_show_details', array('id' => $requestForm->getId()), UrlGeneratorInterface::ABSOLUTE_URL )
  103.             ], [],
  104.             $recipients
  105.         );
  106.         return $send;
  107.     }
  108.  
  109. }