src/UI/WebBundle/Controller/Common/CommonController.php line 108

Open in your IDE?
  1. <?php
  2. namespace Whater\UI\WebBundle\Controller\Common;
  3. use Whater\UI\WebBundle\Controller\AbstractBusController;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Whater\Application\UseCase\User\CommandRequest\ContactFormCommand;
  8. use Whater\Infrastructure\UserBundle\Form\Type\ContactFormType;
  9. /**
  10. * @Route("")
  11. */
  12. class CommonController extends AbstractBusController
  13. {
  14. /**
  15. * @Route("/", name="web_init", defaults={"_format" = "html"})
  16. */
  17. public function initAction(Request $request)
  18. {
  19. // If a user is authenticated redirect to ...
  20. // if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  21. // // Redirect...
  22. // return new RedirectResponse($this->router()->generate('web_app_user_dashboard', array(), true));
  23. // }
  24. // Go to default organization homepage
  25. return new RedirectResponse($this->router()->generate('web_homepage', array(), true));
  26. }
  27. /**
  28. * @Route("/home/{userType}", name="web_homepage", defaults={"_format" = "html", "userType" = "user"})
  29. */
  30. public function homeAction(Request $request, string $userType = null)
  31. {
  32. return $this->render('Public/homepage.html.twig', [
  33. 'userType' => $userType
  34. ]);
  35. }
  36. /**
  37. * @Route("/{userType}/terms", name="web_terms", defaults={"_format" = "html", "userType" = "user"})
  38. */
  39. public function termsAction(Request $request, string $userType = null)
  40. {
  41. return $this->render('Public/terms.html.twig', [
  42. 'userType' => $userType
  43. ]);
  44. }
  45. /**
  46. * @Route("/{userType}/whater_for_users", name="web_whater_for_users", defaults={"_format" = "html", "userType" = "user"})
  47. */
  48. public function whaterForUsersAction(Request $request, string $userType = null)
  49. {
  50. return $this->render('Public/whater_for_users.html.twig', [
  51. 'userType' => $userType
  52. ]);
  53. }
  54. /**
  55. * @Route("/{userType}/whater_for_professionals", name="web_whater_for_professionals", defaults={"_format" = "html", "userType" = "user"})
  56. */
  57. public function whaterForProfessionalsAction(Request $request, string $userType = null)
  58. {
  59. return $this->render('Public/whater_for_professionals.html.twig', [
  60. 'userType' => $userType
  61. ]);
  62. }
  63. /**
  64. * @Route("/{userType}/whater_for_managers", name="web_whater_for_managers", defaults={"_format" = "html", "userType" = "user"})
  65. */
  66. public function whaterForManagersAction(Request $request, string $userType = null)
  67. {
  68. return $this->render('Public/whater_for_managers.html.twig', [
  69. 'userType' => $userType
  70. ]);
  71. }
  72. /**
  73. * @Route("/{userType}/whatiswhater", name="web_whatiswhater", defaults={"_format" = "html", "userType" = "user"})
  74. */
  75. public function whatiswhaterAction(Request $request, string $userType = null)
  76. {
  77. return $this->render('Public/whatiswhater.html.twig', [
  78. 'userType' => $userType
  79. ]);
  80. }
  81. /**
  82. * @Route("/{userType}/faqs", name="web_faqs", defaults={"_format" = "html", "userType" = "user"})
  83. */
  84. public function faqsAction(Request $request, string $userType = null)
  85. {
  86. return $this->render('Public/faqs.html.twig', [
  87. 'userType' => $userType
  88. ]);
  89. }
  90. /**
  91. * @Route("/{userType}/privacitypolicy", name="web_privacity_policy", defaults={"_format" = "html", "userType" = "user"})
  92. */
  93. public function privacityAction(Request $request, string $userType = null)
  94. {
  95. return $this->render('Public/privacity_policy.html.twig', [
  96. 'userType' => $userType
  97. ]);
  98. }
  99. /**
  100. * @Route("/{userType}/contact", name="web_contact", defaults={"_format" = "html", "userType" = "user"})
  101. */
  102. public function contactAction(Request $request, string $userType = null)
  103. {
  104. $grantUser = $this->getGrantedUser();
  105. $form = $this->getFormFactory()->create(
  106. ContactFormType::class,
  107. ContactFormCommand::convertToDTO(),
  108. array(
  109. 'action' => $this->router()->generate('web_contact', array(), true),
  110. 'method' => 'POST',
  111. 'csrf_protection' => true
  112. )
  113. );
  114. if ('POST' === $request->getMethod()) {
  115. $form->handleRequest($request);
  116. if ($form->isSubmitted() && $form->isValid()) {
  117. $this->handle(ContactFormCommand::fromDTO($form->getData(), $grantUser));
  118. $this->setFlash('success', $this->translator()->trans('contact_form.success'));
  119. } else {
  120. $this->setFlash('error', $this->translator()->trans('contact_form.error'));
  121. }
  122. }
  123. return $this->render(
  124. 'Public/contact.html.twig',
  125. [
  126. 'form' => $form->createView(),
  127. 'userType' => $userType
  128. ]
  129. );
  130. }
  131. /**
  132. * @Route("/bewhater", name="web_bewhater", defaults={"_format" = "html", "userType" = "user"})
  133. */
  134. public function bewhaterAction(Request $request)
  135. {
  136. // If a user is authenticated redirect to ...
  137. $bewhatherUrl = $this->parameterBag()->get('bewhater_redirect');
  138. if ($bewhatherUrl) {
  139. return new RedirectResponse($bewhatherUrl);
  140. } else {
  141. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  142. }
  143. }
  144. }