mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 04:53:49 +00:00
Rename and implement form data normalization for filters
The `StepFilterTest` was renamed to `StepFilterOnDateTest` for improved clarity. Added `normalizeFormData` and `denormalizeFormData` methods to `UserJobFilter` and `StepFilterOnDate` for handling form data conversions. Also introduced `ExportDataNormalizerTrait` to enhance consistency in data normalization processes.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
trait ExportDataNormalizerTrait
|
||||
{
|
||||
/**
|
||||
* @param object|list<object> $entity
|
||||
*/
|
||||
public function normalizeDoctrineEntity(object|array $entity): array|int
|
||||
{
|
||||
if (is_array($entity)) {
|
||||
return array_values(array_map(static fn (object $entity) => $entity->getId(), $entity));
|
||||
}
|
||||
|
||||
return $entity->getId();
|
||||
}
|
||||
|
||||
public function denormalizeDoctrineEntity(array|int $id, ObjectRepository $repository): object|array
|
||||
{
|
||||
if (is_array($id)) {
|
||||
return $repository->findBy(['id' => $id]);
|
||||
}
|
||||
|
||||
if (null === $object = $repository->find($id)) {
|
||||
throw new \UnexpectedValueException(sprintf('Object with id "%s" does not exist.', $id));
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user