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 @@
Postes disponibles
- {% if use_fly_and_fixed %} - {% if (period.positionsperweekcycle | length == 0) %} - Aucun poste n'existe pour ce créneau - {% endif %} - {% for week, positions in period.positionsperweekcycle %} - {% if cycle_type == 'abcd' %} -
Semaine {{ week }}
- {% endif %} - - {% endfor %} - {% else %} - {% for week, positions in period.positionsperweekcycle %} + {% if (period.positionsperweekcycle | length == 0) %} + Aucun poste n'existe pour ce créneau + {% endif %} + {% for week, positions in period.positionsperweekcycle %} + {% if cycle_type == 'abcd' %}
Semaine {{ week }}
- + {% endfor %}
Actions supplémentaires
diff --git a/app/Resources/views/admin/periodposition/_partial/edit_collapsible.html.twig b/app/Resources/views/admin/periodposition/_partial/edit_collapsible.html.twig new file mode 100644 index 000000000..2e2d4811b --- /dev/null +++ b/app/Resources/views/admin/periodposition/_partial/edit_collapsible.html.twig @@ -0,0 +1,82 @@ + +
  • +
    +
    +
    + {% if use_fly_and_fixed %} + {% if position.shifter %} + {% if position.formation %}{% endif %} + {{ position.shifter.displayNameWithMemberNumber }} + {% if position.formation %} ({{ position.formation.name }}){% endif %} + {% if not position.formation and position.shifter.formations | length > 0 %} +  ({{ position.shifter.formations | join(', ') }}) + {% endif %} + {% if position.shifter.isNew %} +  {{ beneficiary_new_icon }} + {% endif %} + {% else %} + libre + {% if position.formation %} +  ({{ position.formation.name }}) + {% else %} +  (sans formation particulière) + {% endif %} + {% endif %} + {% else %} + {{ position }} + {% endif %} +
    +
    +
    +
    + {% if use_fly_and_fixed %} + {% if position.shifter %} +

    + 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) }} +
    +
    + {{ form_label(position_book_form.shifter) }} + {{ form_errors(position_book_form.shifter) }} + {{ form_widget(position_book_form.shifter) }} +
    +
    + +
    +
    + {{ form_end(position_book_form) }} + {% endif %} + {% endif %} + {% if not position.shifter %} + {% if is_granted("ROLE_ADMIN") %} +
    + {{ form_start(position_delete_form) }} + {{ form_widget(position_delete_form) }} + + deleteSupprimer + + {{ form_end(position_delete_form) }} +
    + {% endif %} + {% endif %} + {% if position.createdBy %} +

    + 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 %} +
    +
  • diff --git a/app/Resources/views/user/_partial/period_position_card.html.twig b/app/Resources/views/user/_partial/period_position_card.html.twig index d0f1ccd0e..33efc367a 100644 --- a/app/Resources/views/user/_partial/period_position_card.html.twig +++ b/app/Resources/views/user/_partial/period_position_card.html.twig @@ -3,7 +3,9 @@ {{ period_position.period.dayOfWeekString }} de {{ period_position.period.start | date('G\\hi') }} à {{ period_position.period.end | date('G\\hi') }}
    - (Semaine {{ period_position.weekCycle }}) + {% if cycle_type == 'abcd' %} + (Semaine {{ period_position.weekCycle }}) + {% 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]