*/ final class AuditLogRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, AuditLog::class); } /** * @return list */ public function findEntityHistory(string $entityType, string $entityId, int $limit = 100): array { return $this->createQueryBuilder('a') ->andWhere('a.entityType = :entityType') ->andWhere('a.entityId = :entityId') ->setParameter('entityType', $entityType) ->setParameter('entityId', $entityId) ->orderBy('a.createdAt', 'DESC') ->setMaxResults($limit) ->getQuery() ->getResult() ; } /** * @param array{entityType?: string, action?: string} $filters * * @return array{items: list, total: int} */ public function findAllPaginated(int $page = 1, int $itemsPerPage = 30, array $filters = []): array { $qb = $this->createQueryBuilder('a') ->orderBy('a.createdAt', 'DESC') ; if (!empty($filters['entityType'])) { $qb->andWhere('a.entityType = :entityType') ->setParameter('entityType', $filters['entityType']) ; } if (!empty($filters['action'])) { $qb->andWhere('a.action = :action') ->setParameter('action', $filters['action']) ; } $countQb = clone $qb; $countQb->select('COUNT(a.id)') ->resetDQLPart('orderBy') ; $total = (int) $countQb->getQuery()->getSingleScalarResult(); $qb->setFirstResult(($page - 1) * $itemsPerPage) ->setMaxResults($itemsPerPage) ; return [ 'items' => $qb->getQuery()->getResult(), 'total' => $total, ]; } }