Skip to content

Commit

Permalink
Transform member_freeze_change into POST form
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 23, 2022
1 parent 4190f68 commit ffa1f7e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 32 deletions.
20 changes: 11 additions & 9 deletions app/Resources/views/member/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -209,27 +209,29 @@
</div>
<div class="collapsible-body white">
{% if is_granted("freeze_change", member) %}
{{ form_start(freeze_change_form) }}
{% if not member.frozen %}
{% if member.frozenChange %}
<a href="{{ path("member_freeze_change",{"id":member.id}) }}" class="waves-effect waves-light btn orange">
<button type="submit" class="btn waves-effect waves-light orange">
<i class="material-icons left">cancel</i>Annuler la demande de gel du compte
</a>
</button>
{% else %}
<a href="{{ path("member_freeze_change",{"id":member.id}) }}" class="waves-effect waves-light btn deep-purple">
<button type="submit" class="btn waves-effect waves-light deep-purple">
<i class="material-icons left">paused</i>Geler le compte à la fin du cycle
</a>
</button>
{% endif %}
{% else %}
{% if member.frozenChange %}
<a href="{{ path("member_freeze_change",{"id":member.id}) }}" class="waves-effect waves-light btn orange">
<button type="submit" class="btn waves-effect waves-light orange">
<i class="material-icons left">cancel</i>Annuler la demande de dégel du compte
</a>
</button>
{% else %}
<a href="{{ path("member_freeze_change",{"id":member.id}) }}" class="waves-effect waves-light btn waves-purple purple lighten-2">
<i class="material-icons left">play_arrow</i>Dégeler le compte à la fin du cycle
</a>
<button type="submit" class="btn waves-effect waves-light deep-purple lighten-2">
<i class="material-icons left">paused</i>Geler le compte à la fin du cycle
</button>
{% endif %}
{% endif %}
{{ form_end(freeze_change_form) }}
{% endif %}
{% if is_granted("freeze", member) %}
{% if not member.frozen %}
Expand Down
70 changes: 47 additions & 23 deletions src/AppBundle/Controller/MembershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ 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);
$deleteForm = $this->createDeleteForm($member);
Expand Down Expand Up @@ -171,6 +172,7 @@ public function showAction(Membership $member)
'delete_beneficiary_forms' => $deleteBeneficiaryForms,
'freeze_form' => $freezeForm->createView(),
'unfreeze_form' => $unfreezeForm->createView(),
'freeze_change_form' => $freezeChangeForm->createView(),
'close_form' => $closeForm->createView(),
'open_form' => $openForm->createView(),
'delete_form' => $deleteForm->createView(),
Expand Down Expand Up @@ -527,14 +529,13 @@ public function openAction(Request $request, Membership $member)
{
$this->denyAccessUnlessGranted('open', $member);

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

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

if ($form->isSubmitted() && $form->isValid()) {
$session = new Session();
$em = $this->getDoctrine()->getManager();

$member->setWithdrawn(false);
$em->persist($member);
$em->flush();
Expand All @@ -558,14 +559,13 @@ public function freezeAction(Request $request, Membership $member)
{
$this->denyAccessUnlessGranted('freeze', $member);

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

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

if ($form->isSubmitted() && $form->isValid()) {
$session = new Session();
$em = $this->getDoctrine()->getManager();

$member->setFrozen(true);
$member->setFrozenChange(false);
$em->persist($member);
Expand All @@ -590,14 +590,13 @@ public function unfreezeAction(Request $request, Membership $member)
{
$this->denyAccessUnlessGranted('freeze', $member);

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

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

if ($form->isSubmitted() && $form->isValid()) {
$session = new Session();
$em = $this->getDoctrine()->getManager();

$member->setFrozen(false);
$member->setFrozenChange(false);
$em->persist($member);
Expand All @@ -613,23 +612,33 @@ public function unfreezeAction(Request $request, Membership $member)
* Ask freeze status change for user
*
* @Route("/{id}/freeze_change", name="member_freeze_change")
* @Method({"GET"})
* @Method({"POST"})
* @param Request $request
* @param Membership $member
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function freezeChangeAction(Membership $member)
public function freezeChangeAction(Request $request, Membership $member)
{
$this->denyAccessUnlessGranted('freeze_change', $member);
$session = new Session();
$em = $this->getDoctrine()->getManager();
$member->setFrozenChange(!$member->getFrozenChange());
$em->persist($member);
$em->flush();
if ($member->getFrozenChange()) {
$session->getFlashBag()->add('success', 'Le compte sera gelé à la fin du cycle');
} else {
$session->getFlashBag()->add('success', 'Le compte sera dégelé à la fin du cycle');

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

if ($form->isSubmitted() && $form->isValid()) {
$session = new Session();
$em = $this->getDoctrine()->getManager();

$member->setFrozenChange(!$member->getFrozenChange());
$em->persist($member);
$em->flush();

if ($member->getFrozenChange()) {
$session->getFlashBag()->add('success', 'Le compte sera gelé à la fin du cycle !');
} else {
$session->getFlashBag()->add('success', 'Le compte sera dégelé à la fin du cycle !');
}
}

if ($this->getCurrentAppUser()->getBeneficiary() && $member === $this->getCurrentAppUser()->getBeneficiary()->getMembership()) {
return $this->redirectToRoute("fos_user_profile_show");
} else {
Expand All @@ -640,7 +649,7 @@ public function freezeChangeAction(Membership $member)
/**
* Delete member
*
* @Route("/delete/{id}", name="member_delete")
* @Route("/{id}", name="member_delete")
* @Method("DELETE")
* @Security("has_role('ROLE_SUPER_ADMIN')")
* @param Request $request
Expand All @@ -649,16 +658,17 @@ public function freezeChangeAction(Membership $member)
*/
public function deleteAction(Request $request, Membership $member)
{
$session = new Session();

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

$session = new Session();
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($member);
$em->flush();

$session->getFlashBag()->add('success', "Le membre a bien été supprimé");
$session->getFlashBag()->add('success', "Le membre a bien été supprimé !");
}

return $this->redirectToRoute('user_index');
Expand Down Expand Up @@ -1073,6 +1083,20 @@ private function createUnfreezeForm(Membership $member)
->getForm();
}

/**
* Creates a form to edit member frozen_change
*
* @param Membership $member
* @return \Symfony\Component\Form\FormInterface
*/
private function createFreezeChangeForm(Membership $member)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('member_freeze_change', array('id' => $member->getId())))
->setMethod('POST')
->getForm();
}

/**
* Creates a form to close a member entity.
*
Expand Down

0 comments on commit ffa1f7e

Please sign in to comment.