<?php
namespace App\Controller\Front;
use App\Entity\Policy;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class PolicyController extends Controller
{
/**
* @Route("/", name="front_policy_manage")
*
* @return Response
*/
public function manage(Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$policyRepository = $entityManager->getRepository(Policy::class);
if ($this->getUser()->hasRole('ROLE_SUPER_ADMIN')) {
return $this->redirect($this->generateUrl('back_policy_manage'));
}
$policies = [];
foreach ($this->getUser()->getCustomers() as $customer) {
$policy = $policyRepository->findOneByCustomer($customer);
if ($policy) {
$policies[] = $policy;
}
}
return $this->render('front/policy/manage.html.twig',
[
'policies' => $policies,
]);
}
}