From 966550dbaf95a87b604bd16fd57ba6e95f14309e Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Fri, 4 Aug 2023 20:46:04 +0200 Subject: [PATCH 1/4] Additional Period constants. Cleanup --- app/config/services.yml | 2 +- src/AppBundle/Controller/AdminController.php | 1 - .../Controller/HelloassoController.php | 1 - src/AppBundle/Entity/Period.php | 6 ++++- .../Form/AnonymousBeneficiaryType.php | 8 +++--- src/AppBundle/Form/PeriodPositionType.php | 26 ++++++------------- src/AppBundle/Form/PeriodType.php | 5 +--- src/AppBundle/Form/RegistrationType.php | 11 ++++---- 8 files changed, 24 insertions(+), 36 deletions(-) diff --git a/app/config/services.yml b/app/config/services.yml index 3ac1b92a7..bff40b970 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -14,7 +14,7 @@ services: # if you need to do this, you can override this setting on individual services public: false bind: - $localCurrency: '%local_currency_name%' + $local_currency_name: '%local_currency_name%' $use_fly_and_fixed: '%use_fly_and_fixed%' # makes classes in src/AppBundle available to be used as services diff --git a/src/AppBundle/Controller/AdminController.php b/src/AppBundle/Controller/AdminController.php index a02b0a213..85c59433f 100644 --- a/src/AppBundle/Controller/AdminController.php +++ b/src/AppBundle/Controller/AdminController.php @@ -13,7 +13,6 @@ use AppBundle\Entity\User; use AppBundle\Event\HelloassoEvent; use AppBundle\Form\BeneficiaryType; -use AppBundle\Form\RegistrationType; use AppBundle\Service\SearchUserFormHelper; use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\ORM\QueryBuilder; diff --git a/src/AppBundle/Controller/HelloassoController.php b/src/AppBundle/Controller/HelloassoController.php index 3ce492979..c8f92dec9 100644 --- a/src/AppBundle/Controller/HelloassoController.php +++ b/src/AppBundle/Controller/HelloassoController.php @@ -4,7 +4,6 @@ use AppBundle\Entity\HelloassoPayment; use AppBundle\Event\HelloassoEvent; -use AppBundle\Form\RegistrationType; use AppBundle\Form\AutocompleteBeneficiaryType; use Doctrine\ORM\Tools\Pagination\Paginator; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; diff --git a/src/AppBundle/Entity/Period.php b/src/AppBundle/Entity/Period.php index 34d9f6528..3ad14ea85 100644 --- a/src/AppBundle/Entity/Period.php +++ b/src/AppBundle/Entity/Period.php @@ -16,7 +16,11 @@ class Period { const DAYS_OF_WEEK = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"]; const DAYS_OF_WEEK_LIST_WITH_INT = ["Lundi" => 0, "Mardi" => 1, "Mercredi" => 2, "Jeudi" => 3, "Vendredi" => 4, "Samedi" => 5, "Dimanche" => 6]; - const WEEK_CYCLE = ["A", "B", "C", "D"]; + const WEEK_A = "A"; + const WEEK_B = "B"; + const WEEK_C = "C"; + const WEEK_D = "D"; + const WEEK_CYCLE = [Period::WEEK_A, Period::WEEK_B, Period::WEEK_C, Period::WEEK_D]; /** * @var int diff --git a/src/AppBundle/Form/AnonymousBeneficiaryType.php b/src/AppBundle/Form/AnonymousBeneficiaryType.php index 0e3387201..253a96c3f 100644 --- a/src/AppBundle/Form/AnonymousBeneficiaryType.php +++ b/src/AppBundle/Form/AnonymousBeneficiaryType.php @@ -17,12 +17,12 @@ class AnonymousBeneficiaryType extends AbstractType { - private $localCurrency; + private $local_currency_name; private $tokenStorage; - public function __construct(string $localCurrency, TokenStorageInterface $tokenStorage) + public function __construct(string $local_currency_name, TokenStorageInterface $tokenStorage) { - $this->localCurrency = $localCurrency; + $this->local_currency_name = $local_currency_name; $this->tokenStorage = $tokenStorage; } @@ -60,7 +60,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'choices' => array( 'Espèce' => Registration::TYPE_CASH, 'Chèque' => Registration::TYPE_CHECK, - $this->localCurrency => Registration::TYPE_LOCAL, + $this->local_currency_name => Registration::TYPE_LOCAL, 'Helloasso' => Registration::TYPE_HELLOASSO, ) )); diff --git a/src/AppBundle/Form/PeriodPositionType.php b/src/AppBundle/Form/PeriodPositionType.php index aab1b58bf..89016f7cd 100644 --- a/src/AppBundle/Form/PeriodPositionType.php +++ b/src/AppBundle/Form/PeriodPositionType.php @@ -3,6 +3,7 @@ namespace AppBundle\Form; use AppBundle\Entity\Formation; +use AppBundle\Entity\Period; use AppBundle\Entity\PeriodPosition; use AppBundle\Entity\PeriodRoom; use AppBundle\Entity\Role; @@ -20,27 +21,19 @@ class PeriodPositionType extends AbstractType { - const WEEKA = 'A'; - const WEEKB = 'B'; - const WEEKC = 'C'; - const WEEKD = 'D'; - - /** - * {@inheritdoc} - */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('week_cycle', ChoiceType::class, array( 'label' => 'Cycle', 'choices' => array( - "Semaine A" => self::WEEKA, - "Semaine B" => self::WEEKB, - "Semaine C" => self::WEEKC, - "Semaine D" => self::WEEKD, + "Semaine A" => Period::WEEK_A, + "Semaine B" => Period::WEEK_B, + "Semaine C" => Period::WEEK_C, + "Semaine D" => Period::WEEK_D, ), - 'expanded' => false, - 'multiple' => true, - 'empty_data' => [self::WEEKA, self::WEEKB, self::WEEKC, self::WEEKD] + 'expanded' => false, + 'multiple' => true, + 'empty_data' => Period::WEEK_CYCLE )) ->add('formation', EntityType::class, array( 'label'=>'Formation necessaire', @@ -55,7 +48,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) $form = $event->getForm(); // checks if the PeriodPosition object is "new" - // If no data is passed to the form, the data is "null". if (!$period_position || null === $period_position->getId()) { $form->add('nb_of_shifter', IntegerType::class, [ 'label' => 'Nombre de postes disponibles', @@ -87,6 +79,4 @@ public function getBlockPrefix() { return 'appbundle_period_position'; } - - } diff --git a/src/AppBundle/Form/PeriodType.php b/src/AppBundle/Form/PeriodType.php index eb467a72c..e6769b033 100644 --- a/src/AppBundle/Form/PeriodType.php +++ b/src/AppBundle/Form/PeriodType.php @@ -13,7 +13,6 @@ class PeriodType extends AbstractType { - /** * {@inheritdoc} */ @@ -27,7 +26,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'label' => 'Poste', 'class' => 'AppBundle:Job', 'choice_label'=> 'name', - 'multiple' => false, + 'multiple' => false, 'required' => true, 'query_builder' => function(JobRepository $repository) { $qb = $repository->createQueryBuilder('j'); @@ -56,6 +55,4 @@ public function getBlockPrefix() { return 'appbundle_period'; } - - } diff --git a/src/AppBundle/Form/RegistrationType.php b/src/AppBundle/Form/RegistrationType.php index 31f400580..48c857103 100644 --- a/src/AppBundle/Form/RegistrationType.php +++ b/src/AppBundle/Form/RegistrationType.php @@ -1,5 +1,4 @@ localCurrency = $localCurrency; + $this->local_currency_name = $local_currency_name; $this->tokenStorage = $tokenStorage; } @@ -78,7 +77,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'choices' => array( 'Espèce' => Registration::TYPE_CASH, 'Chèque' => Registration::TYPE_CHECK, - $this->localCurrency => Registration::TYPE_LOCAL, + $this->local_currency_name => Registration::TYPE_LOCAL, 'HelloAsso' => Registration::TYPE_HELLOASSO, ), 'label' => 'Mode de réglement', @@ -103,7 +102,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $form->add('mode', ChoiceType::class, array('choices' => array( 'Espèce' => Registration::TYPE_CASH, 'Chèque' => Registration::TYPE_CHECK, - $this->localCurrency => Registration::TYPE_LOCAL, + $this->local_currency_name => Registration::TYPE_LOCAL, // 'CB' => Registration::TYPE_CREDIT_CARD, ),'label' => 'Mode de réglement')); //todo, make it dynamic } From f002e733077267c3e2d984932c654452f357b5a6 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Fri, 4 Aug 2023 21:10:21 +0200 Subject: [PATCH 2/4] Allow to create PeriodPosition without choosing week_cycle (default to A) --- app/Resources/views/admin/period/edit.html.twig | 13 ++++++++----- app/config/services.yml | 1 + .../Controller/AdminPeriodController.php | 11 ++++++++++- src/AppBundle/Entity/Period.php | 1 + src/AppBundle/Form/PeriodPositionType.php | 17 ++++++++++------- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app/Resources/views/admin/period/edit.html.twig b/app/Resources/views/admin/period/edit.html.twig index bb6a23fb1..94803e5d1 100644 --- a/app/Resources/views/admin/period/edit.html.twig +++ b/app/Resources/views/admin/period/edit.html.twig @@ -158,10 +158,12 @@ {{ form_label(position_add_form.nb_of_shifter) }} {{ form_widget(position_add_form.nb_of_shifter) }} -
- {{ form_label(position_add_form.week_cycle) }} - {{ form_widget(position_add_form.week_cycle) }} -
+ {% if cycle_type == 'abcd' %} +
+ {{ form_label(position_add_form.week_cycle) }} + {{ form_widget(position_add_form.week_cycle) }} +
+ {% endif %}
{{ form_label(position_add_form.formation) }} {{ form_widget(position_add_form.formation) }} @@ -170,7 +172,8 @@
- {{ form_end(position_add_form) }} + {{ form_row(position_add_form._token) }} + {{ form_end(position_add_form, {'render_rest': false}) }}
  • diff --git a/app/config/services.yml b/app/config/services.yml index bff40b970..c6b72b639 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -16,6 +16,7 @@ services: bind: $local_currency_name: '%local_currency_name%' $use_fly_and_fixed: '%use_fly_and_fixed%' + $cycle_type: '%cycle_type%' # makes classes in src/AppBundle available to be used as services # this creates a service per class whose id is the fully-qualified class name diff --git a/src/AppBundle/Controller/AdminPeriodController.php b/src/AppBundle/Controller/AdminPeriodController.php index 8ac2e1b95..98fb78af4 100644 --- a/src/AppBundle/Controller/AdminPeriodController.php +++ b/src/AppBundle/Controller/AdminPeriodController.php @@ -31,6 +31,13 @@ */ class AdminPeriodController extends Controller { + private $cycle_type; + + public function __construct($cycle_type) + { + $this->cycle_type = $cycle_type; + } + /** * Display all the periods in a schedule (available and reserved) * @@ -198,7 +205,8 @@ public function newPeriodPositionAction(Request $request, Period $period) if ($form->isSubmitted() && $form->isValid()) { $count = $form["nb_of_shifter"]->getData(); - foreach ($form["week_cycle"]->getData() as $week_cycle) { + $week_cycles = ($this->cycle_type == "abcd") ? $form["week_cycle"]->getData() : [Period::WEEK_A]; + foreach ($week_cycles as $week_cycle) { $position->setWeekCycle($week_cycle); $position->setCreatedBy($current_user); foreach (range(0, $count-1) as $iteration) { @@ -207,6 +215,7 @@ public function newPeriodPositionAction(Request $request, Period $period) $em->persist($p); } } + $em->persist($period); $em->flush(); diff --git a/src/AppBundle/Entity/Period.php b/src/AppBundle/Entity/Period.php index 3ad14ea85..0b4172f3c 100644 --- a/src/AppBundle/Entity/Period.php +++ b/src/AppBundle/Entity/Period.php @@ -21,6 +21,7 @@ class Period const WEEK_C = "C"; const WEEK_D = "D"; const WEEK_CYCLE = [Period::WEEK_A, Period::WEEK_B, Period::WEEK_C, Period::WEEK_D]; + const WEEK_CYCLE_CHOICE_LIST = ["Semaine A" => Period::WEEK_A, "Semaine B" => Period::WEEK_B, "Semaine C" => Period::WEEK_C, "Semaine D" => Period::WEEK_D]; /** * @var int diff --git a/src/AppBundle/Form/PeriodPositionType.php b/src/AppBundle/Form/PeriodPositionType.php index 89016f7cd..d781ffddc 100644 --- a/src/AppBundle/Form/PeriodPositionType.php +++ b/src/AppBundle/Form/PeriodPositionType.php @@ -21,19 +21,22 @@ class PeriodPositionType extends AbstractType { + private $cycle_type; + + public function __construct($cycle_type) + { + $this->cycle_type = $cycle_type; + } + public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('week_cycle', ChoiceType::class, array( - 'label' => 'Cycle', 'choices' => array( - "Semaine A" => Period::WEEK_A, - "Semaine B" => Period::WEEK_B, - "Semaine C" => Period::WEEK_C, - "Semaine D" => Period::WEEK_D, - ), + 'label' => 'Cycle', + 'choices' => ($this->cycle_type == 'abcd') ? Period::WEEK_CYCLE_CHOICE_LIST : [], 'expanded' => false, 'multiple' => true, - 'empty_data' => Period::WEEK_CYCLE + // 'data' => ($this->cycle_type == 'abcd') ? null : [Period::WEEK_A] )) ->add('formation', EntityType::class, array( 'label'=>'Formation necessaire', From 8b710c879b0f3f50acd8946aa3f2c8d3b071bcaa Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Fri, 4 Aug 2023 21:13:00 +0200 Subject: [PATCH 3/4] Hide 'Semaine' in Period index --- app/Resources/views/admin/period/edit.html.twig | 4 +++- app/Resources/views/period/_partial/period_card.html.twig | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Resources/views/admin/period/edit.html.twig b/app/Resources/views/admin/period/edit.html.twig index 94803e5d1..53d467e76 100644 --- a/app/Resources/views/admin/period/edit.html.twig +++ b/app/Resources/views/admin/period/edit.html.twig @@ -41,7 +41,9 @@ Aucun poste n'existe pour ce créneau {% endif %} {% for week, positions in period.positionsperweekcycle %} -
    Semaine {{ week }}
    + {% if cycle_type == 'abcd' %} +
    Semaine {{ week }}
    + {% endif %}
      {% for position in positions %} {% if position.shifter %} diff --git a/app/Resources/views/period/_partial/period_card.html.twig b/app/Resources/views/period/_partial/period_card.html.twig index 547fad6ef..3b4871ef6 100644 --- a/app/Resources/views/period/_partial/period_card.html.twig +++ b/app/Resources/views/period/_partial/period_card.html.twig @@ -40,7 +40,9 @@ {# if display by job/training #}
      {% for week, positions in period.groupedpositionsperweekcycle(week_filter) %} -
      Semaine {{ week }}
      + {% if cycle_type == 'abcd' %} +
      Semaine {{ week }}
      + {% endif %} {% for training, nb_shifters in positions %} person{{ nb_shifters }} x {{ training }}
      @@ -53,7 +55,9 @@
      {% for week, positions in period.positionsperweekcycle %} {% if (week in week_filter) or not week_filter %} -
      Semaine {{ week }}
      + {% if cycle_type == 'abcd' %} +
      Semaine {{ week }}
      + {% endif %} {% for position in positions %} {% include 'period/_partial/position_shifter_display.html.twig' with { 'position': position, 'anonymized': anonymized } %} {% endfor %} From 4b00ff68f2bc22fe1194f5b1cafd853ad640a1c5 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Sat, 5 Aug 2023 09:45:35 +0200 Subject: [PATCH 4/4] Manage ShiftGenerateCommand when cycle_type is null (#938) --- src/AppBundle/Command/ShiftGenerateCommand.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/AppBundle/Command/ShiftGenerateCommand.php b/src/AppBundle/Command/ShiftGenerateCommand.php index 53b552421..c1601b595 100644 --- a/src/AppBundle/Command/ShiftGenerateCommand.php +++ b/src/AppBundle/Command/ShiftGenerateCommand.php @@ -32,6 +32,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $admin = $em->getRepository('AppBundle:User')->findSuperAdminAccount(); $use_fly_and_fixed = $this->getContainer()->getParameter('use_fly_and_fixed'); $reserve_new_shift_to_prior_shifter = $this->getContainer()->getParameter('reserve_new_shift_to_prior_shifter'); + $cycle_type = $this->getContainer()->getParameter('cycle_type'); + $week_cycle_array = $this->getContainer()->get('period_service')->getWeekCycleArray(); $from_given = $input->getArgument('date'); $to_given = $input->getOption('to'); @@ -56,7 +58,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $count_existing_all = 0; $reservedShifts = array(); $formerShifts = array(); - $weekCycle = array("A", "B", "C", "D"); foreach ($period as $date) { $count_new_period = 0; @@ -67,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($closingException) { $output->writeln('>>> FERMETURE EXCEPTIONNELLE : aucun créneau sera généré'); } else { - $dayOfWeek = $date->format('N') - 1; // 0 = 1-1 (for Monday) through 6=7-1 (for Sunday) + $dayOfWeek = $date->format('N') - 1; // 0 = 1-1 (for Monday) through 6 = 7-1 (for Sunday) $periods = $em->getRepository('AppBundle:Period')->createQueryBuilder('p') ->where('p.dayOfWeek = :dow') ->setParameter('dow', $dayOfWeek) @@ -83,11 +84,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $shift->setEnd($end); foreach ($period->getPositions() as $position) { - // Semaine #A-B-C-D - // Ignorer les periodes en dehors du cycle semaine - $weekCycleIndex = ($date->format('W') - 1) % 4; //0 = (1-1)%4 (first week) through 51 - if ($weekCycle[$weekCycleIndex] != $position->getWeekCycle()) { - continue; + if ($cycle_type == 'abcd') { + // Semaine ABCD : ignorer les positions qui ne correspondent pas à la date + $weekCycleIndex = ($date->format('W') - 1) % 4; // 0 = (1-1) % 4 (first week) through 2 = (51-1) % 4 (last week) + if ($week_cycle_array[$weekCycleIndex] != $position->getWeekCycle()) { + continue; + } } $already_generated = $em->getRepository('AppBundle:Shift')->findBy(array('start' => $start, 'end' => $end, 'job' => $period->getJob(), 'position' => $position));