Skip to content

Commit

Permalink
Déplacer la notion de volant du beneficiary vers le membership (#918)
Browse files Browse the repository at this point in the history
* Move close/reopen button at the top of the page

* Change flying status from beneficiary to membership
  • Loading branch information
petitalb authored and raphodn committed Oct 26, 2023
1 parent dc7f8bd commit e99f56a
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 162 deletions.
38 changes: 38 additions & 0 deletions app/DoctrineMigrations/Version20230729100654.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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 Version20230729100654 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');
$this->addSql('ALTER TABLE beneficiary DROP flying');
}

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 beneficiary ADD flying TINYINT(1) DEFAULT \'0\' NOT NULL');
$this->addSql('ALTER TABLE membership DROP flying');
}
}
10 changes: 0 additions & 10 deletions app/Resources/views/beneficiary/_partial/info.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,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
113 changes: 47 additions & 66 deletions app/Resources/views/member/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -219,72 +219,6 @@
</li>
{% endif %}

<!-- Fermer le compte -->
{% if is_granted("ROLE_USER_MANAGER") and is_granted("close",member) %}
<li id="close">
<div class="collapsible-header {% if frontend_cookie and frontend_cookie.user_show is defined and frontend_cookie.user_show.close_open is defined and frontend_cookie.user_show.close_open %}active{% endif %}">
<i class="material-icons">close</i>{% if member.withdrawn %}Ré-ouvrir le compte{% else %}Fermer le compte{% endif %}
</div>
<div class="collapsible-body white">
{% if not member.withdrawn %}
<a href="#close-member-confirmation-modal" class="modal-trigger waves-effect waves-light btn red">
<i class="material-icons left">close</i>Fermer le compte
</a>
{{ form_start(close_form) }}
<div id="close-member-confirmation-modal" class="modal">
<div class="modal-content">
<h5>
<i class="material-icons left small">remove_circle_outline</i>Fermeture du compte membre
</h5>
<p>Attention, vous êtes sur le point de fermer le compte du membre.</p>
<ul>
{% if use_fly_and_fixed %}
<li>Ce membre a {{ period_positions | length }} créneau{% if period_positions | length > 1 %}x{% endif %} fixe.</li>
{% endif %}
<li>Ce membre a {{ in_progress_and_upcoming_shifts | length }} créneau{% if in_progress_and_upcoming_shifts | length > 1 %}x{% endif %} réservé à venir.</li>
</ul>
</div>
<div class="modal-footer">
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat green-text">Retour à la raison</a>
<button type="submit" class="btn waves-effect waves-light orange">
<i class="material-icons left">check</i>Je sais ce que je fais !
</button>
</div>
</div>
{{ form_end(close_form) }}
{% else %}
{% if member.withdrawnDate %}
<p>
Compte fermé le <i>{{ member.withdrawnDate | date_fr }}</i>
{% if member.withdrawnBy %}
par {% include "admin/member/_partial/member_or_user_link.html.twig" with { user: member.withdrawnBy, target_blank: true } %}.
{% endif %}
</p>
{% endif %}
<a href="#open-member-confirmation-modal" class="modal-trigger waves-effect waves-light btn teal">
<i class="material-icons left">check</i>Ré-ouvrir le compte
</a>
{{ form_start(open_form) }}
<div id="open-member-confirmation-modal" class="modal">
<div class="modal-content">
<h5>
<i class="material-icons left small">info_outline</i>Ré-ouverture du compte membre
</h5>
<p>Attention, vous êtes sur le point de ré-ouvrir le compte du membre.</p>
</div>
<div class="modal-footer">
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat green-text">Retour à la raison</a>
<button type="submit" class="btn waves-effect waves-light orange">
<i class="material-icons left">check</i>Je sais ce que je fais !
</button>
</div>
</div>
{{ form_end(open_form) }}
{% endif %}
</div>
</li>
{% endif %}

<!-- Rôles -->
{% if is_granted("ROLE_ADMIN") %}
<li id="super">
Expand Down Expand Up @@ -346,6 +280,53 @@
</li>
{% endif %}
</ul>

<div id="withdrawn-member-confirmation-modal" class="modal">
<div class="modal-content">
<h5>
<i class="material-icons left small">remove_circle_outline</i>{% if member.withdrawn %}Ré-ouverture{% else %}Fermeture{% endif %} du compte membre
</h5>
<p>Attention, vous êtes sur le point de {% if member.withdrawn %}ré-ouvrir{% else %}fermer{% endif %} le compte du membre.</p>
{% if not member.withdrawn %}
<ul>
{% if use_fly_and_fixed %}
<li>Ce membre a {{ period_positions | length }} créneau{% if period_positions | length > 1 %}x{% endif %} fixe.</li>
{% endif %}
<li>Ce membre a {{ in_progress_and_upcoming_shifts | length }} créneau{% if in_progress_and_upcoming_shifts | length > 1 %}x{% endif %} réservé à venir.</li>
</ul>
{% endif %}
</div>
<div class="modal-footer">
{{ form_start(withdrawn_form) }}
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat green-text">Retour à la raison</a>
<button type="submit" class="btn waves-effect waves-light orange">
<i class="material-icons left">check</i>Je sais ce que je fais !
</button>
{{ form_end(withdrawn_form) }}
</div>
</div>

