Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #9 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
103 lines
2.6 KiB
PHP
103 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\AuditLog;
|
|
use DateTimeImmutable;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<AuditLog>
|
|
*/
|
|
final class AuditLogRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, AuditLog::class);
|
|
}
|
|
|
|
/**
|
|
* @return list<AuditLog>
|
|
*/
|
|
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();
|
|
}
|
|
}
|