src/Controller/HomeController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Validator\Constraints\DateTime;
  9. use App\Utils\Constants;
  10. use App\Utils\Breadcrumbs;
  11. use App\Utils\Utils;
  12. use App\Entity\Setting;
  13. use App\Entity\Organisation;
  14. use App\Entity\TrainingMaterial;
  15. use App\Entity\FAQ;
  16. use App\Entity\SupportQuery;
  17. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  18. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  19. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  20. /**
  21. * Require ROLE_USER for *every* controller method in this class.
  22. *
  23. * @IsGranted("ROLE_USER")
  24. */
  25. class HomeController extends AbstractController
  26. {
  27. /**
  28. * @Route("/home", name="home")
  29. * @IsGranted("ROLE_USER")
  30. */
  31. public function index(Request $request, \Swift_Mailer $mailer)
  32. {
  33. // $hasAccess = $this->isGranted('ROLE_USER');
  34. // $this->denyAccessUnlessGranted('ROLE_USER');
  35. if($this->isGranted('ROLE_SUPER_USER')) {
  36. $this->addFlash('error','Access Denied');
  37. return $this->redirectToRoute('error');
  38. }
  39. $user = $this->getUser();
  40. if($user->getOrganisations()->count() <= 0) {
  41. $this->addFlash('error','Organisation not found.');
  42. return $this->redirectToRoute('error');
  43. }
  44. $orgId = $user->getOrganisations()->first()->getId();
  45. $org = $user->getOrganisations()->first();
  46. $constants = new Constants();
  47. $firstBreadcrumb = Breadcrumbs::getFirstBreadcrumb($this->getDoctrine(), $user, $request);
  48. $backLinkLabel = "Home";
  49. $backLink = "/home";
  50. $breadcrumbs[$firstBreadcrumb] = "/";
  51. $breadcrumbs[$backLinkLabel] = $backLink;
  52. $calink = Utils::buildCASwitchLink($this);
  53. $culink = Utils::buildCULink($this, "/home");
  54. return $this->render('cu/home.html.twig', array(
  55. // 'form' => $form->createView(),
  56. 'page_heading' => $backLinkLabel,
  57. 'constants' => $constants,
  58. 'breadcrumbs' => $breadcrumbs,
  59. 'user' => $user,
  60. 'backlink' => $backLink,
  61. 'backlink_label' => $backLinkLabel,
  62. 'calink' => $calink,
  63. 'culink' => $culink,
  64. ));
  65. }
  66. }