mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-29 10:05:03 +00:00
Refactor filters to support "me" as a user option.
Replaced `PickUserDynamicType` with `PickUserOrMeDynamicType` across filters to enable handling of the "me" option. Introduced normalization and denormalization methods for "me" and adjusted all relevant queries and test cases to accommodate this enhancement.
This commit is contained in:
@@ -11,6 +11,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
@@ -63,6 +65,79 @@ trait ExportDataNormalizerTrait
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizer the "user or me" values.
|
||||
*
|
||||
* @param 'me'|User|iterable<'me'|User> $user
|
||||
*
|
||||
* @return int|'me'|list<'me'|int>
|
||||
*/
|
||||
private function normalizeUserOrMe(string|User|iterable $user): int|string|array
|
||||
{
|
||||
if (is_iterable($user)) {
|
||||
$users = [];
|
||||
foreach ($user as $u) {
|
||||
$users[] = $this->normalizeUserOrMe($u);
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
if ('me' === $user) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
return $user->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param 'me'|int|iterable<'me'|int> $userId
|
||||
*
|
||||
* @return 'me'|User|array|null
|
||||
*/
|
||||
private function denormalizeUserOrMe(string|int|iterable $userId, UserRepositoryInterface $userRepository): string|User|array|null
|
||||
{
|
||||
if (is_iterable($userId)) {
|
||||
$users = [];
|
||||
foreach ($userId as $id) {
|
||||
$users[] = $this->denormalizeUserOrMe($id, $userRepository);
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
if ('me' === $userId) {
|
||||
return 'me';
|
||||
}
|
||||
|
||||
return $userRepository->find($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param 'me'|User|iterable<'me'|User> $user
|
||||
*
|
||||
* @return User|list<User>
|
||||
*/
|
||||
private function userOrMe(string|User|iterable $user, ExportGenerationContext $context): User|array
|
||||
{
|
||||
if (is_iterable($user)) {
|
||||
$users = [];
|
||||
foreach ($user as $u) {
|
||||
$users[] = $this->userOrMe($u, $context);
|
||||
}
|
||||
|
||||
return array_values(
|
||||
array_filter($users, static fn (?User $user) => null !== $user)
|
||||
);
|
||||
}
|
||||
|
||||
if ('me' === $user) {
|
||||
return $context->byUser;
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a provided date into a specific string format.
|
||||
*
|
||||
|
Reference in New Issue
Block a user