src/Controller/ContactController.php line 185

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace App\Controller;
  15. use Pimcore\Translation\Translator;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  17. use Symfony\Component\HttpFoundation\RedirectResponse;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  21. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  24. use Symfony\Component\Security\Core\User\UserInterface;
  25. use Symfony\Component\Uid\Uuid;
  26. use Knp\Component\Pager\Pagination\SlidingPagination;
  27. use Knp\Component\Pager\PaginatorInterface;
  28. use Pimcore\Model\DataObject;
  29. use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
  30. use Box\Spout\Common\Entity\Row;
  31. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  32. use FrontendPermissionToolkitBundle\Service as FrontenKitService;
  33. use App\Form\ContactUsFormType;
  34. use App\Form\CollabrationFormType;
  35. use App\Form\WorkWithUsFormType;
  36. use App\Model\ContactUs;
  37. use App\Model\Collabration;
  38. use App\Model\WorkWithUs;
  39. use Symfony\Component\Form\FormError;
  40. use App\Services\EmailService;
  41. /**
  42.  * Class ContactController
  43.  *
  44.  * Controller that handles all account functionality, including register, login and connect to SSO profiles
  45.  */
  46. class ContactController extends BaseController
  47. {  
  48.     public $emailService;
  49.     
  50.     public function __construct(){
  51.         $this->emailService = new EmailService();
  52.     }
  53.     
  54.     /**    
  55.      * @Route("/contact-us", name="contact-us")    
  56.      * @param UserInterface|null $user
  57.      *
  58.      * @return Response
  59.      */
  60.     public function contactUsAction(Request $request){
  61.         
  62.         // build the registration form and pre-fill it with customer data
  63.         $form $this->createForm(ContactUsFormType::class);
  64.         $form->handleRequest($request);        
  65.         $data $form->getViewData();
  66.        
  67.         $errors = [];
  68.         if ($form->isSubmitted() && $form->isValid()) {
  69.             try {
  70.                 $key $data['subject'].'_'.$data['email'].'_'.date('Y-m-d H:i:s');
  71.                 $contactUs \Pimcore\Model\DataObject::getByPath('/Contacts/contact-us/'.$key);
  72.                 if($contactUs)
  73.                 {
  74.                     throw new \Exception("Il cliente con lo stesso ID e-mail esiste già");
  75.                 }
  76.                 $contactUs = new ContactUs();
  77.                 $contactUs->setKey($key);
  78.                 $contactUs->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/Contacts/contact-us'));
  79.                 $contactUs->setPublished(true); 
  80.                 $contactUs->setData($form$request)->save();
  81.                 //$this->addFlash('success', 'Grazie per averci contattato! Vi risponderemo a breve');
  82.                 $this->emailService->sendNotificationEmail($contactUs);
  83.                 return $this->redirectToRoute(
  84.                     "contact-us",['success'=>true]);
  85.                 // if($data['_target_path']){
  86.                 //     return $this->render('contact/thankyou_page_contactus.html.twig');
  87.                 //     //return $this->redirect($data['_target_path']);
  88.                 // }else{
  89.                 //     return $this->redirectToRoute(
  90.                 //         "contact-us");
  91.                 // }
  92.             } catch (\Exception $e) {
  93.                 $form->addError(new FormError($e->getMessage()));
  94.             }
  95.         }
  96.         if ($form->isSubmitted() && !$form->isValid()) {
  97.             foreach ($form->getErrors() as $error) {
  98.                 $errors[] = $error->getMessage();
  99.             }
  100.         }
  101.         if($request->get('success') == true){
  102.             return $this->render('contact/thankyou_page_contactus.html.twig');
  103.         }else{
  104.             return $this->render('contact/contact-us.html.twig', ['form' => $form->createView(),'_target_path'=>$request->headers->get('referer'),'errors' => $errors]);
  105.         }        
  106.     }
  107.     
  108.     
  109.     /**    
  110.      * @Route("/collaborations", name="collaborations")    
  111.      * @param UserInterface|null $user
  112.      *
  113.      * @return Response
  114.      */
  115.     public function collaborationsAction(Request $request){
  116.         
  117.         // build the registration form and pre-fill it with customer data
  118.         $form $this->createForm(CollabrationFormType::class);
  119.         $form->handleRequest($request);        
  120.         $data $form->getViewData();
  121.        
  122.         $errors = [];
  123.         if ($form->isSubmitted() && $form->isValid()) {
  124.             try {
  125.                 $key $data['email'].'_'.date('Y-m-d H:i:s');
  126.                 $collabration \Pimcore\Model\DataObject::getByPath('/Contacts/collabrations/'.$key);
  127.                 if($collabration)
  128.                 {
  129.                     throw new \Exception("Il cliente con lo stesso ID e-mail esiste già");
  130.                 }
  131.                 $collabration = new Collabration();
  132.                 $collabration->setKey($key);
  133.                 $collabration->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/Contacts/collabrations'));
  134.                 $collabration->setPublished(true); 
  135.                 $collabration->setData($form$request)->save();
  136.                 $this->emailService->sendNotificationEmail($collabration);
  137.                 //$this->addFlash('success', 'Grazie per aver mostrato interesse a collaborare con noi. Vi contatteremo a breve');
  138.                
  139.                 return $this->redirectToRoute(
  140.                     "collaborations",['success'=>true]);
  141.                 // if($data['_target_path']){
  142.                 //     return $this->redirect($data['_target_path']);
  143.                 // }else{
  144.                 //     return $this->redirectToRoute(
  145.                 //         "collaborations",['success'=>true]);
  146.                 // }
  147.             } catch (\Exception $e) {
  148.                 $form->addError(new FormError($e->getMessage()));
  149.             }
  150.         }
  151.         if ($form->isSubmitted() && !$form->isValid()) {
  152.             foreach ($form->getErrors() as $error) {
  153.                 $errors[] = $error->getMessage();
  154.             }
  155.         }
  156.         if($request->get('success') == true){
  157.             return $this->render('contact/thankyou_page_collaboration.html.twig');
  158.         }else{
  159.             return $this->render('contact/collabrations.html.twig', ['form' => $form->createView(),'_target_path'=>$request->headers->get('referer'),'errors' => $errors]);
  160.         }
  161.     }
  162.     /**    
  163.      * @Route("/work-with-us", name="work_with_us")    
  164.      * @param UserInterface|null $user
  165.      *
  166.      * @return Response
  167.      */
  168.     public function WorkWithUsAction(Request $request){
  169.         
  170.         // build the registration form and pre-fill it with customer data
  171.         $form $this->createForm(WorkWithUsFormType::class);
  172.         $form->handleRequest($request);        
  173.         $data $form->getViewData();
  174.        
  175.         $errors = [];
  176.         if ($form->isSubmitted() && $form->isValid()) {
  177.             try {
  178.                 $key $data['email'].'_'.date('Y-m-d H:i:s');
  179.                 $workWithUs \Pimcore\Model\DataObject::getByPath('/Contacts/workwithus/'.$key);
  180.                 if($workWithUs)
  181.                 {
  182.                     throw new \Exception("Il cliente con lo stesso ID e-mail esiste già");
  183.                 }
  184.                 $workWithUs = new WorkWithUs();
  185.                 $workWithUs->setKey($key);
  186.                 $workWithUs->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/Contacts/workwithus'));
  187.                 $workWithUs->setPublished(true); 
  188.                 $workWithUs->setData($form$request)->save();
  189.                 //$this->addFlash('success', 'Grazie per aver mostrato interesse a lavorare con noi. Vi contatteremo a breve');
  190.                 $this->emailService->sendNotificationEmail($workWithUs);
  191.                 
  192.                 return $this->redirectToRoute(
  193.                     "work_with_us",['success'=>true]);
  194.                 
  195.                 // if($data['_target_path']){
  196.                 //     return $this->redirect($data['_target_path']);
  197.                 // }else{
  198.                 //     return $this->redirectToRoute(
  199.                 //         "work_with_us");
  200.                 // }
  201.             } catch (\Exception $e) {
  202.                 $form->addError(new FormError($e->getMessage()));
  203.             }
  204.         }
  205.         if ($form->isSubmitted() && !$form->isValid()) {
  206.             foreach ($form->getErrors() as $error) {
  207.                 $errors[] = $error->getMessage();
  208.             }
  209.         }
  210.         if($request->get('success') == true){
  211.             return $this->render('contact/thankyou_page_workwithus.html.twig');
  212.         }else{
  213.             return $this->render('contact/work-with-us.html.twig', ['form' => $form->createView(),'_target_path'=>$request->headers->get('referer'),'errors' => $errors]);
  214.         }
  215.     }
  216. }