From d9c1f52894f50d20da556aefcc5807a0d00a03bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julien=20Fastr=C3=A9?=
Date: Tue, 29 Jun 2021 20:51:08 +0200
Subject: [PATCH] improve activity
---
.../Controller/ActivityController.php | 8 ++---
.../ChillActivityBundle/Menu/MenuBuilder.php | 12 -------
.../Repository/ActivityRepository.php | 27 +++++++++++++-
.../Resources/views/Activity/edit.html.twig | 2 +-
.../Resources/views/Activity/list.html.twig | 36 ++++++++++++++-----
.../Resources/views/Activity/new.html.twig | 2 +-
.../Resources/views/Activity/show.html.twig | 2 +-
7 files changed, 60 insertions(+), 29 deletions(-)
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 @@
-
+
{{ form_end(edit_form) }}
diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/list.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/list.html.twig
index c84d61009..a4d75917e 100644
--- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/list.html.twig
+++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/list.html.twig
@@ -17,7 +17,7 @@
{% else %}
-