Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semaine type : pouvoir créer des créneaux type même si cycle_type est null #937

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions app/Resources/views/admin/period/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
Aucun poste n'existe pour ce créneau
{% endif %}
{% for week, positions in period.positionsperweekcycle %}
<h6>Semaine {{ week }}</h6>
{% if cycle_type == 'abcd' %}
<h6>Semaine {{ week }}</h6>
{% endif %}
<ul class="collapsible">
{% for position in positions %}
{% if position.shifter %}
Expand Down Expand Up @@ -158,10 +160,12 @@
{{ form_label(position_add_form.nb_of_shifter) }}
{{ form_widget(position_add_form.nb_of_shifter) }}
</div>
<div class="col s3">
{{ form_label(position_add_form.week_cycle) }}
{{ form_widget(position_add_form.week_cycle) }}
</div>
{% if cycle_type == 'abcd' %}
<div class="col s3">
{{ form_label(position_add_form.week_cycle) }}
{{ form_widget(position_add_form.week_cycle) }}
</div>
{% endif %}
<div class="col s6">
{{ form_label(position_add_form.formation) }}
{{ form_widget(position_add_form.formation) }}
Expand All @@ -170,7 +174,8 @@
<button type="submit" class="btn waves-effect waves-light teal"><i class="material-icons left">add</i>Ajouter</button>
</div>
</div>
{{ form_end(position_add_form) }}
{{ form_row(position_add_form._token) }}
{{ form_end(position_add_form, {'render_rest': false}) }}
</div>
</li>
<li>
Expand Down
8 changes: 6 additions & 2 deletions app/Resources/views/period/_partial/period_card.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
{# if display by job/training #}
<div id="training" style="margin-top:1em;">
{% for week, positions in period.groupedpositionsperweekcycle(week_filter) %}
<h6>Semaine {{ week }}</h6>
{% if cycle_type == 'abcd' %}
<h6>Semaine {{ week }}</h6>
{% endif %}
{% for training, nb_shifters in positions %}
<i class="material-icons">person</i>{{ nb_shifters }} x {{ training }}
<br/>
Expand All @@ -53,7 +55,9 @@
<div id="shifter" style="margin-top:1em;">
{% for week, positions in period.positionsperweekcycle %}
{% if (week in week_filter) or not week_filter %}
<h6>Semaine {{ week }}</h6>
{% if cycle_type == 'abcd' %}
<h6>Semaine {{ week }}</h6>
{% endif %}
{% for position in positions %}
{% include 'period/_partial/position_shifter_display.html.twig' with { 'position': position, 'anonymized': anonymized } %}
{% endfor %}
Expand Down
3 changes: 2 additions & 1 deletion app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ 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%'
$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
Expand Down
16 changes: 9 additions & 7 deletions src/AppBundle/Command/ShiftGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand All @@ -67,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($closingException) {
$output->writeln('<fg=cyan;>>>></><fg=red;> 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)
Expand All @@ -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));
Expand Down
1 change: 0 additions & 1 deletion src/AppBundle/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/AppBundle/Controller/AdminPeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down Expand Up @@ -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) {
Expand All @@ -207,6 +215,7 @@ public function newPeriodPositionAction(Request $request, Period $period)
$em->persist($p);
}
}

$em->persist($period);
$em->flush();

Expand Down
1 change: 0 additions & 1 deletion src/AppBundle/Controller/HelloassoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/AppBundle/Entity/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ 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];
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
Expand Down
8 changes: 4 additions & 4 deletions src/AppBundle/Form/AnonymousBeneficiaryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
)
));
Expand Down
31 changes: 12 additions & 19 deletions src/AppBundle/Form/PeriodPositionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,27 +21,22 @@

class PeriodPositionType extends AbstractType
{
const WEEKA = 'A';
const WEEKB = 'B';
const WEEKC = 'C';
const WEEKD = 'D';
private $cycle_type;

public function __construct($cycle_type)
{
$this->cycle_type = $cycle_type;
}

/**
* {@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,
),
'expanded' => false,
'multiple' => true,
'empty_data' => [self::WEEKA, self::WEEKB, self::WEEKC, self::WEEKD]
'label' => 'Cycle',
'choices' => ($this->cycle_type == 'abcd') ? Period::WEEK_CYCLE_CHOICE_LIST : [],
'expanded' => false,
'multiple' => true,
// 'data' => ($this->cycle_type == 'abcd') ? null : [Period::WEEK_A]
))
->add('formation', EntityType::class, array(
'label'=>'Formation necessaire',
Expand All @@ -55,7 +51,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',
Expand Down Expand Up @@ -87,6 +82,4 @@ public function getBlockPrefix()
{
return 'appbundle_period_position';
}


}
5 changes: 1 addition & 4 deletions src/AppBundle/Form/PeriodType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class PeriodType extends AbstractType
{

/**
* {@inheritdoc}
*/
Expand All @@ -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');
Expand Down Expand Up @@ -56,6 +55,4 @@ public function getBlockPrefix()
{
return 'appbundle_period';
}


}
11 changes: 5 additions & 6 deletions src/AppBundle/Form/RegistrationType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
// src/AppBundle/Form/RegistrationType.php

namespace AppBundle\Form;

Expand All @@ -18,12 +17,12 @@

class RegistrationType 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;
}

Expand Down Expand Up @@ -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',
Expand All @@ -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
}
Expand Down
Loading