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/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index 3ad204f18..8c8fb45a9 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -224,7 +224,8 @@ class ActivityType extends AbstractType if ($activityType->isVisible('comment')) { $builder->add('comment', CommentType::class, [ - 'label' => $activityType->getLabel('comment'), + 'label' => empty($activityType->getLabel('comment')) + ? 'activity.comment' : $activityType->getLabel('comment'), 'required' => $activityType->isRequired('comment'), ]); } diff --git a/src/Bundle/ChillActivityBundle/Menu/MenuBuilder.php b/src/Bundle/ChillActivityBundle/Menu/MenuBuilder.php deleted file mode 100644 index f11aa28bc..000000000 --- a/src/Bundle/ChillActivityBundle/Menu/MenuBuilder.php +++ /dev/null @@ -1,88 +0,0 @@ - - */ -class MenuBuilder implements LocalMenuBuilderInterface -{ - /** - * - * @var TokenStorageInterface - */ - protected $tokenStorage; - - /** - * - * @var TranslatorInterface - */ - protected $translator; - - /** - * - * @var AuthorizationHelper - */ - protected $authorizationHelper; - - public function __construct( - TokenStorageInterface $tokenStorage, - TranslatorInterface $translator, - AuthorizationHelper $authorizationHelper - ) { - $this->tokenStorage = $tokenStorage; - $this->translator = $translator; - $this->authorizationHelper = $authorizationHelper; - } - - - public function buildMenu($menuId, MenuItem $menu, array $parameters) - { - /* @var $person \Chill\PersonBundle\Entity\Person */ - $person = $parameters['person']; - $user = $this->tokenStorage->getToken()->getUser(); - $roleSee = new Role(ActivityVoter::SEE); - $roleAdd = new Role(ActivityVoter::CREATE); - - if ($this->authorizationHelper->userHasAccess($user, $person, $roleSee)) { - $menu->addChild($this->translator->trans('Activity list'), [ - 'route' => 'chill_activity_activity_list', - 'routeParameters' => [ - 'person_id' => $person->getId() - ] - ]) - ->setExtras([ - '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 - { - return [ 'person' ]; - } -} diff --git a/src/Bundle/ChillActivityBundle/Menu/PersonMenuBuilder.php b/src/Bundle/ChillActivityBundle/Menu/PersonMenuBuilder.php index 7c8092227..e44a0f561 100644 --- a/src/Bundle/ChillActivityBundle/Menu/PersonMenuBuilder.php +++ b/src/Bundle/ChillActivityBundle/Menu/PersonMenuBuilder.php @@ -15,8 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -namespace Chill\ActivityBundle\Menu; - +namespace Chill\ActivityBundle\Menu; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Knp\Menu\MenuItem; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -65,15 +64,6 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface ->setExtra('order', 201) ; } - if ($this->authorizationChecker->isGranted(ActivityVoter::CREATE, $person)) { - $menu->addChild( - $this->translator->trans('Add a new activity'), [ - 'route' => 'chill_activity_activity_new', - 'routeParameters' => [ 'person_id' => $person->getId() ], - ]) - ->setExtra('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/editAccompanyingCourse.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig index a40b1d721..017f2fd40 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig @@ -10,6 +10,7 @@ {% endblock %} {% block js %} + {{ parent() }} {{ encore_entry_link_tags('async_upload') }}