Skip to content

Commit

Permalink
Membre : pouvoir rajouter la notion de volant (elefan-grenoble#1058)
Browse files Browse the repository at this point in the history
* New field Membership.flying

* New parameter use_fly_and_fixed_entity_flying

* Membership flying display

* Update SearchUserFormHelper

* Update controllers & PeriodService
  • Loading branch information
raphodn authored and OursDesCavernes committed Jan 20, 2024
1 parent 92a36d8 commit 1cda033
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 75 deletions.
36 changes: 36 additions & 0 deletions app/DoctrineMigrations/Version20231027213416_membership_flying.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231027213416 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() 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 membership ADD flying TINYINT(1) DEFAULT \'0\' NOT NULL');
$this->addSql('UPDATE membership LEFT OUTER JOIN beneficiary ON beneficiary.id = membership.main_beneficiary_id SET membership.flying=beneficiary.flying WHERE beneficiary.flying = 1');
}

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 membership DROP flying');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
{% if member.mainBeneficiary and not member.mainBeneficiary.user.isEnabled %}
<i class="material-icons" title="Compte pas encore activé">{{ user_account_not_enabled_material_icon }}</i>
{% endif %}
{% if use_fly_and_fixed and fly_and_fixed_entity_flying == 'Membership' and member.flying %}
<i class="material-icons" title="Compte volant">{{ member_flying_material_icon }}</i>
{% endif %}
8 changes: 6 additions & 2 deletions app/Resources/views/admin/period/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@
<li>{{ member_frozen_icon }} Membre gelé</li>
<li>{{ member_exempted_icon }} Membre exempté de créneaux</li>
<li>{{ member_registration_missing_icon }} Membre avec une adhésion expirée</li>
<li>{{ beneficiary_flying_icon }} Bénéficiaire avec un statut "volant"</li>
{% if fly_and_fixed_entity_flying == 'Membership' %}
<li>{{ beneficiary_flying_icon }} Membre avec un statut "volant"</li>
{% else %}
<li>{{ beneficiary_flying_icon }} Bénéficiaire avec un statut "volant"</li>
{% endif %}
</ul>
</td>
</tr>
Expand Down Expand Up @@ -234,7 +238,7 @@
<td>
{% for period in periods_by_day[key] %}
{% if ((filling_filter == null) and (beneficiary_filter == null))
or (filling_filter == "problematic" and period.isProblematic(week_filter))
or (filling_filter == "problematic" and period_service.hasWarningStatus(period, week_filter))
or (filling_filter == "empty" and period.isEmpty(week_filter))
or (filling_filter == "full" and period.isFull(week_filter))
or (filling_filter == "partial" and period.isPartial(week_filter))
Expand Down
30 changes: 20 additions & 10 deletions app/Resources/views/admin/user/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
<div class="col s12 m4">
<h5>Compte</h5>
<div class="row">
<div class="col s4">
<div class="col s3">
<div class="input-field">
{{ form_widget(form.withdrawn) }}
{{ form_label(form.withdrawn) }}
</div>
</div>
<div class="col s4">
<div class="col s3">
<div class="input-field">
{{ form_widget(form.enabled) }}
{{ form_label(form.enabled) }}
</div>
</div>
<div class="col s4">
<div class="col s3">
<div class="input-field">
{{ form_widget(form.frozen) }}
{{ form_label(form.frozen) }}
</div>
</div>
</div>
<div class="row">
<div class="col s4">
<div class="col s3">
<div class="input-field">
{{ form_widget(form.exempted) }}
{{ form_label(form.exempted) }}
</div>
</div>
</div>
<div class="row">
<div class="col s4">
<div class="input-field">
{{ form_widget(form.has_first_shift_date) }}
Expand All @@ -63,6 +63,14 @@
</div>
</div>
{% endif %}
{% if use_fly_and_fixed and fly_and_fixed_entity_flying == 'Membership' %}
<div class="col s4">
<div class="input-field">
{{ form_widget(form.flying) }}
{{ form_label(form.flying) }}
</div>
</div>
{% endif %}
</div>
<div class="row">
<div class="col s3">
Expand Down Expand Up @@ -176,10 +184,12 @@
{{ form_label(form.phone) }}
</div>
{% if use_fly_and_fixed %}
<div class="input-field">
{{ form_widget(form.flying) }}
{{ form_label(form.flying) }}
</div>
{% if fly_and_fixed_entity_flying == 'Beneficiary' %}
<div class="input-field">
{{ form_widget(form.flying) }}
{{ form_label(form.flying) }}
</div>
{% endif %}
<div class="input-field">
{{ form_widget(form.has_period_position) }}
{{ form_label(form.has_period_position) }}
Expand Down
25 changes: 15 additions & 10 deletions app/Resources/views/beneficiary/_partial/info.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
{% if beneficiary.isMain and maximum_nb_of_beneficiaries_in_membership > 1 %}
<span class="badge main-color white-text">{{ beneficiary_main_icon }} principal</span>
{% endif %}
{% if use_fly_and_fixed %}
{% if fly_and_fixed_entity_flying == 'Membership' %}
{% if beneficiary.membership.flying %}
<span class="badge teal white-text">{{ member_flying_icon }} Compte volant</span>
{% else %}
<span class="badge main-color white-text">Compte fixe</span>
{% endif %}
{% else %}
{% if beneficiary.flying %}
<span class="badge teal white-text">{{ beneficiary_flying_icon }} Equipe volante</span>
{% else %}
<span class="badge main-color white-text">Equipe fixe</span>
{% endif %}
{% endif %}
{% endif %}
{% if beneficiary.membership.withdrawn %}
<span class="badge red white-text">{{ member_withdrawn_icon }} fermé</span>
{% endif %}
Expand Down Expand Up @@ -61,16 +76,6 @@
{% endif %})
{% endif %}
</div>
{% if use_fly_and_fixed %}
<div class="col s12">
<i class="material-icons tiny">accessibility</i>
{% if beneficiary.flying %}
<div class="chip green-text">Equipe volante</div>
{% else %}
<div class="chip green-text">Equipe fixe</div>
{% endif %}
</div>
{% endif %}
{% if beneficiary.formations | length %}
<div class="col s12">
<i class="material-icons tiny">assignment_ind</i>
Expand Down
3 changes: 3 additions & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ twig:
member_exempted_icon: '%member_exempted_icon%'
member_exempted_material_icon: '%member_exempted_material_icon%'
member_exempted_background_color: '%member_exempted_background_color%'
member_flying_icon: '%member_flying_icon%'
member_flying_material_icon: '%member_flying_material_icon%'
member_registration_missing_icon: '%member_registration_missing_icon%'
member_registration_missing_material_icon: '%member_registration_missing_material_icon%'
member_registration_missing_background_color: '%member_registration_missing_background_color%'
Expand All @@ -105,6 +107,7 @@ twig:
display_name_shifters: '%display_name_shifters%'
use_card_reader_to_validate_shifts: '%use_card_reader_to_validate_shifts%'
# fly and fixed
fly_and_fixed_entity_flying: '%fly_and_fixed_entity_flying%'
fly_and_fixed_allow_fixed_shift_free: '%fly_and_fixed_allow_fixed_shift_free%'
# time log saving
time_log_saving_shift_free_min_time_in_advance_days: '%time_log_saving_shift_free_min_time_in_advance_days%'
Expand Down
3 changes: 3 additions & 0 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ parameters:

