<?php
namespace App\Controller;
use App\Entity\ClientEntity\NewsMessage;
use App\Entity\Notification;
use App\Entity\StaffMember;
use App\Repository\SettingsRepository;
use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class DefaultController.
*
* @Security("is_granted('ROLE_USER')")
*/
class DefaultController extends AbstractController
{
/**
* @Route("/", name="dashboard")
*/
public function indexAction(EntityManagerInterface $em)
{
// replace this example code with whatever you need
return $this->render('dashboard.html.twig', [
'news' => $em->getRepository(NewsMessage::class)->findLatestNews($this->getUser()),
]);
}
/**
* @Route("/about-us", name="about-us")
*/
public function aboutUsAction()
{
return $this->render('default/about-us.html.twig');
}
/**
* @Route("/about-us/team", name="about-us.team")
*/
public function teamAction()
{
/** @var StaffMember[] $staff */
$staff = $this->getDoctrine()->getRepository(StaffMember::class)->createQueryBuilder('staff')
->select('staff')
->orderBy('staff.position')
->addOrderBy('staff.surName')
->addOrderBy('staff.firstName')
->addOrderBy('staff.id')
->getQuery()
->useQueryCache(true)
->getResult();
return $this->render('default/about-us/team.html.twig', [
'staff' => $staff,
]);
}
/**
* @return BinaryFileResponse
*
* @Route("/about-us/team/photo/{member}", name="about-us.team.photo")
*/
public function teamPhoto(StaffMember $member)
{
return $this->binaryFileResponse($member->getImage());
}
/**
* @return Response
*
* @Route("/terms-and-conditions", name="terms-and-conditions")
*/
public function termsAction(SettingsRepository $repository)
{
return $this->binaryFileResponse($repository->getSettings()->getNonMemberTerms(), true);
}
/**
* @return Response
*
* @Route("/member-terms-and-conditions", name="member-terms-and-conditions")
*/
public function memberTermsAction(SettingsRepository $repository)
{
return $this->binaryFileResponse($repository->getSettings()->getMemberTerms(), true);
}
/**
* @return Response
*
* @Route("/non-petroleum-terms-and-conditions", name="non-petroleum-terms-and-conditions")
*/
public function nonPetroleumTermsAction(SettingsRepository $repository)
{
return $this->binaryFileResponse($repository->getSettings()->getNonPetroleumTerms(), true);
}
/**
* @Route("/todo", name="todo")
*
* @return Response
*/
public function todoAction()
{
return new Response('This functionality has not yet been implemented.', 200, [
'Content-Type' => 'text/plain',
]);
}
/**
* @Route("/notification/{notification}", name="notification")
*
* @return RedirectResponse
*/
public function notificationAction(Notification $notification)
{
if ($notification->getUser()->getId() !== $this->getUser()->getId()) {
throw $this->createNotFoundException();
}
if ($notification->isAutoRemove()) {
$this->getDoctrine()->getRepository(Notification::class)->removeByInternalCode($notification);
}
return $this->redirectToRoute($notification->getRoute(), $notification->getRouteParameters());
}
}