listByPerson, display only events for current circle

This commit is contained in:
Tchama 2019-01-17 14:33:31 +01:00
parent d07cbb15da
commit 42c9a24472
2 changed files with 18 additions and 1 deletions

View File

@ -3,6 +3,8 @@
namespace Chill\EventBundle\Controller; namespace Chill\EventBundle\Controller;
use Chill\EventBundle\Entity\Participation; use Chill\EventBundle\Entity\Participation;
use Chill\EventBundle\Security\Authorization\EventVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Privacy\PrivacyEvent; use Chill\PersonBundle\Privacy\PrivacyEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -27,14 +29,20 @@ class EventController extends Controller
*/ */
protected $eventDispatcher; protected $eventDispatcher;
/**
* @var AuthorizationHelper
*/
protected $authorizationHelper;
/** /**
* EventController constructor. * EventController constructor.
* *
* @param EventDispatcherInterface $eventDispatcher * @param EventDispatcherInterface $eventDispatcher
*/ */
public function __construct(EventDispatcherInterface $eventDispatcher) public function __construct(EventDispatcherInterface $eventDispatcher, AuthorizationHelper $authorizationHelper)
{ {
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
$this->authorizationHelper = $authorizationHelper;
} }
@ -259,6 +267,11 @@ class EventController extends Controller
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$reachablesCircles = $this->authorizationHelper
->getReachableCircles(
$this->getUser(),
new Role(EventVoter::SEE),
$person->getCenter()
); );
$total = $em $total = $em
@ -278,10 +291,13 @@ class EventController extends Controller
->createQuery(" ->createQuery("
SELECT participation SELECT participation
FROM ChillEventBundle:Participation participation FROM ChillEventBundle:Participation participation
JOIN participation.event event
WHERE participation.person = :person_id WHERE participation.person = :person_id
AND event.circle IN (:reachable_circles)
") ")
->setParameters(array( ->setParameters(array(
':person_id' => $person_id, ':person_id' => $person_id,
':reachable_circles' => $reachablesCircles
)) ))
->setFirstResult($paginator->getCurrentPage()->getFirstItemNumber()) ->setFirstResult($paginator->getCurrentPage()->getFirstItemNumber())
->setMaxResults($paginator->getItemsPerPage()) ->setMaxResults($paginator->getItemsPerPage())

View File

@ -2,4 +2,5 @@ services:
Chill\EventBundle\Controller\EventController: Chill\EventBundle\Controller\EventController:
arguments: arguments:
$eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface' $eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface'
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
tags: ['controller.service_arguments'] tags: ['controller.service_arguments']