# Shifting: fly & fixed
use_fly_and_fixed: false
fly_and_fixed_entity_flying: 'Beneficiary'
fly_and_fixed_allow_fixed_shift_free: false

# Shifting: card reader
Expand Down Expand Up @@ -146,6 +147,8 @@ parameters:
member_exempted_icon: '☂'
member_exempted_material_icon: 'beach_access'
member_exempted_background_color: rgb(0, 150, 136, 0.1)
member_flying_icon: '✈'
member_flying_material_icon: 'flightsmode'
member_registration_missing_icon: '$'
member_registration_missing_material_icon: 'attach_money'
member_registration_missing_background_color: rgb(0, 150, 136, 0.1)
Expand Down
1 change: 1 addition & 0 deletions src/AppBundle/Command/ImportUsersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$membership = new Membership();
$output->writeln("<info>No Membership with number <fg=cyan>$member_number</> found, create one</info>",OutputInterface::VERBOSITY_DEBUG);
$membership->setMemberNumber($member_number);
$membership->setFlying(false);
$membership->setWithdrawn(false);
$membership->setFrozen(false);
$membership->setFrozenChange(false);
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 @@ -12,7 +12,6 @@
use AppBundle\Entity\Formation;
use AppBundle\Entity\User;
use AppBundle\Event\HelloassoEvent;
use AppBundle\Form\BeneficiaryType;
use AppBundle\Service\SearchUserFormHelper;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\ORM\QueryBuilder;
Expand Down
1 change: 1 addition & 0 deletions src/AppBundle/Controller/BeneficiaryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public function detachBeneficiaryAction(Request $request, Beneficiary $beneficia
$new_member->setMainBeneficiary($beneficiary);
}
// init other fields
$new_member->setFlying(false);
$new_member->setWithdrawn(false);
$new_member->setFrozen(false);
$new_member->setFrozenChange(false);
Expand Down
1 change: 1 addition & 0 deletions src/AppBundle/Controller/MembershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ public function newAction(Request $request)
$member->removeRegistration($registration); //no registration yet
}

