mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 22:35:01 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,53 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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\CalendarBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
|
||||
use Chill\MainBundle\Form\Type\CommentType;
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||
use Chill\CalendarBundle\Entity\CancelReason;
|
||||
use Chill\CalendarBundle\Entity\Invite;
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\Type\CommentType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CalendarType extends AbstractType
|
||||
{
|
||||
protected ObjectManager $om;
|
||||
|
||||
protected TranslatableStringHelper $translatableStringHelper;
|
||||
protected ObjectManager $om;
|
||||
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
ObjectManager $om
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->om = $om;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('comment', CommentType::class, [
|
||||
'required' => false
|
||||
'required' => false,
|
||||
])
|
||||
// ->add('cancelReason', EntityType::class, [
|
||||
// 'required' => false,
|
||||
@@ -60,124 +61,126 @@ class CalendarType extends AbstractType
|
||||
'required' => false,
|
||||
'choices' => [
|
||||
'Oui' => true,
|
||||
'Non' => false
|
||||
'Non' => false,
|
||||
],
|
||||
'expanded' => true
|
||||
])
|
||||
;
|
||||
|
||||
'expanded' => true,
|
||||
]);
|
||||
|
||||
$builder->add('mainUser', HiddenType::class);
|
||||
$builder->get('mainUser')
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function (?User $user): int {
|
||||
if (NULL !== $user) {
|
||||
if (null !== $user) {
|
||||
$res = $user->getId();
|
||||
} else {
|
||||
$res = -1; //TODO cannot be null in any ways...
|
||||
}
|
||||
|
||||
return $res;
|
||||
},
|
||||
function (?int $userId): User {
|
||||
return $this->om->getRepository(user::class)->findOneBy(['id' => (int) $userId]);
|
||||
}
|
||||
))
|
||||
;
|
||||
));
|
||||
|
||||
$builder->add('startDate', HiddenType::class);
|
||||
$builder->get('startDate')
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function (?DateTimeImmutable $dateTimeImmutable): string {
|
||||
if (NULL !== $dateTimeImmutable) {
|
||||
if (null !== $dateTimeImmutable) {
|
||||
$res = date_format($dateTimeImmutable, 'Y-m-d H:i:s');
|
||||
} else {
|
||||
$res = '';
|
||||
}
|
||||
|
||||
return $res;
|
||||
},
|
||||
function (?string $dateAsString): DateTimeImmutable {
|
||||
dump($dateAsString);
|
||||
|
||||
return new DateTimeImmutable($dateAsString);
|
||||
}
|
||||
))
|
||||
;
|
||||
));
|
||||
|
||||
$builder->add('endDate', HiddenType::class);
|
||||
$builder->get('endDate')
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function (?DateTimeImmutable $dateTimeImmutable): string {
|
||||
if (NULL !== $dateTimeImmutable) {
|
||||
if (null !== $dateTimeImmutable) {
|
||||
$res = date_format($dateTimeImmutable, 'Y-m-d H:i:s');
|
||||
} else {
|
||||
$res = '';
|
||||
}
|
||||
|
||||
return $res;
|
||||
},
|
||||
function (?string $dateAsString): DateTimeImmutable {
|
||||
return new DateTimeImmutable($dateAsString);
|
||||
}
|
||||
))
|
||||
;
|
||||
));
|
||||
|
||||
$builder->add('persons', HiddenType::class);
|
||||
$builder->get('persons')
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function (iterable $personsAsIterable): string {
|
||||
$personIds = [];
|
||||
|
||||
foreach ($personsAsIterable as $value) {
|
||||
$personIds[] = $value->getId();
|
||||
}
|
||||
|
||||
return implode(',', $personIds);
|
||||
},
|
||||
function (?string $personsAsString): array {
|
||||
return array_map(
|
||||
fn(string $id): ?Person => $this->om->getRepository(Person::class)->findOneBy(['id' => (int) $id]),
|
||||
fn (string $id): ?Person => $this->om->getRepository(Person::class)->findOneBy(['id' => (int) $id]),
|
||||
explode(',', $personsAsString)
|
||||
);
|
||||
}
|
||||
))
|
||||
;
|
||||
));
|
||||
|
||||
$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]),
|
||||
fn (string $id): ?ThirdParty => $this->om->getRepository(ThirdParty::class)->findOneBy(['id' => (int) $id]),
|
||||
explode(',', $thirdpartyAsString)
|
||||
);
|
||||
}
|
||||
))
|
||||
;
|
||||
));
|
||||
|
||||
$builder->add('calendarRange', HiddenType::class);
|
||||
$builder->get('calendarRange')
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function (?CalendarRange $calendarRange): ?int {
|
||||
if (NULL !== $calendarRange) {
|
||||
if (null !== $calendarRange) {
|
||||
$res = $calendarRange->getId();
|
||||
} else {
|
||||
$res = -1;
|
||||
}
|
||||
|
||||
return $res;
|
||||
},
|
||||
function (?string $calendarRangeId): ?CalendarRange {
|
||||
if (NULL !== $calendarRangeId) {
|
||||
if (null !== $calendarRangeId) {
|
||||
$res = $this->om->getRepository(CalendarRange::class)->findOneBy(['id' => (int) $calendarRangeId]);
|
||||
} else {
|
||||
$res = NULL;
|
||||
$res = null;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
))
|
||||
;
|
||||
));
|
||||
|
||||
$builder->add('location', HiddenType::class)
|
||||
->get('location')
|
||||
@@ -186,58 +189,48 @@ class CalendarType extends AbstractType
|
||||
if (null === $location) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $location->getId();
|
||||
},
|
||||
function (?string $id): ?Location {
|
||||
return $this->om->getRepository(Location::class)->findOneBy(['id' => (int) $id]);
|
||||
}
|
||||
))
|
||||
;
|
||||
));
|
||||
|
||||
$builder->add('invites', HiddenType::class);
|
||||
$builder->get('invites')
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function (iterable $usersAsIterable): string {
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function (iterable $usersAsIterable): string {
|
||||
$userIds = [];
|
||||
|
||||
foreach ($usersAsIterable as $value) {
|
||||
$userIds[] = $value->getId();
|
||||
}
|
||||
|
||||
return implode(',', $userIds);
|
||||
},
|
||||
function (?string $usersAsString): array {
|
||||
function (?string $usersAsString): array {
|
||||
return array_map(
|
||||
fn(string $id): ?Invite => $this->om->getRepository(Invite::class)->findOneBy(['id' => (int) $id]),
|
||||
fn (string $id): ?Invite => $this->om->getRepository(Invite::class)->findOneBy(['id' => (int) $id]),
|
||||
explode(',', $usersAsString)
|
||||
);
|
||||
}
|
||||
))
|
||||
;
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Calendar::class
|
||||
'data_class' => Calendar::class,
|
||||
]);
|
||||
|
||||
$resolver
|
||||
->setRequired(['accompanyingPeriod'])
|
||||
->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null'])
|
||||
;
|
||||
->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'chill_calendarbundle_calendar';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user