lib/composer/VacancyBundle/src/VisualMedia/VacancyBundle/Controller/VacancyController.php line 76

Open in your IDE?
  1. <?php
  2. /**
  3. * Vacancy Controller
  4. *
  5. * @author Gideon J. Oudhuis <g.oudhuis@visualmedia.nl>
  6. */
  7. namespace VisualMedia\VacancyBundle\Controller;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use VisualMedia\LisaBundle\Component\ManagerData;
  11. use VisualMedia\LisaBundle\Controller\BaseController;
  12. use VisualMedia\PageBundle\Manager\BasePageManager;
  13. use VisualMedia\VacancyBundle\Manager\BaseVacancyManager;
  14. use VisualMedia\VacancyBundle\Provider\VacancyLayoutProvider;
  15. /**
  16. * Vacancy Controller
  17. */
  18. class VacancyController extends BaseController
  19. {
  20. /**
  21. * @param Request $request
  22. * @return Response
  23. */
  24. public function indexAction(Request $request): Response
  25. {
  26. $translator = $this->get('translator');
  27. $title = $translator->trans(sprintf('%s.title', ManageVacancyController::KEY), [], 'pages');
  28. $pageManager = $this->get(BasePageManager::class);
  29. $page = $pageManager->getOrCreatePage(ManageVacancyController::KEY, array(
  30. 'title' => $title,
  31. 'published' => true,
  32. 'indexable' => true,
  33. 'browserTitle' => $title,
  34. 'metaDescription' => sprintf('%s.', $title),
  35. ));
  36. $vacancyManager = $this->get(BaseVacancyManager::class);
  37. $vacancies = $vacancyManager->getIndex(new ManagerData(array(
  38. $vacancyManager::OPTION_PUBLISHED => true,
  39. ), array('created' => 'DESC')));
  40. return $this->render('@VisualMediaVacancy/Vacancy/index.html.twig', array(
  41. 'browser_title' => $page->browserTitle,
  42. 'meta_description' => $page->metaDescription,
  43. 'meta_keywords' => $page->metaKeywords,
  44. 'indexable' => $page->indexable,
  45. 'vacancies' => $vacancies,
  46. 'page' => $page,
  47. ));
  48. }
  49. /**
  50. * @param Request $request
  51. * @param string $slug
  52. * @return Response
  53. */
  54. public function viewAction(Request $request, string $slug): Response
  55. {
  56. $translator = $this->get('translator');
  57. $layoutProvider = $this->get(VacancyLayoutProvider::class);
  58. $manager = $this->get(BaseVacancyManager::class);
  59. if (null === $vacancy = $manager->getFirst(new ManagerData(array($manager::OPTION_SLUG => $slug)))) {
  60. throw new Exception($translator->trans('vacancy.not_found', [], 'exception'), 404);
  61. }
  62. elseif (!$vacancy->getPublished()) {
  63. throw new Exception($translator->trans('vacancy.gone', [], 'exception'), 410);
  64. }
  65. return $this->render($vacancy->getLayout(), array(
  66. 'browser_title' => $vacancy->getBrowserTitle(),
  67. 'meta_description' => $vacancy->getMetaDescription(),
  68. 'meta_keywords' => $vacancy->getMetaKeywords(),
  69. 'indexable' => $vacancy->getIndexable(),
  70. 'vacancy' => $vacancy,
  71. ));
  72. }
  73. }