diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 38ca08d1f..fe515918a 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -72,6 +72,7 @@ class ActivityController extends AbstractController { $em = $this->getDoctrine()->getManager(); $view = null; + // TODO: add pagination [$person, $accompanyingPeriod] = $this->getEntity($request); @@ -80,10 +81,9 @@ class ActivityController extends AbstractController ->getReachableCircles($this->getUser(), new Role('CHILL_ACTIVITY_SEE'), $person->getCenter()); - $activities = $em->getRepository('ChillActivityBundle:Activity')->findBy( - ['person' => $person, 'scope' => $reachableScopes], - ['date' => 'DESC'], - ); + $activities = $em->getRepository(Activity::class) + ->findByPersonImplied($person, $reachableScopes) + ; $event = new PrivacyEvent($person, array( 'element_class' => Activity::class, diff --git a/src/Bundle/ChillActivityBundle/Menu/MenuBuilder.php b/src/Bundle/ChillActivityBundle/Menu/MenuBuilder.php index f11aa28bc..df7620f30 100644 --- a/src/Bundle/ChillActivityBundle/Menu/MenuBuilder.php +++ b/src/Bundle/ChillActivityBundle/Menu/MenuBuilder.php @@ -67,18 +67,6 @@ class MenuBuilder implements LocalMenuBuilderInterface 'order' => 201 ]); } - - if ($this->authorizationHelper->userHasAccess($user, $person, $roleAdd)) { - $menu->addChild($this->translator->trans('Add a new activity'), [ - 'route' => 'chill_activity_activity_new', - 'routeParameters' => [ - 'person_id' => $person->getId() - ] - ]) - ->setExtras([ - 'order' => 200 - ]); - } } public static function getMenuIds(): array diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php index b5155d4c9..340481ca9 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php @@ -38,5 +38,30 @@ class ActivityRepository extends ServiceEntityRepository { parent::__construct($registry, Activity::class); } - + + public function findByPersonImplied($person, array $scopes, $orderBy = [ 'date' => 'DESC'], $limit = 100, $offset = 0) + { + $qb = $this->createQueryBuilder('a'); + $qb->select('a'); + + $qb + // TODO add acl + //->where($qb->expr()->in('a.scope', ':scopes')) + //->setParameter('scopes', $scopes) + ->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('a.person', ':person'), + ':person MEMBER OF a.persons' + ) + ) + ->setParameter('person', $person) + ; + + foreach ($orderBy as $k => $dir) { + $qb->addOrderBy('a.'.$k, $dir); + } + + return $qb->getQuery() + ->getResult(); + } } diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig index 56a7c96b4..5e010bc87 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig @@ -99,7 +99,7 @@