src/Controller/VacancyController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\VacancyFormType;
  4. use App\Services\CheckwebsitesettingService;
  5. use App\Services\GeneralSendMailService;
  6. use App\Services\ReCaptchaService;
  7. use Knp\Component\Pager\PaginatorInterface;
  8. use MultilingualBundle\Service\DocumentLookupService;
  9. use Pimcore\Model\DataObject\Vacancy;
  10. use Pimcore\Model\Site;
  11. use Pimcore\Model\DataObject;
  12. use Pimcore\Translation\Translator;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  17. class VacancyController extends BaseController
  18. {
  19.     protected $recaptcha;
  20.     protected $recaptchaVersion;
  21.     protected $recaptchaPublicKey;
  22.     protected $checkwebsitesettingService;
  23.     protected $inotherlang;
  24.     protected $translator;
  25.     protected $sendmail;
  26.     protected $currentLanguage;
  27.     public function __construct(CheckwebsitesettingService $checkwebsitesettingServiceDocumentLookupService $inotherlangTranslator $translatorReCaptchaService $recaptchaGeneralSendMailService $sendmail){
  28.         $this->checkwebsitesettingService $checkwebsitesettingService;
  29.         $this->inotherlang $inotherlang;
  30.         $this->translator $translator;
  31.         $this->recaptcha $recaptcha;
  32.         $this->recaptchaVersion $recaptcha->getVersion();
  33.         $this->recaptchaPublicKey $recaptcha->getPublicKey();
  34.         $this->sendmail $sendmail;
  35.     }
  36.     /**
  37.      * @param Request $request
  38.      *
  39.      * @return Response
  40.      *
  41.      * @throws \Exception
  42.      */
  43.     public function overviewAction(Request $requestPaginatorInterface $paginator)
  44.     {
  45.         $subSiteKey '*';
  46.         if (Site::isSiteRequest()) {
  47.             $subSiteKey Site::getCurrentSite()->getRootDocument()->getKey();
  48.         }
  49.         $vacancyList = new DataObject\Vacancy\Listing();
  50.         $vacancyList->setOrderKey('date');
  51.         $vacancyList->setOrder('DESC');
  52.         if (Site::isSiteRequest()) {
  53.             $vacancyList->setCondition('subsites LIKE ? AND title != ""''%' $subSiteKey '%');
  54.         }
  55.         $paginator $paginator->paginate(
  56.             $vacancyList,
  57.             $request->get('page'1),
  58.             6
  59.         );
  60.         return $this->render('vacancy/overview.html.twig', [
  61.             'vacancies' => $paginator,
  62.             'paginationVariables' => $paginator->getPaginationData()
  63.         ]);
  64.     }
  65.     /**
  66.      * @Route("{_locale}/{path}/{key}~v{id}", name="vacancy-detail", defaults={"path"=""}, requirements={"path"=".*?", "key"="[\w-]+", "id"="\d+"})
  67.      *
  68.      * @param Request $request
  69.      *
  70.      * @return Response
  71.      */
  72.     public function detailAction(Request $request)
  73.     {
  74.         $vacancy Vacancy::getById($request->get('id'));
  75.         if (!($vacancy instanceof Vacancy && ($vacancy->isPublished() || $this->verifyPreviewRequest($request$vacancy)))) {
  76.             throw new NotFoundHttpException('Vacancy not found.');
  77.         }
  78.         //
  79.         $formName VacancyFormType::class;
  80.         $emailTemplate 'email_vacancy_contact';           // Email template contact
  81.         $emailTemplateConfirm 'email_vacancy_customer';   // Email template contact confirm
  82.         ///////// EDIT VARIABLES ABOVE
  83.         $showApplyForm true;
  84. //        $this->currentLanguage = $request->getLocale();
  85.         // initialize form and handle request data
  86.         if($formName){
  87.             $form $this->createForm($formName);
  88.             $form->handleRequest($request);
  89.         }
  90.         // handle form
  91.         if ($form->isSubmitted()) {
  92.             if ($form->isValid()) {
  93.                 $params $request->request->all();
  94.                 $message "Bedankt voor uw bericht. We nemen zo snel mogelijk contact met u op!";
  95.                 if($this->recaptchaVersion){
  96.                     if($this->recaptcha->captchaverify($params)){
  97.                         $data $form->getData();
  98.                         $this->sendmail->_sendMailDefaultForm($data"$emailTemplate""$emailTemplateConfirm""$message"$vacancy);
  99.                         $showApplyForm false;
  100.                     }else{
  101.                         $message "Captcha code is niet correct!";
  102.                         $this->addFlash("warning"$message);
  103.                     }
  104.                 }else{
  105.                     $data $form->getData();
  106.                     $this->sendmail->_sendMailDefaultForm($data"$emailTemplate""$emailTemplateConfirm""$message"$vacancy);
  107.                     $showApplyForm false;
  108.                 }
  109.             }
  110.         }
  111.         return $this->render('vacancy/detail.html.twig', [
  112.             'vacancy' => $vacancy,
  113.             'form' => $form->createView(),
  114.             'recaptcha' => $this->recaptchaVersion,
  115.             'recaptchaPublic' => $this->recaptchaPublicKey,
  116.             'showApplyForm' => $showApplyForm
  117.         ]);
  118.     }
  119. }