get('chill.person.repository.person') ->find($id); if (null === $person) { throw $this->createNotFoundException('The person is not found'); } $this->denyAccessUnlessGranted(PersonVoter::SEE, $person); /* @var $authorizationHelper \Chill\MainBundle\Security\Authorization\AuthorizationHelper */ $authorizationHelper = $this->get('chill.main.security.' . 'authorization.helper'); $circles = $authorizationHelper->getReachableCircles( $this->getUser(), new Role(ConsultationVoter::SEE), $person->getCenter() ); // create a query which take circles into account $consultations = $this->getDoctrine()->getManager() ->createQuery('SELECT c FROM ChillHealthBundle:Consultation c ' . 'WHERE c.patient = :person AND c.circle IN(:circles) ' . 'ORDER BY c.date DESC') ->setParameter('person', $person) ->setParameter('circles', $circles) ->getResult(); return $this->render('ChillHealthBundle:Consultation:list.html.twig', [ 'person' => $person, 'consultations' => $consultations, ]); } }