src/Controller/DefaultController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ClientEntity\NewsMessage;
  4. use App\Entity\Notification;
  5. use App\Entity\StaffMember;
  6. use App\Repository\SettingsRepository;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  9. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. /**
  14.  * Class DefaultController.
  15.  *
  16.  * @Security("is_granted('ROLE_USER')")
  17.  */
  18. class DefaultController extends AbstractController
  19. {
  20.     /**
  21.      * @Route("/", name="dashboard")
  22.      */
  23.     public function indexAction(EntityManagerInterface $em)
  24.     {
  25.         // replace this example code with whatever you need
  26.         return $this->render('dashboard.html.twig', [
  27.             'news' => $em->getRepository(NewsMessage::class)->findLatestNews($this->getUser()),
  28.         ]);
  29.     }
  30.     /**
  31.      * @Route("/about-us", name="about-us")
  32.      */
  33.     public function aboutUsAction()
  34.     {
  35.         return $this->render('default/about-us.html.twig');
  36.     }
  37.     /**
  38.      * @Route("/about-us/team", name="about-us.team")
  39.      */
  40.     public function teamAction()
  41.     {
  42.         /** @var StaffMember[] $staff */
  43.         $staff $this->getDoctrine()->getRepository(StaffMember::class)->createQueryBuilder('staff')
  44.             ->select('staff')
  45.             ->orderBy('staff.position')
  46.             ->addOrderBy('staff.surName')
  47.             ->addOrderBy('staff.firstName')
  48.             ->addOrderBy('staff.id')
  49.             ->getQuery()
  50.             ->useQueryCache(true)
  51.             ->getResult();
  52.         return $this->render('default/about-us/team.html.twig', [
  53.             'staff' => $staff,
  54.         ]);
  55.     }
  56.     /**
  57.      * @return BinaryFileResponse
  58.      *
  59.      * @Route("/about-us/team/photo/{member}", name="about-us.team.photo")
  60.      */
  61.     public function teamPhoto(StaffMember $member)
  62.     {
  63.         return $this->binaryFileResponse($member->getImage());
  64.     }
  65.     /**
  66.      * @return Response
  67.      *
  68.      * @Route("/terms-and-conditions", name="terms-and-conditions")
  69.      */
  70.     public function termsAction(SettingsRepository $repository)
  71.     {
  72.         return $this->binaryFileResponse($repository->getSettings()->getNonMemberTerms(), true);
  73.     }
  74.     /**
  75.      * @return Response
  76.      *
  77.      * @Route("/member-terms-and-conditions", name="member-terms-and-conditions")
  78.      */
  79.     public function memberTermsAction(SettingsRepository $repository)
  80.     {
  81.         return $this->binaryFileResponse($repository->getSettings()->getMemberTerms(), true);
  82.     }
  83.     /**
  84.      * @return Response
  85.      *
  86.      * @Route("/non-petroleum-terms-and-conditions", name="non-petroleum-terms-and-conditions")
  87.      */
  88.     public function nonPetroleumTermsAction(SettingsRepository $repository)
  89.     {
  90.         return $this->binaryFileResponse($repository->getSettings()->getNonPetroleumTerms(), true);
  91.     }
  92.     /**
  93.      * @Route("/todo", name="todo")
  94.      *
  95.      * @return Response
  96.      */
  97.     public function todoAction()
  98.     {
  99.         return new Response('This functionality has not yet been implemented.'200, [
  100.             'Content-Type' => 'text/plain',
  101.         ]);
  102.     }
  103.     /**
  104.      * @Route("/notification/{notification}", name="notification")
  105.      *
  106.      * @return RedirectResponse
  107.      */
  108.     public function notificationAction(Notification $notification)
  109.     {
  110.         if ($notification->getUser()->getId() !== $this->getUser()->getId()) {
  111.             throw $this->createNotFoundException();
  112.         }
  113.         if ($notification->isAutoRemove()) {
  114.             $this->getDoctrine()->getRepository(Notification::class)->removeByInternalCode($notification);
  115.         }
  116.         return $this->redirectToRoute($notification->getRoute(), $notification->getRouteParameters());
  117.     }
  118. }