src/Controller/Front/PolicyController.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Policy;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as Controller;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class PolicyController extends Controller
  9. {
  10. /**
  11. * @Route("/", name="front_policy_manage")
  12. *
  13. * @return Response
  14. */
  15. public function manage(Request $request)
  16. {
  17. $entityManager = $this->getDoctrine()->getManager();
  18. $policyRepository = $entityManager->getRepository(Policy::class);
  19. if ($this->getUser()->hasRole('ROLE_SUPER_ADMIN')) {
  20. return $this->redirect($this->generateUrl('back_policy_manage'));
  21. }
  22. $policies = [];
  23. foreach ($this->getUser()->getCustomers() as $customer) {
  24. $policy = $policyRepository->findOneByCustomer($customer);
  25. if ($policy) {
  26. $policies[] = $policy;
  27. }
  28. }
  29. return $this->render('front/policy/manage.html.twig',
  30. [
  31. 'policies' => $policies,
  32. ]);
  33. }
  34. }