From 675e8450fc4a3a497fe0f3a3fa3f162343a02356 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 8 Sep 2025 08:33:36 +0200 Subject: [PATCH] WIP: switch from ACLAware to normal repository usage --- .../Controller/MyInvitationsController.php | 25 ++++--- .../Repository/InviteACLAwareRepository.php | 68 ------------------- .../InviteACLAwareRepositoryInterface.php | 21 ------ .../Repository/InviteRepository.php | 6 +- .../views/Invitations/listByUser.html.twig | 2 +- .../translations/messages.fr.yml | 2 + 6 files changed, 18 insertions(+), 106 deletions(-) delete mode 100644 src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepository.php delete mode 100644 src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepositoryInterface.php diff --git a/src/Bundle/ChillCalendarBundle/Controller/MyInvitationsController.php b/src/Bundle/ChillCalendarBundle/Controller/MyInvitationsController.php index d39e21476..fc2743e08 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/MyInvitationsController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/MyInvitationsController.php @@ -11,11 +11,9 @@ declare(strict_types=1); namespace Chill\CalendarBundle\Controller; -use Chill\CalendarBundle\Repository\InviteACLAwareRepository; +use Chill\CalendarBundle\Repository\InviteRepository; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Pagination\PaginatorFactory; -use Doctrine\ORM\NonUniqueResultException; -use Doctrine\ORM\NoResultException; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -24,12 +22,8 @@ use Symfony\Component\Routing\Annotation\Route; class MyInvitationsController extends AbstractController { - public function __construct(private readonly InviteACLAwareRepository $inviteACLAwareRepository, private readonly PaginatorFactory $paginator) {} + public function __construct(private readonly InviteRepository $inviteRepository, private readonly PaginatorFactory $paginator) {} - /** - * @throws NonUniqueResultException - * @throws NoResultException - */ #[Route(path: '/{_locale}/calendar/invitations/my', name: 'chill_calendar_invitations_list_my')] public function myInvitations(Request $request): Response { @@ -41,13 +35,18 @@ class MyInvitationsController extends AbstractController throw new UnauthorizedHttpException('you are not a user'); } - $total = $this->inviteACLAwareRepository->countByUser($user); + $total = count($this->inviteRepository->findBy(['user' => $user])); + dump($total); + dump($this->inviteRepository->findBy(['user' => $user])); $paginator = $this->paginator->create($total); - $invitations = $this->inviteACLAwareRepository->findByUser( - $user, + + dump($paginator->getCurrentPageFirstItemNumber()); + dump($paginator->getItemsPerPage()); + $invitations = $this->inviteRepository->findBy( + ['user' => $user], ['createdAt' => 'DESC'], - $paginator->getCurrentPageFirstItemNumber(), - $paginator->getItemsPerPage() +// $paginator->getCurrentPageFirstItemNumber(), +// $paginator->getItemsPerPage() ); dump($invitations); diff --git a/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepository.php b/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepository.php deleted file mode 100644 index e79381e19..000000000 --- a/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepository.php +++ /dev/null @@ -1,68 +0,0 @@ -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 deleted file mode 100644 index c388b0c03..000000000 --- a/src/Bundle/ChillCalendarBundle/Repository/InviteACLAwareRepositoryInterface.php +++ /dev/null @@ -1,21 +0,0 @@ -entityRepository->findBy($criteria, $orderBy, $limit, $offset); } diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Invitations/listByUser.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Invitations/listByUser.html.twig index 22ca9d7a8..282b83dfe 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Invitations/listByUser.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Invitations/listByUser.html.twig @@ -10,7 +10,7 @@ {% if invitations|length == 0 %}

- {{ "There is no invitation items."|trans }} + {{ "invite.list.none"|trans }}

{% else %} {{ include ('@ChillCalendar/Invitations/_list_item.html.twig') }} diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index cfb2fe057..740303fd5 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -86,6 +86,8 @@ invite: declined: Refusé pending: En attente tentative: Accepté provisoirement + list: + none: Il n'y aucun invitation # exports Exports of calendar: Exports des rendez-vous