rdv: add thirdParty in concerned persons (WIP)

This commit is contained in:
nobohan
2021-07-19 10:08:43 +02:00
parent 1557b8f80a
commit 43d6dc835f
4 changed files with 53 additions and 18 deletions

View File

@@ -14,6 +14,7 @@ use Chill\CalendarBundle\Entity\Calendar;
use Chill\CalendarBundle\Entity\CancelReason;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
@@ -81,7 +82,45 @@ class CalendarType extends AbstractType
}
))
;
$builder->add('professionals', HiddenType::class);
$builder->get('professionals')
->addModelTransformer(new CallbackTransformer(
function (iterable $thirdpartyAsIterable): string {
$thirdpartyIds = [];
foreach ($thirdpartyAsIterable as $value) {
$thirdpartyIds[] = $value->getId();
}
return implode(',', $thirdpartyIds);
},
function (?string $thirdpartyAsString): array {
return array_map(
fn(string $id): ?ThirdParty => $this->om->getRepository(ThirdParty::class)->findOneBy(['id' => (int) $id]),
explode(',', $thirdpartyAsString)
);
}
))
;
// $builder->add('users', HiddenType::class);
// $builder->get('users')
// ->addModelTransformer(new CallbackTransformer(
// function (iterable $usersAsIterable): string {
// $userIds = [];
// foreach ($usersAsIterable as $value) {
// $userIds[] = $value->getId();
// }
// return implode(',', $userIds);
// },
// function (?string $usersAsString): array {
// return array_map(
// fn(string $id): ?User => $this->om->getRepository(User::class)->findOneBy(['id' => (int) $id]),
// explode(',', $usersAsString)
// );
// }
// ))
// ;
}/**
* {@inheritdoc}