diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 92771ed32..4bde0e6f9 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -156,17 +156,6 @@ class CalendarController extends AbstractController // $view = 'ChillCalendarBundle:Calendar:newUser.html.twig'; // } - // $activityType_id = $request->get('activityType_id', 0); - // $activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) - // ->find($activityType_id); - - // if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType || - // !$activityType->isActive()) { - - // $params = $this->buildParamsToUrl($user, $accompanyingPeriod); - // return $this->redirectToRoute('chill_activity_activity_select_type', $params); - // } - $entity = new Calendar(); $entity->setUser($this->getUser()); @@ -181,28 +170,25 @@ class CalendarController extends AbstractController // $entity->setType($activityType); // $entity->setDate(new \DateTime('now')); - // $form = $this->createForm(ActivityType::class, $entity, [ - // 'center' => $entity->getCenter(), - // 'role' => new Role('CHILL_ACTIVITY_CREATE'), - // 'activityType' => $entity->getType(), - // 'accompanyingPeriod' => $accompanyingPeriod, - // ])->handleRequest($request); + $form = $this->createForm(CalendarType::class, $entity, [ + 'accompanyingPeriod' => $accompanyingPeriod, + ])->handleRequest($request); - // if ($form->isSubmitted() && $form->isValid()) { - // $em->persist($entity); - // $em->flush(); + if ($form->isSubmitted() && $form->isValid()) { + $em->persist($entity); + $em->flush(); - // $this->addFlash('success', $this->get('translator')->trans('Success : activity created!')); + $this->addFlash('success', $this->get('translator')->trans('Success : calendar item created!')); - // $params = $this->buildParamsToUrl($person, $accompanyingPeriod); - // $params['id'] = $entity->getId(); + $params = $this->buildParamsToUrl($user, $accompanyingPeriod); //TODO useful? + $params['id'] = $entity->getId(); - // return $this->redirectToRoute('chill_activity_activity_show', $params); - // } + return $this->redirectToRoute('chill_calendar_calendar_show', $params); + } - // if ($view === null) { - // throw $this->createNotFoundException('Template not found'); - // } + if ($view === null) { + throw $this->createNotFoundException('Template not found'); + } // $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); @@ -210,7 +196,7 @@ class CalendarController extends AbstractController 'user' => $user, 'accompanyingCourse' => $accompanyingPeriod, 'entity' => $entity, - // 'form' => $form->createView(), + 'form' => $form->createView(), //'activity_json' => $calendar_array ]); } @@ -456,20 +442,20 @@ class CalendarController extends AbstractController ]; } - // private function buildParamsToUrl( - // ?Person $person, - // ?AccompanyingPeriod $accompanyingPeriod - // ): array { - // $params = []; + private function buildParamsToUrl( + ?User $user, + ?AccompanyingPeriod $accompanyingPeriod + ): array { + $params = []; - // if ($person) { - // $params['person_id'] = $person->getId(); - // } + if ($user) { + $params['user_id'] = $user->getId(); + } - // if ($accompanyingPeriod) { - // $params['accompanying_period_id'] = $accompanyingPeriod->getId(); - // } + if ($accompanyingPeriod) { + $params['accompanying_period_id'] = $accompanyingPeriod->getId(); + } - // return $params; - // } + return $params; + } } diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php index 5804b93ff..f67dfb67f 100644 --- a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php @@ -27,6 +27,7 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf $loader->load('services.yml'); $loader->load('services/controller.yml'); $loader->load('services/fixtures.yml'); + $loader->load('services/form.yml'); } public function prepend(ContainerBuilder $container) diff --git a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php new file mode 100644 index 000000000..c83fd9859 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php @@ -0,0 +1,80 @@ +translatableStringHelper = $translatableStringHelper; + } + + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('comment', CommentType::class, array( + 'required' => false + )) + ->add('startDate', DateType::class, array( + 'required' => false, + 'input' => 'datetime_immutable', + 'widget' => 'single_text' + )) + ->add('endDate', DateType::class, array( + 'required' => false, + 'input' => 'datetime_immutable', + 'widget' => 'single_text' + )) + ->add('cancelReason', EntityType::class, array( + 'required' => false, + 'class' => CancelReason::class, + 'choice_label' => function (CancelReason $entity) { + return $this->translatableStringHelper->localize($entity->getName()); + }, + )) + ; + + }/** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => Calendar::class + )); + + $resolver + ->setRequired(['accompanyingPeriod']) + ->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null']) + ; + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'chill_calendarbundle_calendar'; + } + + +} + + diff --git a/src/Bundle/ChillCalendarBundle/Repository/CancelReasonRepository.php b/src/Bundle/ChillCalendarBundle/Repository/CancelReasonRepository.php index 11c2f7f59..5bd07fbd9 100644 --- a/src/Bundle/ChillCalendarBundle/Repository/CancelReasonRepository.php +++ b/src/Bundle/ChillCalendarBundle/Repository/CancelReasonRepository.php @@ -2,7 +2,7 @@ namespace Chill\CalendarBundle\Repository; -use CalendarBundle\Entity\CancelReason; +use Chill\CalendarBundle\Entity\CancelReason; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; diff --git a/src/Bundle/ChillCalendarBundle/Repository/InviteRepository.php b/src/Bundle/ChillCalendarBundle/Repository/InviteRepository.php index da9207cc4..ece11269f 100644 --- a/src/Bundle/ChillCalendarBundle/Repository/InviteRepository.php +++ b/src/Bundle/ChillCalendarBundle/Repository/InviteRepository.php @@ -2,7 +2,7 @@ namespace Chill\CalendarBundle\Repository; -use CalendarBundle\Entity\Invite; +use Chill\CalendarBundle\Entity\Invite; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/services/form.yml b/src/Bundle/ChillCalendarBundle/Resources/config/services/form.yml new file mode 100644 index 000000000..12241277f --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/form.yml @@ -0,0 +1,9 @@ +--- +services: + chill.calendar.form.type.calendar: + class: Chill\CalendarBundle\Form\CalendarType + arguments: + - "@chill.main.helper.translatable_string" + + tags: + - { name: form.type, alias: chill_calendarbundle_calendar } \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig index e69de29bb..ebb9ac911 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig @@ -0,0 +1,80 @@ +