$member->setFlying(false);
$member->setWithdrawn(false);
$member->setFrozen(false);
$member->setFrozenChange(false);
Expand Down
1 change: 0 additions & 1 deletion src/AppBundle/Controller/NoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use AppBundle\Entity\Shift;
use AppBundle\Entity\TimeLog;
use AppBundle\Entity\User;
use AppBundle\Form\BeneficiaryType;
use AppBundle\Form\NoteType;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Session\Session;
Expand Down
1 change: 0 additions & 1 deletion src/AppBundle/Controller/RegistrationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use AppBundle\Entity\Formation;
use AppBundle\Entity\User;
use AppBundle\Event\HelloassoEvent;
use AppBundle\Form\BeneficiaryType;
use AppBundle\Form\RegistrationType;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\ORM\QueryBuilder;
Expand Down
33 changes: 27 additions & 6 deletions src/AppBundle/Entity/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class Membership
*/
private $frozen_change;

/**
* @var bool
*
* @ORM\Column(name="flying", type="boolean", options={"default" : 0}, nullable=false)
*/
private $flying;

/**
* @ORM\OneToMany(targetEntity="Registration", mappedBy="membership",cascade={"persist", "remove"})
* @OrderBy({"date" = "DESC"})
Expand Down Expand Up @@ -116,19 +123,19 @@ class Membership
*/
private $timeLogs;

/**
* @ORM\OneToMany(targetEntity="MembershipShiftExemption", mappedBy="membership", cascade={"persist", "remove"})
* @OrderBy({"createdAt" = "DESC"})
*/
private $membershipShiftExemptions;

/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;

/**
* @ORM\OneToMany(targetEntity="MembershipShiftExemption", mappedBy="membership", cascade={"persist", "remove"})
* @OrderBy({"createdAt" = "DESC"})
*/
private $membershipShiftExemptions;

/**
* Membership constructor.
*/
Expand Down Expand Up @@ -489,6 +496,20 @@ public function getFrozenChange()
return $this->frozen_change;
}

/**
* @return bool
*/
public function isFlying(): ?bool {
return $this->flying;
}

/**
* @param bool $flying
*/
public function setFlying(?bool $flying): void {
$this->flying = $flying;
}

/**
* Get lastRegistration
*
Expand Down
25 changes: 0 additions & 25 deletions src/AppBundle/Entity/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,31 +460,6 @@ public function getGroupedPositionsPerWeekCycle(?String $weekCycle=null): array
return $aggregatePerWeekCycle;
}

/**
* Return true if at least one shifter (a.k.a. beneficiary) registered for
* this period is "problematic", meaning with a withdrawn or frozen membership
* of if the shifter is member of the flying team.
*
* useful only if the use_fly_and_fixed is activated
*
* @param String|null $weekCycle a string of the week to keep or null if no filter
* @return bool
*/
public function isProblematic(?String $weekCycle=null): bool
{
foreach ($this->positions as $position) {
if($shifter = $position->getShifter()){
if((($weekCycle && $position->getWeekCycle()==$weekCycle) or !$weekCycle)
and ($shifter->isFlying()
or $shifter->getMembership()->isFrozen()
or $shifter->getMembership()->isWithdrawn())){
return true;
}
}
}
return false;
}

/**
* Return true if 0 periods have been assigned to a shifter (a.k.a. beneficiary)
* Note: useful only if the use_fly_and_fixed is activated
Expand Down
2 changes: 0 additions & 2 deletions src/AppBundle/Form/BeneficiaryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,4 @@ public function getBlockPrefix()
{
return 'appbundle_beneficiary';
}


}
6 changes: 5 additions & 1 deletion src/AppBundle/Security/MembershipVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MembershipVoter extends Voter
const CLOSE = 'close';
const FREEZE = 'freeze';
const FREEZE_CHANGE = 'freeze_change';
const FLYING = 'flying';
const ROLE_REMOVE = 'role_remove';
const ROLE_ADD = 'role_add';
const ANNOTATE = 'annotate';
Expand All @@ -46,6 +47,7 @@ protected function supports($attribute, $subject)
self::ROLE_ADD,
self::FREEZE,
self::FREEZE_CHANGE,
self::FLYING,
self::CREATE,
self::ANNOTATE,
self::ACCESS_TOOLS,
Expand Down Expand Up @@ -104,6 +106,8 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
case self::ROLE_REMOVE:
case self::EDIT:
return $this->canEdit($subject, $token);
case self::FLYING:
return $this->canEdit($subject, $token);
}

throw new \LogicException('This code should not be reached!');
Expand Down Expand Up @@ -153,4 +157,4 @@ private function isLocationOk()
$ips = explode(',', $ips);
return (isset($checkIps) and !$checkIps) or (isset($ip) and in_array($ip, $ips));
}
}
}
Loading

0 comments on commit 1cda033

Please sign in to comment.