src/Controller/FrontendBundle/Registration/RegisterProviderController.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Controller\FrontendBundle\Registration;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use App\BackendBundle\Mailer\Target\Register\RegisterProviderPremium;
  8. use App\BackendBundle\Mailer\Target\Register\RegisterProviderSendProvider;
  9. use App\BackendBundle\Helper\CommunicationHelper;
  10. use App\BackendBundle\Helper\MailerHelper;
  11. use App\BackendBundle\Helper\RegisterHelper;
  12. use App\BackendBundle\Helper\SiteTitleHelper;
  13. use App\BackendBundle\Helper\UserHelper;
  14. use App\BackendBundle\Helper\ValidationHelper;
  15. class RegisterProviderController extends AbstractController {
  16.     private $communicationHelper;
  17.     private $mailerHelper;
  18.     private $registerHelper;
  19.     private $userHelper;
  20.     private $siteTitleHelper;
  21.     private $validationHelper;
  22.     public function __construct(SiteTitleHelper $sitetitlehelperCommunicationHelper $communicationhelperMailerHelper $mailerhelperRegisterHelper $registerhelperUserHelper $userhelperValidationHelper $validationhelper) {
  23.         $this->siteTitleHelper $sitetitlehelper;
  24.         $this->communicationHelper $communicationhelper;
  25.         $this->mailerHelper $mailerhelper;
  26.         $this->registerHelper $registerhelper;
  27.         $this->userHelper $userhelper;
  28.         $this->validationHelper $validationhelper;
  29.     }
  30.     /**
  31.      * @return \Symfony\Component\HttpFoundation\Response
  32.      * @Route("/register/anbieter/type", name="provider_type_choose", defaults={"title": "Registrierung als Anbieter", "description": "Registrieren Sie sich jetzt als Anbieter auf berufsreise.at und präsentieren Sie sich und Ihr Angebot Tiroler Schüler*innen."}) 
  33.      */
  34.     public function chooseProviderAction(Request $request) {
  35.         $this->siteTitleHelper->setTitleDescription($request);
  36.         return $this->render('@frontend/registration/registration_provider_type.html.twig');
  37.     }
  38.     /**
  39.      * Needed to redirect from wko box to correct url
  40.      * 
  41.      * @return \Symfony\Component\HttpFoundation\Response
  42.      * @Route("/register/anbieter/new_premium", name="provider_wko_box", defaults={"title": "Registrierung als Anbieter", "description": "Registrieren Sie sich jetzt als Anbieter auf berufsreise.at und präsentieren Sie sich und Ihr Angebot Tiroler Schüler*innen."}) 
  43.      */
  44.     public function wkoBoxRedirectAction(Request $request) {
  45.         $this->siteTitleHelper->setTitleDescription($request);
  46.         return $this->redirect("/register/anbieter/unternehmen");
  47.     }    
  48.     
  49.     /**
  50.      * @return \Symfony\Component\HttpFoundation\Response
  51.      * @Route("/register/anbieter/unternehmen", name="provider_register_step_data", defaults={"title": "Registrierung als Unternehmen", "description": "Registrieren Sie Ihr Unternehmen auf berufsreise.at und präsentieren Sie sich und Ihre Angebote Lehrpersonen und Schüler*innen."}) 
  52.      */
  53.     public function registerCompanyPremiumAction(Request $request) {
  54.         $this->siteTitleHelper->setTitleDescription($request);
  55.         if ($request->isXmlHttpRequest()) {
  56.             $data = array();
  57.             $data['status'] = 'ok';
  58.             $loginData $request->request->get('login');
  59.             $personData $request->request->get('person');
  60.             $companyData $request->request->get('company');
  61.             $isFormValid $this->validationHelper->isFormValid('register'$request);
  62.             if (!$isFormValid) {
  63.                 $data['status'] = 'error';
  64.                 $data['message'] = 'Fehler beim Absenden der Formulardaten';
  65.             }
  66.             $email $loginData['email'];
  67.             $isEmailValid $this->validationHelper->isEmailValid($email);
  68.             if (!$isEmailValid) {
  69.                 $data['status'] = 'error';
  70.                 $data['message'] = 'Ungültige E-Mail-Adresse';
  71.                 return new JsonResponse($data);
  72.             }
  73.             if ($this->checkUserExists($email)) {
  74.                 $data['status'] = 'error';
  75.                 $data['message'] = 'Zu den eingegebenen Daten existiert bereits ein Benutzer';
  76.                 return new JsonResponse($data);
  77.             }
  78.             $roleNames = array('ROLE_USER''ROLE_COMPANY');
  79.             $this->createRegisteredUser($loginData$personData$roleNames);
  80.             $this->sendProviderPremiumRegisterMail($loginData$personData$companyData'Unternehmen');
  81.             $this->sendProviderRegisterMailToProvider($loginData);
  82.             $data['url'] = $this->generateUrl('provider_register_step_data_success');
  83.             return new JsonResponse($data);
  84.         } else {
  85.             $validationData $this->validationHelper->getFormValidationData('register');
  86.             return $this->render('@frontend/registration/register_company_premium.html.twig', array(
  87.                         'validationData' => $validationData
  88.             ));
  89.         }
  90.     }
  91.     /**
  92.      * @return \Symfony\Component\HttpFoundation\Response
  93.      * @Route("/register/anbieter/bopartner", name="provider_bo_register_step_data", defaults={"title": "Registrierung als BO-Institution", "description": "Registrieren Sie Ihr BO-Institution auf berufsreise.at und präsentieren Sie sich und Ihre Angebote Lehrpersonen und Schüler*innen."}) 
  94.      */
  95.     public function registerBOProviderAction(Request $request) {
  96.         $this->siteTitleHelper->setTitleDescription($request);
  97.         if ($request->isXmlHttpRequest()) {
  98.             $data = array();
  99.             $data['status'] = 'ok';
  100.             $loginData $request->request->get('login');
  101.             $personData $request->request->get('person');
  102.             $boPartnerData $request->request->get('bopartner');
  103.             $isFormValid $this->validationHelper->isFormValid('register'$request);
  104.             if (!$isFormValid) {
  105.                 $data['status'] = 'error';
  106.                 $data['message'] = 'Fehler beim Absenden der Formulardaten';
  107.             }
  108.             $email $loginData['email'];
  109.             $isEmailValid $this->validationHelper->isEmailValid($email);
  110.             if (!$isEmailValid) {
  111.                 $data['status'] = 'error';
  112.                 $data['message'] = 'Ungültige E-Mail-Adresse';
  113.                 return new JsonResponse($data);
  114.             }            
  115.             
  116.             if ($this->checkUserExists($loginData['email'])) {
  117.                 $data['status'] = 'error';
  118.                 $data['message'] = 'Zu den eingegebenen Daten existiert bereits ein Benutzer';
  119.                 return new JsonResponse($data);
  120.             }
  121.             $roleNames = array('ROLE_USER''ROLE_BOPARTNER');
  122.             $this->createRegisteredUser($loginData$personData$roleNames);
  123.             $this->sendProviderPremiumRegisterMail($loginData$personData$boPartnerData'BO-Institution');
  124.             $this->sendProviderRegisterMailToProvider($loginData);
  125.             $data['url'] = $this->generateUrl('provider_register_step_data_success');
  126.             return new JsonResponse($data);
  127.         } else {
  128.             $validationData $this->validationHelper->getFormValidationData('register');
  129.             return $this->render('@frontend/registration/register_bo_provider.html.twig', array(
  130.                         'validationData' => $validationData
  131.             ));
  132.         }
  133.     }
  134.     /**
  135.      * @return \Symfony\Component\HttpFoundation\Response
  136.      * @Route("/register/anbieter/weiterfuehrendeschule", name="provider_sec_school_register_step_data", defaults={"title": "Registrierung als weiterführende Schule", "description": "Registrieren Sie Ihre weiterführende Schule auf berufsreise.at und präsentieren Sie sich und Ihre Angebote Lehrpersonen und Schüler*innen."}) 
  137.      */
  138.     public function registerSecondarySchoolProviderAction(Request $request) {
  139.         $this->siteTitleHelper->setTitleDescription($request);
  140.         if ($request->isXmlHttpRequest()) {
  141.             $data = array();
  142.             $data['status'] = 'ok';
  143.             $loginData $request->request->get('login');
  144.             $personData $request->request->get('person');
  145.             $schoolData $request->request->get('school');
  146.             $isFormValid $this->validationHelper->isFormValid('register'$request);
  147.             if (!$isFormValid) {
  148.                 $data['status'] = 'error';
  149.                 $data['message'] = 'Fehler beim Absenden der Formulardaten';
  150.             }
  151.             $email $loginData['email'];
  152.             $isEmailValid $this->validationHelper->isEmailValid($email);
  153.             if (!$isEmailValid) {
  154.                 $data['status'] = 'error';
  155.                 $data['message'] = 'Ungültige E-Mail-Adresse';
  156.                 return new JsonResponse($data);
  157.             }            
  158.             
  159.             if ($this->checkUserExists($loginData['email'])) {
  160.                 $data['status'] = 'error';
  161.                 $data['message'] = 'Zu den eingegebenen Daten existiert bereits ein Benutzer';
  162.                 return new JsonResponse($data);
  163.             }
  164.             $roleNames = array('ROLE_USER''ROLE_SECONDARY_SCHOOL');
  165.             $this->createRegisteredUser($loginData$personData$roleNames);
  166.             $this->sendProviderPremiumRegisterMail($loginData$personData$schoolData'Weiterführende Schule');
  167.             $this->sendProviderRegisterMailToProvider($loginData);
  168.             $data['url'] = $this->generateUrl('provider_register_step_data_success');
  169.             return new JsonResponse($data);
  170.         } else {
  171.             $validationData $this->validationHelper->getFormValidationData('register');
  172.             return $this->render('@frontend/registration/register_secondary_school_provider.html.twig', array(
  173.                         'validationData' => $validationData
  174.             ));
  175.         }
  176.     }
  177.     /**
  178.      * @return \Symfony\Component\HttpFoundation\Response
  179.      * @Route("/register/anbieter/abgeschlossen", name="provider_register_step_data_success", defaults={"title": "Registrierung erfolgreich abgeschlossen", "description": "Vielen Dank für Ihre Registrierung auf berufsreise.at."}) 
  180.      */
  181.     public function successAction(Request $request) {
  182.         $this->siteTitleHelper->setTitleDescription($request);
  183.         return $this->render('@frontend/registration/register_company_success.html.twig');
  184.     }
  185.     private function createRegisteredUser($loginData$personData$roleNames) {
  186.         $firstname $personData['firstname'];
  187.         $lastname $personData['lastname'];
  188.         $gender $personData['gender'];
  189.         $email $loginData['email'];
  190.         $password $loginData['password'];
  191.         // check if user exists is done in a step before
  192.         $user $this->userHelper->createUser($email$passwordfalse$roleNames);
  193.         $person $this->registerHelper->createPerson($firstname$lastname$gendernullnull);
  194.         $this->userHelper->createUserData($user$personnullnull);
  195.     }
  196.     private function checkUserExists($email) {
  197.         $user $this->userHelper->getUserByEmail($email);
  198.         if (empty($user)) {
  199.             return false;
  200.         }
  201.         return true;
  202.     }
  203.     private function sendProviderPremiumRegisterMail($loginData$personData$providerData$providerType) {
  204.         $mailerSwift $this->mailerHelper->getMailerRegisterEmail();
  205.         $wkoNr '';
  206.         if (isset($providerData['wknr'])) {
  207.             $wkoNr $providerData['wknr'];
  208.         }
  209.         $options = array();
  210.         $options['providerType'] = $providerType;
  211.         $options['nameProvider'] = $providerData['name'];
  212.         $options['wkoNr'] = $wkoNr;
  213.         $options['street'] = $providerData['street'];
  214.         $options['plz'] = $providerData['zip'];
  215.         $options['ort'] = $providerData['place'];
  216.         $options['firstname'] = $personData['firstname'];
  217.         $options['lastname'] = $personData['lastname'];
  218.         $options['email'] = $loginData['email'];
  219.         $target = new RegisterProviderPremium($options);
  220.         $this->mailerHelper->sendMailTemplate($mailerSwift$target);
  221.     }
  222.     private function sendProviderRegisterMailToProvider($loginData) {
  223.         $mailer $this->mailerHelper->getMailerRegisterEmail();
  224.         $options = array();
  225.         $options['email'] = $loginData['email'];
  226.         $target = new RegisterProviderSendProvider($options);
  227.         $this->mailerHelper->sendMailTemplate($mailer$target);
  228.     }
  229. }