diff --git a/src/Bundle/ChillMainBundle/Controller/UserExportController.php b/src/Bundle/ChillMainBundle/Controller/UserExportController.php index cb921d47f..e3192f171 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserExportController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserExportController.php @@ -47,30 +47,12 @@ final readonly class UserExportController $csv->insertOne( array_map( fn (string $e) => $this->translator->trans('admin.users.export.'.$e), - [ - 'id', - // 'username', - 'email', - 'enabled', - 'civility_id', - 'civility_abbreviation', - 'civility_name', - 'label', - 'mainCenter_id', - 'mainCenter_name', - 'mainScope_id', - 'mainScope_name', - 'userJob_id', - 'userJob_name', - 'currentLocation_id', - 'currentLocation_name', - 'mainLocation_id', - 'mainLocation_name', - 'absenceStart', - ] + UserRepositoryInterface::FIELDS ) ); - $csv->addFormatter(fn (array $row) => null !== ($row['absenceStart'] ?? null) ? array_merge($row, ['absenceStart' => $row['absenceStart']->format('Y-m-d')]) : $row); + $csv->addFormatter( + fn (array $row) => null !== ($row['absenceStart'] ?? null) ? array_merge($row, ['absenceStart' => $row['absenceStart']->format('Y-m-d')]) : $row + ); /* @phpstan-ignore-next-line as phpstan seem to ignore that we transform datetime into string */ $csv->insertAll($users); diff --git a/src/Bundle/ChillMainBundle/Repository/UserRepository.php b/src/Bundle/ChillMainBundle/Repository/UserRepository.php index 9ac8af9ee..12e0980e7 100644 --- a/src/Bundle/ChillMainBundle/Repository/UserRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/UserRepository.php @@ -27,26 +27,6 @@ final readonly class UserRepository implements UserRepositoryInterface { private EntityRepository $repository; - private const FIELDS = [ - 'id', - 'email', - 'enabled', - 'civility_id', - 'civility_abbreviation', - 'civility_name', - 'label', - 'mainCenter_id', - 'mainCenter_name', - 'mainScope_id', - 'mainScope_name', - 'userJob_id', - 'userJob_name', - 'currentLocation_id', - 'currentLocation_name', - 'mainLocation_id', - 'mainLocation_name', - ]; - public function __construct(private EntityManagerInterface $entityManager, private Connection $connection) { $this->repository = $entityManager->getRepository(User::class); @@ -119,7 +99,9 @@ final readonly class UserRepository implements UserRepositoryInterface currentLocation.name AS currentLocation_name, mainLocation.id AS mainLocation_id, mainLocation.name AS mainLocation_name, - u.absenceStart + u.absenceStart AS absenceStart, + u.locale AS mainLanguage, + u.roles @> jsonb_build_array('%s') AS isRoleSeeAuditTrails FROM users u LEFT JOIN chill_main_civility civility ON u.civility_id = civility.id LEFT JOIN centers mainCenter ON u.maincenter_id = mainCenter.id @@ -130,13 +112,13 @@ final readonly class UserRepository implements UserRepositoryInterface LEFT JOIN chill_main_location currentLocation ON u.currentlocation_id = currentLocation.id LEFT JOIN chill_main_location mainLocation ON u.mainlocation_id = mainLocation.id ORDER BY u.label, u.id - SQL); + SQL, User::ROLE_SEE_AUDIT_TRAILS); $query = $this->connection->prepare($sql); foreach ($query->executeQuery(['lang' => $lang])->iterateAssociative() as $u) { $converted = []; - foreach (self::FIELDS as $f) { + foreach (UserRepositoryInterface::FIELDS as $f) { $converted[$f] = $u[strtolower($f)]; } diff --git a/src/Bundle/ChillMainBundle/Repository/UserRepositoryInterface.php b/src/Bundle/ChillMainBundle/Repository/UserRepositoryInterface.php index f6c74b7dd..9b73542ba 100644 --- a/src/Bundle/ChillMainBundle/Repository/UserRepositoryInterface.php +++ b/src/Bundle/ChillMainBundle/Repository/UserRepositoryInterface.php @@ -19,6 +19,30 @@ use Doctrine\Persistence\ObjectRepository; */ interface UserRepositoryInterface extends ObjectRepository { + public const FIELDS = [ + 'id', + 'username', + 'email', + 'enabled', + 'civility_id', + 'civility_abbreviation', + 'civility_name', + 'label', + 'mainCenter_id', + 'mainCenter_name', + 'mainScope_id', + 'mainScope_name', + 'userJob_id', + 'userJob_name', + 'currentLocation_id', + 'currentLocation_name', + 'mainLocation_id', + 'mainLocation_name', + 'absenceStart', + 'mainLanguage', + 'isRoleSeeAuditTrails', + ]; + public function countBy(array $criteria): int; public function countByActive(): int;