mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
exports: fix buildForm in SocialWorkType Filter
This commit is contained in:
parent
9b1e464011
commit
4cb6e8e564
@ -50,72 +50,42 @@ class SocialWorkTypeFilter implements FilterInterface
|
|||||||
$builder
|
$builder
|
||||||
->add('actionType', HiddenType::class)
|
->add('actionType', HiddenType::class)
|
||||||
->get('actionType')
|
->get('actionType')
|
||||||
->addModelTransformer(new CallbackTransformer(
|
->addModelTransformer($this->iterableToIdTransformer(SocialAction::class))
|
||||||
static function (?iterable $actionsAsIterable): string {
|
|
||||||
if (null === $actionsAsIterable) { return ''; }
|
|
||||||
$actionIds = [];
|
|
||||||
foreach ($actionsAsIterable as $value) {
|
|
||||||
$actionIds[] = $value->getId();
|
|
||||||
}
|
|
||||||
return implode(',', $actionIds);
|
|
||||||
},
|
|
||||||
function (?string $actionsAsString): array {
|
|
||||||
if (null === $actionsAsString) { return []; }
|
|
||||||
return array_map(
|
|
||||||
fn (string $id): ?SocialAction
|
|
||||||
=> $this->socialActionRepository->findOneBy(['id' => (int) $id]),
|
|
||||||
explode(',', $actionsAsString)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
))
|
|
||||||
;
|
;
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('goal', HiddenType::class)
|
->add('goal', HiddenType::class)
|
||||||
->get('goal')
|
->get('goal')
|
||||||
->addModelTransformer(new CallbackTransformer(
|
->addModelTransformer($this->iterableToIdTransformer(Goal::class))
|
||||||
static function (?iterable $goalsAsIterable): string {
|
|
||||||
if (null === $goalsAsIterable) { return ''; }
|
|
||||||
$goalIds = [];
|
|
||||||
foreach ($goalsAsIterable as $value) {
|
|
||||||
$goalIds[] = $value->getId();
|
|
||||||
}
|
|
||||||
return implode(',', $goalIds);
|
|
||||||
},
|
|
||||||
function (?string $goalsAsString): array {
|
|
||||||
if (null === $goalsAsString) { return []; }
|
|
||||||
return array_map(
|
|
||||||
fn (string $id): ?Goal
|
|
||||||
=> $this->socialActionRepository->findOneBy(['id' => (int) $id]),
|
|
||||||
explode(',', $goalsAsString)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
))
|
|
||||||
;
|
;
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('result', HiddenType::class)
|
->add('result', HiddenType::class)
|
||||||
->get('result')
|
->get('result')
|
||||||
->addModelTransformer(new CallbackTransformer(
|
->addModelTransformer($this->iterableToIdTransformer(Result::class))
|
||||||
static function (?iterable $resultsAsIterable): string {
|
;
|
||||||
if (null === $resultsAsIterable) { return ''; }
|
|
||||||
$resultIds = [];
|
|
||||||
foreach ($resultsAsIterable as $value) {
|
|
||||||
$resultIds[] = $value->getId();
|
|
||||||
}
|
}
|
||||||
return implode(',', $resultIds);
|
|
||||||
|
private function iterableToIdTransformer(string $entity): CallbackTransformer
|
||||||
|
{
|
||||||
|
return new CallbackTransformer(
|
||||||
|
static function (?iterable $asIterable): string {
|
||||||
|
if (null === $asIterable) { return ''; }
|
||||||
|
$ids = [];
|
||||||
|
foreach ($asIterable as $value) {
|
||||||
|
$ids[] = $value->getId();
|
||||||
|
}
|
||||||
|
return implode(',', $ids);
|
||||||
},
|
},
|
||||||
function (?string $resultsAsString): array {
|
function (?string $asString) use ($entity): array {
|
||||||
if (null === $resultsAsString) { return []; }
|
if (null === $asString) { return []; }
|
||||||
return array_map(
|
return array_map(
|
||||||
fn (string $id): ?Result
|
fn (string $id)
|
||||||
=> $this->socialActionRepository->findOneBy(['id' => (int) $id]),
|
=> $this->em
|
||||||
explode(',', $resultsAsString)
|
->getRepository($entity)
|
||||||
|
->findOneBy(['id' => (int) $id]),
|
||||||
|
explode(',', $asString)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
))
|
);
|
||||||
;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user