diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index fe090962a..b84f72d73 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -158,6 +158,7 @@ class CalendarController extends AbstractController $entity = new Calendar(); $entity->setUser($this->getUser()); + $entity->setStatus($entity::STATUS_VALID); // if ($user instanceof User) { // $entity->setPerson($user); @@ -167,9 +168,6 @@ class CalendarController extends AbstractController $entity->setAccompanyingPeriod($accompanyingPeriod); } - // $entity->setType($activityType); - // $entity->setDate(new \DateTime('now')); - $form = $this->createForm(CalendarType::class, $entity, [ 'accompanyingPeriod' => $accompanyingPeriod, ])->handleRequest($request); @@ -191,7 +189,6 @@ class CalendarController extends AbstractController } $entity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); - dump($entity_array); return $this->render($view, [ 'user' => $user, diff --git a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php index d4a906230..6d898133e 100644 --- a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php +++ b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php @@ -23,6 +23,10 @@ use Chill\CalendarBundle\Repository\CalendarRepository; */ class Calendar { + const STATUS_VALID = 'valid'; + const STATUS_CANCELED = 'canceled'; + const STATUS_MOVED = 'moved'; + /** * @ORM\Id * @ORM\GeneratedValue diff --git a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php index 7500594ea..a4072f12e 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php @@ -8,24 +8,33 @@ 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\CancelReason; +use Chill\CalendarBundle\Entity\Invite; 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; + class CalendarType extends AbstractType { - private TranslatableStringHelper $translatableStringHelper; + protected TranslatableStringHelper $translatableStringHelper; + protected ObjectManager $om; - public function __construct(TranslatableStringHelper $translatableStringHelper) + public function __construct( + TranslatableStringHelper $translatableStringHelper, + ObjectManager $om + ) { $this->translatableStringHelper = $translatableStringHelper; + $this->om = $om; } /** @@ -38,12 +47,12 @@ class CalendarType extends AbstractType 'required' => false )) ->add('startDate', DateType::class, array( - 'required' => false, + 'required' => true, 'input' => 'datetime_immutable', 'widget' => 'single_text' )) ->add('endDate', DateType::class, array( - 'required' => false, + 'required' => true, 'input' => 'datetime_immutable', 'widget' => 'single_text' )) @@ -102,8 +111,8 @@ class CalendarType extends AbstractType )) ; - // $builder->add('users', HiddenType::class); - // $builder->get('users') + // $builder->add('invites', HiddenType::class); + // $builder->get('invites') // ->addModelTransformer(new CallbackTransformer( // function (iterable $usersAsIterable): string { // $userIds = []; @@ -114,7 +123,7 @@ class CalendarType extends AbstractType // }, // function (?string $usersAsString): array { // return array_map( - // fn(string $id): ?User => $this->om->getRepository(User::class)->findOneBy(['id' => (int) $id]), + // fn(string $id): ?Invite => $this->om->getRepository(Invite::class)->findOneBy(['id' => (int) $id]), // explode(',', $usersAsString) // ); // } diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/services/form.yml b/src/Bundle/ChillCalendarBundle/Resources/config/services/form.yml index 12241277f..85095dc9a 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/config/services/form.yml +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/form.yml @@ -4,6 +4,7 @@ services: class: Chill\CalendarBundle\Form\CalendarType arguments: - "@chill.main.helper.translatable_string" + - "@doctrine.orm.entity_manager" tags: - { name: form.type, alias: chill_calendarbundle_calendar } \ No newline at end of file