From cc3e7f54a76e3825237bad8620c87c47d72de132 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 23 Jul 2021 10:14:20 +0200 Subject: [PATCH] rdv: minor corrections following MR review --- .../Controller/CalendarController.php | 27 +++++++++------- .../DataFixtures/ORM/LoadCancelReason.php | 12 +++---- .../DataFixtures/ORM/LoadInvite.php | 10 +++--- .../ChillCalendarExtension.php | 12 +++---- .../ChillCalendarBundle/Form/CalendarType.php | 32 +++++++++---------- 5 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index bc2a87313..893d8eefc 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -93,11 +93,11 @@ class CalendarController extends AbstractController $view = 'ChillCalendarBundle:Calendar:listByAccompanyingCourse.html.twig'; } - return $this->render($view, array( + return $this->render($view, [ 'calendarItems' => $calendarItems, 'user' => $user, 'accompanyingCourse' => $accompanyingPeriod, - )); + ]); } /** @@ -143,8 +143,11 @@ class CalendarController extends AbstractController $params['id'] = $entity->getId(); return $this->redirectToRoute('chill_calendar_calendar_show', $params); + } elseif ($form->isSubmitted() and !$form->isValid()) { + $this->addFlash('error', $this->get('translator')->trans('This form contains errors')); } + if ($view === null) { throw $this->createNotFoundException('Template not found'); } @@ -194,12 +197,12 @@ class CalendarController extends AbstractController throw $this->createNotFoundException('Template not found'); } - return $this->render($view, array( + return $this->render($view, [ //'person' => $person, 'accompanyingCourse' => $accompanyingPeriod, 'entity' => $entity, //'delete_form' => $deleteForm->createView(), - )); + ]); } @@ -240,6 +243,8 @@ class CalendarController extends AbstractController $params = $this->buildParamsToUrl($user, $accompanyingPeriod); $params['id'] = $id; return $this->redirectToRoute('chill_activity_activity_show', $params); + } elseif ($form->isSubmitted() and !$form->isValid()) { + $this->addFlash('error', $this->get('translator')->trans('This form contains errors')); } $deleteForm = $this->createDeleteForm($id, $user, $accompanyingPeriod); @@ -250,13 +255,13 @@ class CalendarController extends AbstractController $entity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); - return $this->render($view, array( + return $this->render($view, [ 'entity' => $entity, 'form' => $form->createView(), 'delete_form' => $deleteForm->createView(), 'accompanyingCourse' => $accompanyingPeriod, 'entity_json' => $entity_array - )); + ]); } /** @@ -290,10 +295,10 @@ class CalendarController extends AbstractController if ($form->isValid()) { - $this->logger->notice("A calendar event has been removed", array( + $this->logger->notice("A calendar event has been removed", [ 'by_user' => $this->getUser()->getUsername(), 'calendar_id' => $entity->getId() - )); + ]); $em->remove($entity); $em->flush(); @@ -310,11 +315,11 @@ class CalendarController extends AbstractController throw $this->createNotFoundException('Template not found'); } - return $this->render($view, array( + return $this->render($view, [ 'calendar' => $entity, 'delete_form' => $form->createView(), 'accompanyingCourse' => $accompanyingPeriod, - )); + ]); } /** @@ -328,7 +333,7 @@ class CalendarController extends AbstractController return $this->createFormBuilder() ->setAction($this->generateUrl('chill_calendar_calendar_delete', $params)) ->setMethod('DELETE') - ->add('submit', SubmitType::class, array('label' => 'Delete')) + ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm() ; } diff --git a/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCancelReason.php b/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCancelReason.php index 041c4178e..370b08f07 100644 --- a/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCancelReason.php +++ b/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCancelReason.php @@ -20,15 +20,15 @@ class LoadCancelReason extends Fixture implements FixtureGroupInterface return ['calendar']; } - public static $references = array(); + public static $references = []; public function load(ObjectManager $manager): void { - $arr = array( - array('name' => CancelReason::CANCELEDBY_USER), - array('name' => CancelReason::CANCELEDBY_PERSON), - array('name' => CancelReason::CANCELEDBY_DONOTCOUNT), - ); + $arr = [ + ['name' => CancelReason::CANCELEDBY_USER], + ['name' => CancelReason::CANCELEDBY_PERSON], + ['name' => CancelReason::CANCELEDBY_DONOTCOUNT], + ]; foreach ($arr as $a) { print "Creating calendar cancel reason : " . $a['name'] . "\n"; diff --git a/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadInvite.php b/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadInvite.php index 93d5f6f55..9c265b3ac 100644 --- a/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadInvite.php +++ b/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadInvite.php @@ -20,14 +20,14 @@ class LoadInvite extends Fixture implements FixtureGroupInterface return ['calendar']; } - public static $references = array(); + public static $references = []; public function load(ObjectManager $manager): void { - $arr = array( - array('name' => array('fr' => 'Rendez-vous décliné')), - array('name' => array('fr' => 'Rendez-vous accepté')), - ); + $arr = [ + ['name' => ['fr' => 'Rendez-vous décliné']], + ['name' => ['fr' => 'Rendez-vous accepté']], + ]; foreach ($arr as $a) { print "Creating calendar invite : " . $a['name']['fr'] . "\n"; diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php index f67dfb67f..c6e807d03 100644 --- a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php @@ -38,13 +38,13 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf protected function preprendRoutes(ContainerBuilder $container) { - $container->prependExtensionConfig('chill_main', array( - 'routing' => array( - 'resources' => array( + $container->prependExtensionConfig('chill_main', [ + 'routing' => [ + 'resources' => [ '@ChillCalendarBundle/Resources/config/routing.yml' - ) - ) - )); + ] + ] + ]); } diff --git a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php index e8afcabcc..2c756898e 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php @@ -44,42 +44,42 @@ class CalendarType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('mainUser', EntityType::class, array( + ->add('mainUser', EntityType::class, [ 'required' => true, 'class' => User::class, 'choice_label' => function (User $entity) { return $entity->getUsernameCanonical(); }, // TODO 'empty_data' => - )) - ->add('comment', CommentType::class, array( + ]) + ->add('comment', CommentType::class, [ 'required' => false - )) - ->add('startDate', DateType::class, array( + ]) + ->add('startDate', DateType::class, [ 'required' => true, 'input' => 'datetime_immutable', 'widget' => 'single_text' - )) - ->add('endDate', DateType::class, array( + ]) + ->add('endDate', DateType::class, [ 'required' => true, 'input' => 'datetime_immutable', 'widget' => 'single_text' - )) - ->add('cancelReason', EntityType::class, array( + ]) + ->add('cancelReason', EntityType::class, [ 'required' => false, 'class' => CancelReason::class, 'choice_label' => function (CancelReason $entity) { return $entity->getCanceledBy(); }, - )) - ->add('sendSMS', ChoiceType::class, array( + ]) + ->add('sendSMS', ChoiceType::class, [ 'required' => false, - 'choices' => array( + 'choices' => [ 'Oui' => true, 'Non' => false - ), + ], 'expanded' => true - )) + ]) ; $builder->add('persons', HiddenType::class); @@ -145,9 +145,9 @@ class CalendarType extends AbstractType */ public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefaults(array( + $resolver->setDefaults([ 'data_class' => Calendar::class - )); + ]); $resolver ->setRequired(['accompanyingPeriod'])