lib/composer/ProjectBundle/src/VisualMedia/ProjectBundle/Controller/ProjectController.php line 31

Open in your IDE?
  1. <?php
  2. /**
  3. * Project Controller
  4. *
  5. * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
  6. */
  7. namespace VisualMedia\ProjectBundle\Controller;
  8. use Exception;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use VisualMedia\LisaBundle\Component\ManagerData;
  12. use VisualMedia\LisaBundle\Controller\BaseController;
  13. use VisualMedia\PageBundle\Manager\BasePageManager;
  14. use VisualMedia\ProjectBundle\Entity\BaseProject;
  15. use VisualMedia\ProjectBundle\Manager\BaseProjectManager;
  16. use VisualMedia\ProjectBundle\Provider\ProjectLayoutProvider;
  17. /**
  18. * Project Controller
  19. */
  20. class ProjectController extends BaseController
  21. {
  22. /**
  23. * @param Request $request
  24. * @return Response
  25. */
  26. public function indexAction(Request $request): Response
  27. {
  28. $translator = $this->get('translator');
  29. $title = $translator->trans(sprintf('%s.title', ManageProjectController::KEY), [], 'pages');
  30. $pageManager = $this->get(BasePageManager::class);
  31. $page = $pageManager->getOrCreatePage(ManageProjectController::KEY, array(
  32. 'title' => $title,
  33. 'published' => true,
  34. 'indexable' => true,
  35. 'browserTitle' => $title,
  36. 'metaDescription' => sprintf('%s.', $title),
  37. ));
  38. $projectManager = $this->get(BaseProjectManager::class);
  39. $projects = $projectManager->getIndex(new ManagerData(array(
  40. $projectManager::OPTION_PUBLISHED => true,
  41. ), array('ordering' => 'ASC')));
  42. return $this->render('@VisualMediaProject/Project/index.html.twig', array(
  43. 'browser_title' => $page->browserTitle,
  44. 'meta_description' => $page->metaDescription,
  45. 'meta_keywords' => $page->metaKeywords,
  46. 'indexable' => $page->indexable,
  47. 'projects' => $projects,
  48. 'page' => $page,
  49. ));
  50. }
  51. /**
  52. * @param Request $request
  53. * @param string $slug
  54. * @return Response
  55. */
  56. public function viewBySlugAction(Request $request, string $slug = null): Response
  57. {
  58. $translator = $this->get('translator');
  59. $layoutProvider = $this->get(ProjectLayoutProvider::class);
  60. $manager = $this->get(BaseProjectManager::class);
  61. if (null === $project = $manager->getFirst(new ManagerData(array($manager::OPTION_SLUG => $slug)))) {
  62. throw new Exception($translator->trans('project.not_found', [], 'exception'), 404);
  63. }
  64. elseif (!$project->getPublished()) {
  65. throw new Exception($translator->trans('project.gone', [], 'exception'), 410);
  66. }
  67. return $this->render($project->getLayout(), array(
  68. 'browser_title' => $project->getBrowserTitle(),
  69. 'meta_description' => $project->getMetaDescription(),
  70. 'meta_keywords' => $project->getMetaKeywords(),
  71. 'indexable' => $project->getIndexable(),
  72. 'project' => $project,
  73. ));
  74. }
  75. /**
  76. * @param Request $request
  77. * @param integer $count
  78. * @return Response
  79. */
  80. public function ssiAction(Request $request, ?int $count = null): Response
  81. {
  82. $manager = $this->get(BaseProjectManager::class);
  83. $projects = $manager->getIndex(new ManagerData(array(
  84. $manager::OPTION_PUBLISHED => true,
  85. ), array('ordering' => $manager::ORDER_DIR_ASC), $count));
  86. return $this->render('@VisualMediaProject/Project/ssi.html.twig', array(
  87. 'projects' => $projects,
  88. ));
  89. }
  90. }