Skip to content

Commit

Permalink
Allow to create PeriodPosition without choosing week_cycle (default t…
Browse files Browse the repository at this point in the history
…o A)
  • Loading branch information
raphodn committed Aug 4, 2023
1 parent 966550d commit f002e73
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
13 changes: 8 additions & 5 deletions app/Resources/views/admin/period/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,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 +172,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
1 change: 1 addition & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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: 1 addition & 0 deletions src/AppBundle/Entity/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions src/AppBundle/Form/PeriodPositionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f002e73

Please sign in to comment.