diff --git a/app/DoctrineMigrations/Version20230823170329_period_position_weekcycle_allow_null.php b/app/DoctrineMigrations/Version20230823170329_period_position_weekcycle_allow_null.php new file mode 100644 index 000000000..c3c69dcf3 --- /dev/null +++ b/app/DoctrineMigrations/Version20230823170329_period_position_weekcycle_allow_null.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE period_position CHANGE week_cycle week_cycle VARCHAR(1) DEFAULT NULL'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE period_position CHANGE week_cycle week_cycle VARCHAR(1) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`'); + } +} diff --git a/app/Resources/views/admin/period/edit.html.twig b/app/Resources/views/admin/period/edit.html.twig index 53d467e76..f3430b674 100644 --- a/app/Resources/views/admin/period/edit.html.twig +++ b/app/Resources/views/admin/period/edit.html.twig @@ -36,114 +36,19 @@
- Créneau fixe réservé - pour {{ position.shifter }} - le {{ position.bookedTime | date_fr_full_with_time }} - par {% include "admin/member/_partial/member_or_user_link.html.twig" with { user: position.booker, target_blank: true } %}. -
- {{ form_start(positions_free_forms[position.id]) }} - {{ form_widget(positions_free_forms[position.id]) }} - - lock_openLibérer - - {{ form_end(positions_free_forms[position.id]) }} -- Poste type créé le {{ position.createdAt | date_fr_full_with_time }} - par {% include "admin/member/_partial/member_or_user_link.html.twig" with { user: position.createdBy, target_blank: true } %}. -
- {% endif %} -+ Créneau fixe réservé + pour {{ position.shifter }} + le {{ position.bookedTime | date_fr_full_with_time }} + par {% include "admin/member/_partial/member_or_user_link.html.twig" with { user: position.booker, target_blank: true } %}. +
+ {{ form_start(position_free_form) }} + {{ form_widget(position_free_form) }} + + lock_openLibérer + + {{ form_end(position_free_form) }} + {% else %} + {{ form_start(position_book_form) }} ++ Poste type créé le {{ position.createdAt | date_fr_full_with_time }} + par {% include "admin/member/_partial/member_or_user_link.html.twig" with { user: position.createdBy, target_blank: true } %}. +
+ {% endif %} +person{{ period_position.shifter.firstname }} diff --git a/src/AppBundle/Controller/AdminPeriodController.php b/src/AppBundle/Controller/AdminPeriodController.php index 98fb78af4..d47a113be 100644 --- a/src/AppBundle/Controller/AdminPeriodController.php +++ b/src/AppBundle/Controller/AdminPeriodController.php @@ -205,9 +205,20 @@ public function newPeriodPositionAction(Request $request, Period $period) if ($form->isSubmitted() && $form->isValid()) { $count = $form["nb_of_shifter"]->getData(); - $week_cycles = ($this->cycle_type == "abcd") ? $form["week_cycle"]->getData() : [Period::WEEK_A]; - foreach ($week_cycles as $week_cycle) { - $position->setWeekCycle($week_cycle); + + if ($this->cycle_type == "abcd") { + $week_cycles = $form["week_cycle"]->getData(); + foreach ($week_cycles as $week_cycle) { + $position->setWeekCycle($week_cycle); + $position->setCreatedBy($current_user); + foreach (range(0, $count-1) as $iteration) { + $p = clone($position); + $period->addPosition($p); + $em->persist($p); + } + } + } else { + $position->setWeekCycle(null); $position->setCreatedBy($current_user); foreach (range(0, $count-1) as $iteration) { $p = clone($position); @@ -219,10 +230,10 @@ public function newPeriodPositionAction(Request $request, Period $period) $em->persist($period); $em->flush(); - $session->getFlashBag()->add('success', $count . ' poste' . (($count>1) ? 's':'') . ' ajouté ' . (($count>1) ? 's':'') . ' (pour chaque cycle sélectionné) !'); + $session->getFlashBag()->add('success', $count . ' poste' . (($count>1) ? 's':'') . ' ajouté ' . (($count>1) ? 's':'') . (($this->cycle_type == "abcd") ? ' (pour chaque cycle sélectionné) !':' !')); } - return $this->redirectToRoute('admin_period_edit',array('id'=>$period->getId())); + return $this->redirectToRoute('admin_period_edit', array('id' => $period->getId())); } /** @@ -244,7 +255,7 @@ public function deletePeriodPositionAction(Request $request, Period $period, Per $session->getFlashBag()->add('success', 'Le poste ' . $position . ' a bien été supprimé !'); } - return $this->redirectToRoute('admin_period_edit',array('id'=>$period->getId())); + return $this->redirectToRoute('admin_period_edit', array('id' => $period->getId())); } /** diff --git a/src/AppBundle/Entity/PeriodPosition.php b/src/AppBundle/Entity/PeriodPosition.php index 23a125e29..dbd22b362 100644 --- a/src/AppBundle/Entity/PeriodPosition.php +++ b/src/AppBundle/Entity/PeriodPosition.php @@ -37,7 +37,7 @@ class PeriodPosition /** * @var string - * @ORM\Column(name="week_cycle", type="string", length=1, nullable=false) + * @ORM\Column(name="week_cycle", type="string", length=1, nullable=true) */ private $weekCycle; @@ -95,7 +95,10 @@ public function __construct() */ public function __toString() { - $name = $this->getPeriod() . ' - Semaine ' . $this->getWeekCycle(); + $name = (string) $this->getPeriod(); + if ($this->getWeekCycle()) { + $name .= ' - Semaine ' . $this->getWeekCycle(); + } if ($this->getFormation()) { $name .= ' (' . $this->getFormation()->getName() . ')'; } diff --git a/src/AppBundle/Form/PeriodPositionType.php b/src/AppBundle/Form/PeriodPositionType.php index d781ffddc..19aa52d6d 100644 --- a/src/AppBundle/Form/PeriodPositionType.php +++ b/src/AppBundle/Form/PeriodPositionType.php @@ -33,7 +33,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('week_cycle', ChoiceType::class, array( 'label' => 'Cycle', - 'choices' => ($this->cycle_type == 'abcd') ? Period::WEEK_CYCLE_CHOICE_LIST : [], + 'choices' => ($this->cycle_type == "abcd") ? Period::WEEK_CYCLE_CHOICE_LIST : [], 'expanded' => false, 'multiple' => true, // 'data' => ($this->cycle_type == 'abcd') ? null : [Period::WEEK_A]