*/ final class AuditLogRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, AuditLog::class); } /** * @return list */ public function findByFilters( ?int $employeeId = null, ?DateTimeImmutable $from = null, ?DateTimeImmutable $to = null, ?string $entityType = null, int $limit = 50, int $offset = 0, ): array { $qb = $this->createQueryBuilder('a') ->orderBy('a.createdAt', 'DESC') ->setMaxResults($limit) ->setFirstResult($offset) ; if (null !== $employeeId) { $qb->andWhere('a.employee = :employeeId') ->setParameter('employeeId', $employeeId) ; } if (null !== $from) { $qb->andWhere('a.affectedDate >= :from') ->setParameter('from', $from) ; } if (null !== $to) { $qb->andWhere('a.affectedDate <= :to') ->setParameter('to', $to) ; } if (null !== $entityType) { $qb->andWhere('a.entityType = :entityType') ->setParameter('entityType', $entityType) ; } return $qb->getQuery()->getResult(); } public function countByFilters( ?int $employeeId = null, ?DateTimeImmutable $from = null, ?DateTimeImmutable $to = null, ?string $entityType = null, ): int { $qb = $this->createQueryBuilder('a') ->select('COUNT(a.id)') ; if (null !== $employeeId) { $qb->andWhere('a.employee = :employeeId') ->setParameter('employeeId', $employeeId) ; } if (null !== $from) { $qb->andWhere('a.affectedDate >= :from') ->setParameter('from', $from) ; } if (null !== $to) { $qb->andWhere('a.affectedDate <= :to') ->setParameter('to', $to) ; } if (null !== $entityType) { $qb->andWhere('a.entityType = :entityType') ->setParameter('entityType', $entityType) ; } return (int) $qb->getQuery()->getSingleScalarResult(); } }