diff --git a/.changes/unreleased/Feature-20250808-120802.yaml b/.changes/unreleased/Feature-20250808-120802.yaml new file mode 100644 index 000000000..50d1eb8ba --- /dev/null +++ b/.changes/unreleased/Feature-20250808-120802.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: Create invitation list in user menu +time: 2025-08-08T12:08:02.446361367+02:00 +custom: + Issue: "385" + SchemaChange: No schema change diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 94db03b1f..ae8114ea7 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -266,7 +266,7 @@ class CalendarController extends AbstractController } if (!$this->getUser() instanceof User) { - throw new UnauthorizedHttpException('you are not an user'); + throw new UnauthorizedHttpException('you are not a user'); } $view = '@ChillCalendar/Calendar/listByUser.html.twig'; diff --git a/src/Bundle/ChillCalendarBundle/Controller/MyInvitationsController.php b/src/Bundle/ChillCalendarBundle/Controller/MyInvitationsController.php new file mode 100644 index 000000000..d39e21476 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Controller/MyInvitationsController.php @@ -0,0 +1,62 @@ +denyAccessUnlessGranted('ROLE_USER'); + + $user = $this->getUser(); + + if (!$user instanceof User) { + throw new UnauthorizedHttpException('you are not a user'); + } + + $total = $this->inviteACLAwareRepository->countByUser($user); + $paginator = $this->paginator->create($total); + $invitations = $this->inviteACLAwareRepository->findByUser( + $user, + ['createdAt' => 'DESC'], + $paginator->getCurrentPageFirstItemNumber(), + $paginator->getItemsPerPage() + ); + + dump($invitations); + + $view = '@ChillCalendar/Invitations/listByUser.html.twig'; + + return $this->render($view, [ + 'invitations' => $invitations, + 'paginator' => $paginator, + ]); + } +} diff --git a/src/Bundle/ChillCalendarBundle/Menu/UserMenuBuilder.php b/src/Bundle/ChillCalendarBundle/Menu/UserMenuBuilder.php index 3a062f7b8..fe3083d96 100644 --- a/src/Bundle/ChillCalendarBundle/Menu/UserMenuBuilder.php +++ b/src/Bundle/ChillCalendarBundle/Menu/UserMenuBuilder.php @@ -30,6 +30,13 @@ class UserMenuBuilder implements LocalMenuBuilderInterface 'order' => 9, 'icon' => 'tasks', ]); + $menu->addChild('My invitations list', [ + 'route' => 'chill_calendar_invitations_list_my', + ]) + ->setExtras([ + 'order' => 9, + 'icon' => 'tasks', + ]); } } diff --git a/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepository.php b/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepository.php new file mode 100644 index 000000000..e79381e19 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepository.php @@ -0,0 +1,68 @@ +buildQueryByUser($user) + ->select('COUNT(i)') + ->getQuery() + ->getSingleScalarResult(); + } + + public function findByUser(User $user, ?array $orderBy = [], ?int $offset = null, ?int $limit = null): array + { + $qb = $this->buildQueryByUser($user) + ->select('i'); + + foreach ($orderBy as $sort => $order) { + $qb->addOrderBy('i.'.$sort, $order); + } + + if (null !== $offset) { + $qb->setFirstResult($offset); + } + + if (null !== $limit) { + $qb->setMaxResults($limit); + } + + return $qb->getQuery()->getResult(); + } + + public function buildQueryByUser(User $user): QueryBuilder + { + $qb = $this->em->createQueryBuilder() + ->from(Invite::class, 'i'); + + $qb->where('i.user = :user'); + + $qb->setParameter('user', $user); + + return $qb; + } +} diff --git a/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepositoryInterface.php b/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepositoryInterface.php new file mode 100644 index 000000000..c388b0c03 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepositoryInterface.php @@ -0,0 +1,21 @@ + 0 %} +
+ {% if calendar.endDate.diff(calendar.startDate).days >= 1 %} + {{ calendar.startDate|format_datetime('short', 'short') }} + - {{ calendar.endDate|format_datetime('short', 'short') }} + {% else %} + {{ calendar.startDate|format_datetime('short', 'short') }} + - {{ calendar.endDate|format_datetime('none', 'short') }} + {% endif %} +
+ + + ++ {{ "There is no invitation items."|trans }} +
+ {% else %} + {{ include ('@ChillCalendar/Invitations/_list_item.html.twig') }} + {% endif %} + +{% endblock %} + +{% block js %} + {{ parent() }} +{% endblock %} + +{% block css %} + {{ parent() }} +{% endblock %}