<div id="flying-member-confirmation-modal" class="modal">
<div class="modal-content">
<h5>
<i class="material-icons left small">remove_circle_outline</i>Passage du compte en {% if member.flying %}fixe{% else %}volant{% endif %}
</h5>
<p>Attention, vous êtes sur le point de passer le compte du membre en {% if member.flying %}fixe{% else %}volant{% endif %}.</p>
{% if not member.flying %}
<ul>
<li>Ce membre a {{ period_positions | length }} créneau{% if period_positions | length > 1 %}x{% endif %} fixe.</li>
</ul>
{% endif %}
</div>
<div class="modal-footer">
{{ form_start(flying_form) }}
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat green-text">Retour à la raison</a>
<button type="submit" class="btn waves-effect waves-light orange">
<i class="material-icons left">check</i>OK
</button>
{{ form_end(flying_form) }}
</div>
</div>
{% endblock %}

{% block javascripts %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Réservé
</div>
{% else %}
{% set warning = beneficiary_service.hasWarningStatus(shifter) %}
{% set warning = membership_service.hasWarningStatus(shifter.membership) %}
<a href="{{ path('member_show', { 'member_number': shifter.membership.memberNumber }) }}" target="_blank"
class="black-text tooltipped editable-box truncate" data-position="bottom"
data-tooltip="{{ shifter | print_with_number_and_status_icon | raw }} &#013;&#010; ({{ formation }})">
Expand Down
1 change: 0 additions & 1 deletion src/AppBundle/Command/ImportUsersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$dispatcher->dispatch(BeneficiaryCreatedEvent::NAME, new BeneficiaryCreatedEvent($beneficiary));

$beneficiary->setEmail($email);
$beneficiary->setFlying(false);

$em->persist($beneficiary);
}
Expand Down
1 change: 0 additions & 1 deletion src/AppBundle/Controller/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public function sendAction(Request $request, \Swift_Mailer $mailer)
$user = $em->getRepository(User::class)->findOneBy(array('email' => $nonMember));
if (is_object($user)) {
$fake_beneficiary = new Beneficiary();
$fake_beneficiary->setFlying(false);
$fake_beneficiary->setUser($user);
$fake_beneficiary->setFirstname($user->getUsername());
$fake_beneficiary->setLastname(' ');
Expand Down
93 changes: 63 additions & 30 deletions src/AppBundle/Controller/MembershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function showAction(Membership $member)
$freezeForm = $this->createFreezeForm($member);
$unfreezeForm = $this->createUnfreezeForm($member);
$freezeChangeForm = $this->createFreezeChangeForm($member);
$closeForm = $this->createCloseForm($member);
$openForm = $this->createOpenForm($member);
$flyingForm = $this->createFlyingForm($member);
$withdrawnForm = $this->createWithdrawnForm($member);
$deleteForm = $this->createDeleteForm($member);

$note = new Note();
Expand Down Expand Up @@ -197,8 +197,8 @@ public function showAction(Membership $member)
'freeze_form' => $freezeForm->createView(),
'unfreeze_form' => $unfreezeForm->createView(),
'freeze_change_form' => $freezeChangeForm->createView(),
'close_form' => $closeForm->createView(),
'open_form' => $openForm->createView(),
'flying_form' => $flyingForm->createView(),
'withdrawn_form' => $withdrawnForm->createView(),
'delete_form' => $deleteForm->createView(),
'time_log_new_form' => $timeLogNewForm->createView(),
'time_log_delete_forms' => $timeLogDeleteForms,
Expand Down Expand Up @@ -501,61 +501,94 @@ public function activeUserAccountAction(Request $request)


/**
* Close member
* Close/Reopen member
*
* @Route("/{id}/close", name="member_close", methods={"POST"})
* @Route("/{id}/withdrawn", name="member_withdrawn", methods={"POST"})
* @param Request $request
* @param Membership $member
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function closeAction(Request $request, Membership $member)
public function withdrawnAction(Request $request, Membership $member)
{
$this->denyAccessUnlessGranted('close', $member);

$current_user = $this->get('security.token_storage')->getToken()->getUser();
$session = new Session();

$form = $this->createCloseForm($member);
$form = $this->createWithdrawnForm($member);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$withdrawn = $form->get("withdrawn")->getData();
if ($withdrawn) {
$this->denyAccessUnlessGranted('close', $member);
if ($member->isWithdrawn()) {
$session->getFlashBag()->add('error', 'Ce compte est déjà fermé');
return $this->redirectToShow($member);
}
$member->setWithdrawnDate(new \DateTime('now'));
$member->setWithdrawnBy($current_user);
} else {
$this->denyAccessUnlessGranted('open', $member);
if (!$member->isWithdrawn()) {
$session->getFlashBag()->add('error', 'Ce compte est déjà ouvert');
return $this->redirectToShow($member);
}
}
$member->setWithdrawn($withdrawn);
$em = $this->getDoctrine()->getManager();
$member->setWithdrawn(true);
$member->setWithdrawnDate(new \DateTime('now'));
$member->setWithdrawnBy($current_user);
$em->persist($member);
$em->flush();

$session->getFlashBag()->add('success', 'Compte fermé !');
if ($withdrawn) {
$session->getFlashBag()->add('success', 'Compte fermé !');
} else {
$session->getFlashBag()->add('success', 'Compte ré-ouvert !');
}
}

return $this->redirectToShow($member);
}

/**
* Open member
* Change flying status member
*
* @Route("/{id}/open", name="member_open", methods={"POST"})
* @Route("/{id}/flying", name="member_flying", methods={"POST"})
* @param Request $request
* @param Membership $member
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function openAction(Request $request, Membership $member)
public function flyingAction(Request $request, Membership $member)
{
$this->denyAccessUnlessGranted('open', $member);
$this->denyAccessUnlessGranted('flying', $member);
$current_user = $this->get('security.token_storage')->getToken()->getUser();
$session = new Session();

$form = $this->createOpenForm($member);
$form = $this->createFlyingForm($member);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$session = new Session();
$flying = $form->get("flying")->getData();
if ($flying) {
if ($member->isFlying()) {
$session->getFlashBag()->add('error', 'Ce compte est déjà volant');
return $this->redirectToShow($member);
}
} else {
if (!$member->isFlying()) {
$session->getFlashBag()->add('error', 'Ce compte est déjà fixe');
return $this->redirectToShow($member);
}
}
$member->setFlying($flying);
$em = $this->getDoctrine()->getManager();

$member->setWithdrawn(false);
$em->persist($member);
$em->flush();

$session->getFlashBag()->add('success', 'Compte ré-ouvert !');
if ($flying) {
$session->getFlashBag()->add('success', 'Le compte est volant !');
} else {
$session->getFlashBag()->add('success', 'Le compte est fixe !');
}
}

return $this->redirectToShow($member);
Expand Down Expand Up @@ -732,7 +765,6 @@ public function newAction(Request $request)
$user->setEmail($a_beneficiary->getEmail());
$beneficiary = new Beneficiary();
$beneficiary->setUser($user);
$beneficiary->setFlying(false);
$member->setMainBeneficiary($beneficiary);
}

Expand Down Expand Up @@ -880,7 +912,6 @@ public function addBeneficiaryAction(Request $request)

$beneficiary = new Beneficiary();
$beneficiary->setUser(new User());
$beneficiary->setFlying(false);
$beneficiary->setEmail($a_beneficiary->getEmail());

$form->get('beneficiary')->setData($beneficiary);
Expand Down Expand Up @@ -1118,29 +1149,31 @@ private function createFreezeChangeForm(Membership $member)
}

/**
* Creates a form to close a member entity.
* Creates a form to close or open a member entity.
*
* @param Membership $member
* @return \Symfony\Component\Form\FormInterface
*/
private function createCloseForm(Membership $member)
private function createWithdrawnForm(Membership $member)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('member_close', array('id' => $member->getId())))
->setAction($this->generateUrl('member_withdrawn', array('id' => $member->getId())))
->add('withdrawn', HiddenType::class, ['data' => $member->isWithdrawn() ? 0 : 1])
->setMethod('POST')
->getForm();
}

/**
* Creates a form to open a member entity.
* Creates a form to set flying for a member entity.
*
* @param Membership $member
* @return \Symfony\Component\Form\FormInterface
*/
private function createOpenForm(Membership $member)
private function createFlyingForm(Membership $member)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('member_open', array('id' => $member->getId())))
->setAction($this->generateUrl('member_flying', array('id' => $member->getId())))
->add('flying', HiddenType::class, ['data' => $member->isFlying() ? 0 : 1])
->setMethod('POST')
->getForm();
}
Expand Down
Loading

0 comments on commit e99f56a

Please sign in to comment.