feat(audit) : filtres Employé et Utilisateur en champ texte (recherche libre)
Employé = recherche partielle sur nom/prénom (nouveau filtre back 'employee', LIKE via join) ; Utilisateur = recherche partielle sur username. Remplace les selects par des champs texte. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ use App\State\AuditLogProvider;
|
||||
provider: AuditLogProvider::class,
|
||||
parameters: [
|
||||
new QueryParameter(key: 'employeeId'),
|
||||
new QueryParameter(key: 'employee'),
|
||||
new QueryParameter(key: 'from'),
|
||||
new QueryParameter(key: 'to'),
|
||||
new QueryParameter(key: 'entityType'),
|
||||
|
||||
@@ -30,6 +30,7 @@ final class AuditLogRepository extends ServiceEntityRepository implements AuditL
|
||||
?string $username = null,
|
||||
?string $ip = null,
|
||||
?string $device = null,
|
||||
?string $employeeName = null,
|
||||
int $limit = 50,
|
||||
int $offset = 0,
|
||||
): array {
|
||||
@@ -38,7 +39,7 @@ final class AuditLogRepository extends ServiceEntityRepository implements AuditL
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
;
|
||||
$this->applyFilters($qb, $employeeId, $from, $to, $entityTypes, $actions, $username, $ip, $device);
|
||||
$this->applyFilters($qb, $employeeId, $from, $to, $entityTypes, $actions, $username, $ip, $device, $employeeName);
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
@@ -52,9 +53,10 @@ final class AuditLogRepository extends ServiceEntityRepository implements AuditL
|
||||
?string $username = null,
|
||||
?string $ip = null,
|
||||
?string $device = null,
|
||||
?string $employeeName = null,
|
||||
): int {
|
||||
$qb = $this->createQueryBuilder('a')->select('COUNT(a.id)');
|
||||
$this->applyFilters($qb, $employeeId, $from, $to, $entityTypes, $actions, $username, $ip, $device);
|
||||
$this->applyFilters($qb, $employeeId, $from, $to, $entityTypes, $actions, $username, $ip, $device, $employeeName);
|
||||
|
||||
return (int) $qb->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
@@ -73,10 +75,17 @@ final class AuditLogRepository extends ServiceEntityRepository implements AuditL
|
||||
?string $username,
|
||||
?string $ip,
|
||||
?string $device,
|
||||
?string $employeeName = null,
|
||||
): void {
|
||||
if (null !== $employeeId) {
|
||||
$qb->andWhere('a.employee = :employeeId')->setParameter('employeeId', $employeeId);
|
||||
}
|
||||
if (null !== $employeeName && '' !== $employeeName) {
|
||||
$qb->join('a.employee', 'e')
|
||||
->andWhere('LOWER(e.lastName) LIKE :employeeName OR LOWER(e.firstName) LIKE :employeeName')
|
||||
->setParameter('employeeName', '%'.mb_strtolower($employeeName).'%')
|
||||
;
|
||||
}
|
||||
if (null !== $from) {
|
||||
$qb->andWhere('a.affectedDate >= :from')->setParameter('from', $from);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ interface AuditLogReadRepositoryInterface
|
||||
?string $username = null,
|
||||
?string $ip = null,
|
||||
?string $device = null,
|
||||
?string $employeeName = null,
|
||||
int $limit = 50,
|
||||
int $offset = 0,
|
||||
): array;
|
||||
@@ -41,5 +42,6 @@ interface AuditLogReadRepositoryInterface
|
||||
?string $username = null,
|
||||
?string $ip = null,
|
||||
?string $device = null,
|
||||
?string $employeeName = null,
|
||||
): int;
|
||||
}
|
||||
|
||||
@@ -47,14 +47,15 @@ class AuditLogProvider implements ProviderInterface
|
||||
$username = $this->normalizeString($query->get('username'));
|
||||
$ip = $this->normalizeString($query->get('ip'));
|
||||
$device = $this->normalizeString($query->get('device'));
|
||||
$employee = $this->normalizeString($query->get('employee'));
|
||||
|
||||
$empId = $employeeId ? (int) $employeeId : null;
|
||||
$fromDt = $from ? new DateTimeImmutable((string) $from) : null;
|
||||
$toDt = $to ? new DateTimeImmutable((string) $to) : null;
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
$total = $this->auditLogRepository->countByFilters($empId, $fromDt, $toDt, $entityTypes, $actions, $username, $ip, $device);
|
||||
$logs = $this->auditLogRepository->findByFilters($empId, $fromDt, $toDt, $entityTypes, $actions, $username, $ip, $device, $perPage, $offset);
|
||||
$total = $this->auditLogRepository->countByFilters($empId, $fromDt, $toDt, $entityTypes, $actions, $username, $ip, $device, $employee);
|
||||
$logs = $this->auditLogRepository->findByFilters($empId, $fromDt, $toDt, $entityTypes, $actions, $username, $ip, $device, $employee, $perPage, $offset);
|
||||
|
||||
$items = [];
|
||||
foreach ($logs as $log) {
|
||||
|
||||
Reference in New Issue
Block a user