<?php
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/
namespace App\Controller;
use Pimcore\Translation\Translator;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Uid\Uuid;
use Knp\Component\Pager\Pagination\SlidingPagination;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Model\DataObject;
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
use Box\Spout\Common\Entity\Row;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use FrontendPermissionToolkitBundle\Service as FrontenKitService;
use App\Form\ContactUsFormType;
use App\Form\CollabrationFormType;
use App\Form\WorkWithUsFormType;
use App\Model\ContactUs;
use App\Model\Collabration;
use App\Model\WorkWithUs;
use Symfony\Component\Form\FormError;
use App\Services\EmailService;
/**
* Class ContactController
*
* Controller that handles all account functionality, including register, login and connect to SSO profiles
*/
class ContactController extends BaseController
{
public $emailService;
public function __construct(){
$this->emailService = new EmailService();
}
/**
* @Route("/contact-us", name="contact-us")
* @param UserInterface|null $user
*
* @return Response
*/
public function contactUsAction(Request $request){
// build the registration form and pre-fill it with customer data
$form = $this->createForm(ContactUsFormType::class);
$form->handleRequest($request);
$data = $form->getViewData();
$errors = [];
if ($form->isSubmitted() && $form->isValid()) {
try {
$key = $data['subject'].'_'.$data['email'].'_'.date('Y-m-d H:i:s');
$contactUs = \Pimcore\Model\DataObject::getByPath('/Contacts/contact-us/'.$key);
if($contactUs)
{
throw new \Exception("Il cliente con lo stesso ID e-mail esiste già");
}
$contactUs = new ContactUs();
$contactUs->setKey($key);
$contactUs->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/Contacts/contact-us'));
$contactUs->setPublished(true);
$contactUs->setData($form, $request)->save();
//$this->addFlash('success', 'Grazie per averci contattato! Vi risponderemo a breve');
$this->emailService->sendNotificationEmail($contactUs);
return $this->redirectToRoute(
"contact-us",['success'=>true]);
// if($data['_target_path']){
// return $this->render('contact/thankyou_page_contactus.html.twig');
// //return $this->redirect($data['_target_path']);
// }else{
// return $this->redirectToRoute(
// "contact-us");
// }
} catch (\Exception $e) {
$form->addError(new FormError($e->getMessage()));
}
}
if ($form->isSubmitted() && !$form->isValid()) {
foreach ($form->getErrors() as $error) {
$errors[] = $error->getMessage();
}
}
if($request->get('success') == true){
return $this->render('contact/thankyou_page_contactus.html.twig');
}else{
return $this->render('contact/contact-us.html.twig', ['form' => $form->createView(),'_target_path'=>$request->headers->get('referer'),'errors' => $errors]);
}
}
/**
* @Route("/collaborations", name="collaborations")
* @param UserInterface|null $user
*
* @return Response
*/
public function collaborationsAction(Request $request){
// build the registration form and pre-fill it with customer data
$form = $this->createForm(CollabrationFormType::class);
$form->handleRequest($request);
$data = $form->getViewData();
$errors = [];
if ($form->isSubmitted() && $form->isValid()) {
try {
$key = $data['email'].'_'.date('Y-m-d H:i:s');
$collabration = \Pimcore\Model\DataObject::getByPath('/Contacts/collabrations/'.$key);
if($collabration)
{
throw new \Exception("Il cliente con lo stesso ID e-mail esiste già");
}
$collabration = new Collabration();
$collabration->setKey($key);
$collabration->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/Contacts/collabrations'));
$collabration->setPublished(true);
$collabration->setData($form, $request)->save();
$this->emailService->sendNotificationEmail($collabration);
//$this->addFlash('success', 'Grazie per aver mostrato interesse a collaborare con noi. Vi contatteremo a breve');
return $this->redirectToRoute(
"collaborations",['success'=>true]);
// if($data['_target_path']){
// return $this->redirect($data['_target_path']);
// }else{
// return $this->redirectToRoute(
// "collaborations",['success'=>true]);
// }
} catch (\Exception $e) {
$form->addError(new FormError($e->getMessage()));
}
}
if ($form->isSubmitted() && !$form->isValid()) {
foreach ($form->getErrors() as $error) {
$errors[] = $error->getMessage();
}
}
if($request->get('success') == true){
return $this->render('contact/thankyou_page_collaboration.html.twig');
}else{
return $this->render('contact/collabrations.html.twig', ['form' => $form->createView(),'_target_path'=>$request->headers->get('referer'),'errors' => $errors]);
}
}
/**
* @Route("/work-with-us", name="work_with_us")
* @param UserInterface|null $user
*
* @return Response
*/
public function WorkWithUsAction(Request $request){
// build the registration form and pre-fill it with customer data
$form = $this->createForm(WorkWithUsFormType::class);
$form->handleRequest($request);
$data = $form->getViewData();
$errors = [];
if ($form->isSubmitted() && $form->isValid()) {
try {
$key = $data['email'].'_'.date('Y-m-d H:i:s');
$workWithUs = \Pimcore\Model\DataObject::getByPath('/Contacts/workwithus/'.$key);
if($workWithUs)
{
throw new \Exception("Il cliente con lo stesso ID e-mail esiste già");
}
$workWithUs = new WorkWithUs();
$workWithUs->setKey($key);
$workWithUs->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/Contacts/workwithus'));
$workWithUs->setPublished(true);
$workWithUs->setData($form, $request)->save();
//$this->addFlash('success', 'Grazie per aver mostrato interesse a lavorare con noi. Vi contatteremo a breve');
$this->emailService->sendNotificationEmail($workWithUs);
return $this->redirectToRoute(
"work_with_us",['success'=>true]);
// if($data['_target_path']){
// return $this->redirect($data['_target_path']);
// }else{
// return $this->redirectToRoute(
// "work_with_us");
// }
} catch (\Exception $e) {
$form->addError(new FormError($e->getMessage()));
}
}
if ($form->isSubmitted() && !$form->isValid()) {
foreach ($form->getErrors() as $error) {
$errors[] = $error->getMessage();
}
}
if($request->get('success') == true){
return $this->render('contact/thankyou_page_workwithus.html.twig');
}else{
return $this->render('contact/work-with-us.html.twig', ['form' => $form->createView(),'_target_path'=>$request->headers->get('referer'),'errors' => $errors]);
}
}
}