mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 21:34:59 +00:00
move queries in repository
This commit is contained in:
@@ -24,6 +24,7 @@ namespace Chill\EventBundle\Controller;
|
||||
|
||||
use Chill\EventBundle\Entity\Participation;
|
||||
use Chill\EventBundle\Form\Type\PickEventType;
|
||||
use Chill\EventBundle\Repository\ParticipationRepository;
|
||||
use Chill\EventBundle\Security\Authorization\EventVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
@@ -342,6 +343,7 @@ class EventController extends Controller
|
||||
*
|
||||
* @param $person_id
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function listByPersonAction($person_id)
|
||||
{
|
||||
@@ -356,46 +358,27 @@ class EventController extends Controller
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
|
||||
$reachablesCircles = $this->authorizationHelper
|
||||
->getReachableCircles(
|
||||
$this->getUser(),
|
||||
new Role(EventVoter::SEE),
|
||||
$person->getCenter()
|
||||
);
|
||||
$reachablesCircles = $this->authorizationHelper->getReachableCircles(
|
||||
$this->getUser(),
|
||||
new Role(EventVoter::SEE),
|
||||
$person->getCenter()
|
||||
);
|
||||
|
||||
$total = $em
|
||||
->createQuery("
|
||||
SELECT COUNT (participation.id)
|
||||
FROM ChillEventBundle:Participation participation
|
||||
WHERE participation.person = :person_id
|
||||
")
|
||||
->setParameter(':person_id', $person_id)
|
||||
->getSingleScalarResult();
|
||||
$total = $em->getRepository('ChillEventBundle:Participation')->countByPerson($person_id);
|
||||
|
||||
/**
|
||||
* @var $paginatorFactory \Chill\MainBundle\Pagination\PaginatorFactory
|
||||
*/
|
||||
$paginatorFactory = $this->get('chill_main.paginator_factory');
|
||||
$paginator = $paginatorFactory->create($total);
|
||||
|
||||
$participations = $em
|
||||
->createQuery("
|
||||
SELECT participation
|
||||
FROM ChillEventBundle:Participation participation
|
||||
JOIN participation.event event
|
||||
WHERE participation.person = :person_id
|
||||
AND event.circle IN (:reachable_circles)
|
||||
ORDER BY event.date ASC
|
||||
")
|
||||
->setParameters(array(
|
||||
':person_id' => $person_id,
|
||||
':reachable_circles' => $reachablesCircles
|
||||
))
|
||||
->setFirstResult($paginator->getCurrentPage()->getFirstItemNumber())
|
||||
->setMaxResults($paginator->getItemsPerPage())
|
||||
->getResult()
|
||||
;
|
||||
|
||||
|
||||
$participations = $em->getRepository('ChillEventBundle:Participation')->findByPersonInCircle(
|
||||
$person_id,
|
||||
$reachablesCircles,
|
||||
$paginator->getCurrentPage()->getFirstItemNumber(),
|
||||
$paginator->getItemsPerPage()
|
||||
);
|
||||
|
||||
$privacyEvent = new PrivacyEvent($person, array(
|
||||
'element_class' => Participation::class,
|
||||
'action' => 'list'
|
||||
|
Reference in New Issue
Block a user