src/Controller/JobController.php line 66

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Elements.at New Media Solutions GmbH
  4.  *
  5.  */
  6. namespace App\Controller;
  7. use App\Service\ApplicationService;
  8. use App\Service\JobService;
  9. use Elements\Bundle\HashCashBundle\Service\HashCashService;
  10. use Pimcore\Model\DataObject\Job;
  11. use Pimcore\Model\DataObject\JobTeam;
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  16. class JobController extends AbstractController
  17. {
  18.     public function overviewAction(Request $requestJobService $jobService): Response
  19.     {
  20.         $categories $this->document->getEditable('categories') && method_exists($this->document->getEditable('categories'), 'getElements') ? $this->document->getEditable('categories')->getElements() : [];
  21.         return $this->render('job/overview.html.twig', [
  22.             'categories' => $jobService->getCategoryTabs(new Job\Listing(), null$categories),
  23.         ]);
  24.     }
  25.     public function detailAction(Request $requestApplicationService $serviceHashCashService $hashCashService): Response
  26.     {
  27.         \Pimcore\Cache::disable();
  28.         $job Job::getById($request->get('id'));
  29.         if (!$job instanceof Job || !$job->isPublished() || !$job->getTitle($request->getLocale())) {
  30.             throw new NotFoundHttpException();
  31.         }
  32.         $returnArray = [ 'job' => $job ];
  33.         if ($request->getMethod() == 'POST') {
  34.             if ($hashCashService->validateProcessFrom()) {
  35.                 $applicationResult $service->handleApplication($request$job);
  36.                 if ($applicationResult instanceof RedirectResponse) {
  37.                     return $applicationResult;
  38.                 } else {
  39.                     $returnArray['errors'] = $applicationResult;
  40.                 }
  41.             }
  42.         }
  43.         return $this->render('job/detail.html.twig'$returnArray);
  44.     }
  45.     public function teamOverviewAction(Request $request): Response
  46.     {
  47.         $teams = new JobTeam\Listing();
  48.         $teams->setOrderKey('sort');
  49.         $teams->setOrder('ASC');
  50.         return $this->render('job/team-overview.html.twig', [ 'teams' => $teams ]);
  51.     }
  52.     public function teamDetailAction(Request $requestJobService $jobService): Response
  53.     {
  54.         $id $request->get('id');
  55.         $team JobTeam::getById($id);
  56.         if (!$team instanceof JobTeam || !$team->isPublished() || !$team->getTitle($request->getLocale())) {
  57.             throw new NotFoundHttpException();
  58.         }
  59.         $jobs = new Job\Listing();
  60.         $jobs->addConditionParam('team__id = :id', [ 'id' => $id ]);
  61.         $teams = new JobTeam\Listing();
  62.         $teams->addConditionParam('o_id != :id', [ 'id' => $id ]);
  63.         return $this->render('job/team-detail.html.twig', [
  64.             'team' => $team,
  65.             'teams' => $teams,
  66.             'categories' => $jobService->getCategoryTabs($jobs$id),
  67.             'jobCount' => $jobs->getCount(),
  68.         ]);
  69.     }
  70.     public function initiativeApplicationAction(Request $requestApplicationService $serviceHashCashService $hashCashService): Response
  71.     {
  72.         $returnArray = [];
  73.         if ($request->getMethod() == 'POST') {
  74.             if ($hashCashService->validateProcessFrom()) {
  75.                 $applicationResult $service->handleApplication($requestnull$this->document->getEditable('initiativeApplicationMail'));
  76.                 if ($applicationResult instanceof RedirectResponse) {
  77.                     return $applicationResult;
  78.                 } else {
  79.                     $returnArray['errors'] = $applicationResult;
  80.                 }
  81.             }
  82.         }
  83.         return $this->render('job/initiative-application.html.twig'$returnArray);
  84.     }
  85. }