mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-16 19:07:48 +00:00
Refactor user repository fields management and enhance query structure
- Moved the `FIELDS` constant from `UserRepository` to `UserRepositoryInterface` to improve consistency and sharing. - Updated SQL queries to include new fields (`absenceStart`, `mainLanguage`, and `isRoleSeeAuditTrails`). - Streamlined CSV export logic to reference the shared `FIELDS` constant.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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)];
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user