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

Refactoring : renommer ShiftExemptionController en AdminShiftExemptionController #1023

Merged
merged 3 commits into from
Sep 30, 2023
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
6 changes: 4 additions & 2 deletions app/Resources/views/admin/shiftexemption/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_shiftexemption_index') }}"><i class="material-icons">list</i>&nbsp;Liste des exemptions de bénévolat</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_shiftexemption_index') }}"><i class="material-icons">list</i>&nbsp;Liste des motifs d'exemptions de bénévolat</a><i class="material-icons">chevron_right</i>
<i class="material-icons">edit</i>&nbsp;Editer
{% endblock %}

Expand All @@ -16,7 +16,9 @@

{% if is_granted("ROLE_SUPER_ADMIN") %}
{{ form_start(delete_form) }}
<button type="submit" class="btn waves-effect waves-light red"><i class="material-icons left">delete</i>Supprimer</button>
<button type="submit" class="btn waves-effect waves-light red" onclick="var r = confirm('Etes-vous sûr de vouloir supprimer ce motif d\'exemption ?!'); if (r == true) {$(this).closest('form').submit();}; event.stopPropagation();">
<i class="material-icons left">delete</i>Supprimer
</button>
{{ form_end(delete_form) }}
{% endif %}
{% endblock %}
2 changes: 1 addition & 1 deletion app/Resources/views/admin/shiftexemption/index.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'layout.html.twig' %}

{% block title %}Liste des exemptions de bénévolat - {{ site_name }}{% endblock %}
{% block title %}Liste des motifs d'exemptions de bénévolat - {{ site_name }}{% endblock %}

{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
Expand Down
4 changes: 2 additions & 2 deletions app/Resources/views/admin/shiftexemption/new.html.twig
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% extends 'layout.html.twig' %}

{% block title %}Ajouter une exemption de bénévolat - {{ site_name }}{% endblock %}
{% block title %}Ajouter un motif d'exemption de bénévolat - {{ site_name }}{% endblock %}

{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_shiftexemption_index') }}"><i class="material-icons">list</i>&nbsp;Liste des exemptions de bénévolat</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_shiftexemption_index') }}"><i class="material-icons">list</i>&nbsp;Liste des motifs d'exemptions de bénévolat</a><i class="material-icons">chevron_right</i>
<i class="material-icons">add</i>&nbsp;Ajouter
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use \Datetime;

/**
* MembershipShiftExemption controller.
* Admin MembershipShiftExemption controller.
*
* @Route("admin/membershipshiftexemption")
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Symfony\Component\HttpFoundation\Session\Session;

/**
* Shiftexemption controller.
* Admin Shiftexemption controller.
*
* @Route("admin/shifts/exemptions")
*/
class ShiftExemptionController extends Controller
class AdminShiftExemptionController extends Controller
{
/**
* Lists all shiftExemption entities.
Expand Down Expand Up @@ -42,12 +42,13 @@ public function indexAction(Request $request)
public function newAction(Request $request)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();

$shiftExemption = new Shiftexemption();
$form = $this->createForm('AppBundle\Form\ShiftExemptionType', $shiftExemption);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($shiftExemption);
$em->flush();

Expand All @@ -70,21 +71,22 @@ public function newAction(Request $request)
public function editAction(Request $request, ShiftExemption $shiftExemption)
{
$session = new Session();
$deleteForm = $this->createDeleteForm($shiftExemption);
$editForm = $this->createForm('AppBundle\Form\ShiftExemptionType', $shiftExemption);
$editForm->handleRequest($request);
$em = $this->getDoctrine()->getManager();

if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
$form = $this->createForm('AppBundle\Form\ShiftExemptionType', $shiftExemption);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em->flush();

$session->getFlashBag()->add('success', 'Le motif d\'exemption a bien été édité !');
return $this->redirectToRoute('admin_shiftexemption_index');
}

return $this->render('admin/shiftexemption/edit.html.twig', array(
'shiftExemption' => $shiftExemption,
'form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
'form' => $form->createView(),
'delete_form' => $this->getDeleteForm($shiftExemption)->createView(),
));
}

Expand All @@ -97,11 +99,13 @@ public function editAction(Request $request, ShiftExemption $shiftExemption)
public function deleteAction(Request $request, ShiftExemption $shiftExemption)
{
$session = new Session();
$form = $this->createDeleteForm($shiftExemption);
$em = $this->getDoctrine()->getManager();

$form = $this->getDeleteForm($shiftExemption);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
// TODO: error 500 if shiftExemption is used in membershipShiftExemption
$em->remove($shiftExemption);
$em->flush();
$session->getFlashBag()->add('success', 'Le motif d\'exemption bien été supprimé !');
Expand All @@ -117,12 +121,11 @@ public function deleteAction(Request $request, ShiftExemption $shiftExemption)
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(ShiftExemption $shiftExemption)
private function getDeleteForm(ShiftExemption $shiftExemption)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('admin_shiftexemption_delete', array('id' => $shiftExemption->getId())))
->setMethod('DELETE')
->getForm()
;
->getForm();
}
}