WIP: switch from ACLAware to normal repository usage

This commit is contained in:
2025-09-08 08:33:36 +02:00
parent 4ffd7034d0
commit 675e8450fc
6 changed files with 18 additions and 106 deletions

View File

@@ -11,11 +11,9 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Controller; namespace Chill\CalendarBundle\Controller;
use Chill\CalendarBundle\Repository\InviteACLAwareRepository; use Chill\CalendarBundle\Repository\InviteRepository;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Pagination\PaginatorFactory;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -24,12 +22,8 @@ use Symfony\Component\Routing\Annotation\Route;
class MyInvitationsController extends AbstractController 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')] #[Route(path: '/{_locale}/calendar/invitations/my', name: 'chill_calendar_invitations_list_my')]
public function myInvitations(Request $request): Response public function myInvitations(Request $request): Response
{ {
@@ -41,13 +35,18 @@ class MyInvitationsController extends AbstractController
throw new UnauthorizedHttpException('you are not a user'); 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); $paginator = $this->paginator->create($total);
$invitations = $this->inviteACLAwareRepository->findByUser(
$user, dump($paginator->getCurrentPageFirstItemNumber());
dump($paginator->getItemsPerPage());
$invitations = $this->inviteRepository->findBy(
['user' => $user],
['createdAt' => 'DESC'], ['createdAt' => 'DESC'],
$paginator->getCurrentPageFirstItemNumber(), // $paginator->getCurrentPageFirstItemNumber(),
$paginator->getItemsPerPage() // $paginator->getItemsPerPage()
); );
dump($invitations); dump($invitations);

View File

@@ -1,68 +0,0 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Repository;
use Chill\CalendarBundle\Entity\Invite;
use Chill\MainBundle\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\QueryBuilder;
readonly class InviteACLAwareRepository implements InviteACLAwareRepositoryInterface
{
public function __construct(private EntityManagerInterface $em) {}
/**
* @throws NonUniqueResultException
* @throws NoResultException
*/
public function countByUser(User $user): int
{
return $this->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;
}
}

View File

@@ -1,21 +0,0 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Repository;
use Chill\MainBundle\Entity\User;
interface InviteACLAwareRepositoryInterface
{
public function countByUser(User $user): int;
public function findByUser(User $user, ?array $orderBy = [], ?int $offset = null, ?int $limit = null): array;
}

View File

@@ -16,9 +16,9 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectRepository; use Doctrine\Persistence\ObjectRepository;
class InviteRepository implements ObjectRepository readonly class InviteRepository implements ObjectRepository
{ {
private readonly EntityRepository $entityRepository; private EntityRepository $entityRepository;
public function __construct(EntityManagerInterface $em) public function __construct(EntityManagerInterface $em)
{ {
@@ -41,7 +41,7 @@ class InviteRepository implements ObjectRepository
/** /**
* @return array|Invite[] * @return array|Invite[]
*/ */
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null) public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
{ {
return $this->entityRepository->findBy($criteria, $orderBy, $limit, $offset); return $this->entityRepository->findBy($criteria, $orderBy, $limit, $offset);
} }

View File

@@ -10,7 +10,7 @@
{% if invitations|length == 0 %} {% if invitations|length == 0 %}
<p class="chill-no-data-statement"> <p class="chill-no-data-statement">
{{ "There is no invitation items."|trans }} {{ "invite.list.none"|trans }}
</p> </p>
{% else %} {% else %}
{{ include ('@ChillCalendar/Invitations/_list_item.html.twig') }} {{ include ('@ChillCalendar/Invitations/_list_item.html.twig') }}

View File

@@ -86,6 +86,8 @@ invite:
declined: Refusé declined: Refusé
pending: En attente pending: En attente
tentative: Accepté provisoirement tentative: Accepté provisoirement
list:
none: Il n'y aucun invitation
# exports # exports
Exports of calendar: Exports des rendez-vous Exports of calendar: Exports des rendez-vous