<?php
namespace App\Controller\FrontendBundle\Registration;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\BackendBundle\Mailer\Target\Register\RegisterProviderPremium;
use App\BackendBundle\Mailer\Target\Register\RegisterProviderSendProvider;
use App\BackendBundle\Helper\CommunicationHelper;
use App\BackendBundle\Helper\MailerHelper;
use App\BackendBundle\Helper\RegisterHelper;
use App\BackendBundle\Helper\SiteTitleHelper;
use App\BackendBundle\Helper\UserHelper;
use App\BackendBundle\Helper\ValidationHelper;
class RegisterProviderController extends AbstractController {
private $communicationHelper;
private $mailerHelper;
private $registerHelper;
private $userHelper;
private $siteTitleHelper;
private $validationHelper;
public function __construct(SiteTitleHelper $sitetitlehelper, CommunicationHelper $communicationhelper, MailerHelper $mailerhelper, RegisterHelper $registerhelper, UserHelper $userhelper, ValidationHelper $validationhelper) {
$this->siteTitleHelper = $sitetitlehelper;
$this->communicationHelper = $communicationhelper;
$this->mailerHelper = $mailerhelper;
$this->registerHelper = $registerhelper;
$this->userHelper = $userhelper;
$this->validationHelper = $validationhelper;
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @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."})
*/
public function chooseProviderAction(Request $request) {
$this->siteTitleHelper->setTitleDescription($request);
return $this->render('@frontend/registration/registration_provider_type.html.twig');
}
/**
* Needed to redirect from wko box to correct url
*
* @return \Symfony\Component\HttpFoundation\Response
* @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."})
*/
public function wkoBoxRedirectAction(Request $request) {
$this->siteTitleHelper->setTitleDescription($request);
return $this->redirect("/register/anbieter/unternehmen");
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @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."})
*/
public function registerCompanyPremiumAction(Request $request) {
$this->siteTitleHelper->setTitleDescription($request);
if ($request->isXmlHttpRequest()) {
$data = array();
$data['status'] = 'ok';
$loginData = $request->request->get('login');
$personData = $request->request->get('person');
$companyData = $request->request->get('company');
$isFormValid = $this->validationHelper->isFormValid('register', $request);
if (!$isFormValid) {
$data['status'] = 'error';
$data['message'] = 'Fehler beim Absenden der Formulardaten';
}
$email = $loginData['email'];
$isEmailValid = $this->validationHelper->isEmailValid($email);
if (!$isEmailValid) {
$data['status'] = 'error';
$data['message'] = 'Ungültige E-Mail-Adresse';
return new JsonResponse($data);
}
if ($this->checkUserExists($email)) {
$data['status'] = 'error';
$data['message'] = 'Zu den eingegebenen Daten existiert bereits ein Benutzer';
return new JsonResponse($data);
}
$roleNames = array('ROLE_USER', 'ROLE_COMPANY');
$this->createRegisteredUser($loginData, $personData, $roleNames);
$this->sendProviderPremiumRegisterMail($loginData, $personData, $companyData, 'Unternehmen');
$this->sendProviderRegisterMailToProvider($loginData);
$data['url'] = $this->generateUrl('provider_register_step_data_success');
return new JsonResponse($data);
} else {
$validationData = $this->validationHelper->getFormValidationData('register');
return $this->render('@frontend/registration/register_company_premium.html.twig', array(
'validationData' => $validationData
));
}
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @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."})
*/
public function registerBOProviderAction(Request $request) {
$this->siteTitleHelper->setTitleDescription($request);
if ($request->isXmlHttpRequest()) {
$data = array();
$data['status'] = 'ok';
$loginData = $request->request->get('login');
$personData = $request->request->get('person');
$boPartnerData = $request->request->get('bopartner');
$isFormValid = $this->validationHelper->isFormValid('register', $request);
if (!$isFormValid) {
$data['status'] = 'error';
$data['message'] = 'Fehler beim Absenden der Formulardaten';
}
$email = $loginData['email'];
$isEmailValid = $this->validationHelper->isEmailValid($email);
if (!$isEmailValid) {
$data['status'] = 'error';
$data['message'] = 'Ungültige E-Mail-Adresse';
return new JsonResponse($data);
}
if ($this->checkUserExists($loginData['email'])) {
$data['status'] = 'error';
$data['message'] = 'Zu den eingegebenen Daten existiert bereits ein Benutzer';
return new JsonResponse($data);
}
$roleNames = array('ROLE_USER', 'ROLE_BOPARTNER');
$this->createRegisteredUser($loginData, $personData, $roleNames);
$this->sendProviderPremiumRegisterMail($loginData, $personData, $boPartnerData, 'BO-Institution');
$this->sendProviderRegisterMailToProvider($loginData);
$data['url'] = $this->generateUrl('provider_register_step_data_success');
return new JsonResponse($data);
} else {
$validationData = $this->validationHelper->getFormValidationData('register');
return $this->render('@frontend/registration/register_bo_provider.html.twig', array(
'validationData' => $validationData
));
}
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @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."})
*/
public function registerSecondarySchoolProviderAction(Request $request) {
$this->siteTitleHelper->setTitleDescription($request);
if ($request->isXmlHttpRequest()) {
$data = array();
$data['status'] = 'ok';
$loginData = $request->request->get('login');
$personData = $request->request->get('person');
$schoolData = $request->request->get('school');
$isFormValid = $this->validationHelper->isFormValid('register', $request);
if (!$isFormValid) {
$data['status'] = 'error';
$data['message'] = 'Fehler beim Absenden der Formulardaten';
}
$email = $loginData['email'];
$isEmailValid = $this->validationHelper->isEmailValid($email);
if (!$isEmailValid) {
$data['status'] = 'error';
$data['message'] = 'Ungültige E-Mail-Adresse';
return new JsonResponse($data);
}
if ($this->checkUserExists($loginData['email'])) {
$data['status'] = 'error';
$data['message'] = 'Zu den eingegebenen Daten existiert bereits ein Benutzer';
return new JsonResponse($data);
}
$roleNames = array('ROLE_USER', 'ROLE_SECONDARY_SCHOOL');
$this->createRegisteredUser($loginData, $personData, $roleNames);
$this->sendProviderPremiumRegisterMail($loginData, $personData, $schoolData, 'Weiterführende Schule');
$this->sendProviderRegisterMailToProvider($loginData);
$data['url'] = $this->generateUrl('provider_register_step_data_success');
return new JsonResponse($data);
} else {
$validationData = $this->validationHelper->getFormValidationData('register');
return $this->render('@frontend/registration/register_secondary_school_provider.html.twig', array(
'validationData' => $validationData
));
}
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @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."})
*/
public function successAction(Request $request) {
$this->siteTitleHelper->setTitleDescription($request);
return $this->render('@frontend/registration/register_company_success.html.twig');
}
private function createRegisteredUser($loginData, $personData, $roleNames) {
$firstname = $personData['firstname'];
$lastname = $personData['lastname'];
$gender = $personData['gender'];
$email = $loginData['email'];
$password = $loginData['password'];
// check if user exists is done in a step before
$user = $this->userHelper->createUser($email, $password, false, $roleNames);
$person = $this->registerHelper->createPerson($firstname, $lastname, $gender, null, null);
$this->userHelper->createUserData($user, $person, null, null);
}
private function checkUserExists($email) {
$user = $this->userHelper->getUserByEmail($email);
if (empty($user)) {
return false;
}
return true;
}
private function sendProviderPremiumRegisterMail($loginData, $personData, $providerData, $providerType) {
$mailerSwift = $this->mailerHelper->getMailerRegisterEmail();
$wkoNr = '';
if (isset($providerData['wknr'])) {
$wkoNr = $providerData['wknr'];
}
$options = array();
$options['providerType'] = $providerType;
$options['nameProvider'] = $providerData['name'];
$options['wkoNr'] = $wkoNr;
$options['street'] = $providerData['street'];
$options['plz'] = $providerData['zip'];
$options['ort'] = $providerData['place'];
$options['firstname'] = $personData['firstname'];
$options['lastname'] = $personData['lastname'];
$options['email'] = $loginData['email'];
$target = new RegisterProviderPremium($options);
$this->mailerHelper->sendMailTemplate($mailerSwift, $target);
}
private function sendProviderRegisterMailToProvider($loginData) {
$mailer = $this->mailerHelper->getMailerRegisterEmail();
$options = array();
$options['email'] = $loginData['email'];
$target = new RegisterProviderSendProvider($options);
$this->mailerHelper->sendMailTemplate($mailer, $target);
}
}