<?php
namespace Whater\UI\WebBundle\Controller\Common;
use Whater\UI\WebBundle\Controller\AbstractBusController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Whater\Application\UseCase\User\CommandRequest\ContactFormCommand;
use Whater\Infrastructure\UserBundle\Form\Type\ContactFormType;
/**
* @Route("")
*/
class CommonController extends AbstractBusController
{
/**
* @Route("/", name="web_init", defaults={"_format" = "html"})
*/
public function initAction(Request $request)
{
// If a user is authenticated redirect to ...
// if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
// // Redirect...
// return new RedirectResponse($this->router()->generate('web_app_user_dashboard', array(), true));
// }
// Go to default organization homepage
return new RedirectResponse($this->router()->generate('web_homepage', array(), true));
}
/**
* @Route("/home/{userType}", name="web_homepage", defaults={"_format" = "html", "userType" = "user"})
*/
public function homeAction(Request $request, string $userType = null)
{
return $this->render('Public/homepage.html.twig', [
'userType' => $userType
]);
}
/**
* @Route("/{userType}/terms", name="web_terms", defaults={"_format" = "html", "userType" = "user"})
*/
public function termsAction(Request $request, string $userType = null)
{
return $this->render('Public/terms.html.twig', [
'userType' => $userType
]);
}
/**
* @Route("/{userType}/whater_for_users", name="web_whater_for_users", defaults={"_format" = "html", "userType" = "user"})
*/
public function whaterForUsersAction(Request $request, string $userType = null)
{
return $this->render('Public/whater_for_users.html.twig', [
'userType' => $userType
]);
}
/**
* @Route("/{userType}/whater_for_professionals", name="web_whater_for_professionals", defaults={"_format" = "html", "userType" = "user"})
*/
public function whaterForProfessionalsAction(Request $request, string $userType = null)
{
return $this->render('Public/whater_for_professionals.html.twig', [
'userType' => $userType
]);
}
/**
* @Route("/{userType}/whater_for_managers", name="web_whater_for_managers", defaults={"_format" = "html", "userType" = "user"})
*/
public function whaterForManagersAction(Request $request, string $userType = null)
{
return $this->render('Public/whater_for_managers.html.twig', [
'userType' => $userType
]);
}
/**
* @Route("/{userType}/whatiswhater", name="web_whatiswhater", defaults={"_format" = "html", "userType" = "user"})
*/
public function whatiswhaterAction(Request $request, string $userType = null)
{
return $this->render('Public/whatiswhater.html.twig', [
'userType' => $userType
]);
}
/**
* @Route("/{userType}/faqs", name="web_faqs", defaults={"_format" = "html", "userType" = "user"})
*/
public function faqsAction(Request $request, string $userType = null)
{
return $this->render('Public/faqs.html.twig', [
'userType' => $userType
]);
}
/**
* @Route("/{userType}/privacitypolicy", name="web_privacity_policy", defaults={"_format" = "html", "userType" = "user"})
*/
public function privacityAction(Request $request, string $userType = null)
{
return $this->render('Public/privacity_policy.html.twig', [
'userType' => $userType
]);
}
/**
* @Route("/{userType}/contact", name="web_contact", defaults={"_format" = "html", "userType" = "user"})
*/
public function contactAction(Request $request, string $userType = null)
{
$grantUser = $this->getGrantedUser();
$form = $this->getFormFactory()->create(
ContactFormType::class,
ContactFormCommand::convertToDTO(),
array(
'action' => $this->router()->generate('web_contact', array(), true),
'method' => 'POST',
'csrf_protection' => true
)
);
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->handle(ContactFormCommand::fromDTO($form->getData(), $grantUser));
$this->setFlash('success', $this->translator()->trans('contact_form.success'));
} else {
$this->setFlash('error', $this->translator()->trans('contact_form.error'));
}
}
return $this->render(
'Public/contact.html.twig',
[
'form' => $form->createView(),
'userType' => $userType
]
);
}
/**
* @Route("/bewhater", name="web_bewhater", defaults={"_format" = "html", "userType" = "user"})
*/
public function bewhaterAction(Request $request)
{
// If a user is authenticated redirect to ...
$bewhatherUrl = $this->parameterBag()->get('bewhater_redirect');
if ($bewhatherUrl) {
return new RedirectResponse($bewhatherUrl);
} else {
return new RedirectResponse($this->router()->generate('web_init', array(), true));
}
}
}