Skip to content

Commit

Permalink
Exemptions : filtre basique sur la liste des membres exemptés (elefan…
Browse files Browse the repository at this point in the history
…-grenoble#726)

* Cleanup a bit the template

* Add ShiftExemption.created_at. Add mapping for ManyToOne

* Simple filter form
  • Loading branch information
raphodn authored and quot17 committed Mar 28, 2023
1 parent 9c765cc commit 9b90f75
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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 Version20230130112101 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 shift_exemption ADD created_at DATETIME NOT NULL');
}

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 shift_exemption DROP created_at');
}
}
2 changes: 1 addition & 1 deletion app/Resources/views/admin/job/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
</div>
</div>
{{ form_widget(filter_form.filter) }}
{{ form_end(filter_form) }}
</div>
</li>
</ul>
{{ form_end(filter_form) }}

<table class="responsive-table">
<thead>
Expand Down
52 changes: 40 additions & 12 deletions app/Resources/views/admin/membershipshiftexemption/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,34 @@
{% block content %}
<h4>Liste des membres exempté.e.s de bénévolat ({{ membershipShiftExemptions | length }})</h4>

{# Filter form --------- #}
<ul class="collapsible">
<li>
<div class="collapsible-header">
<i class="material-icons">tune</i>Filtres
</div>
<div class="collapsible-body">
{{ form_start(filter_form) }}
<div class="row">
<div class="col s4">
<div class="input-field">
{{ form_widget(filter_form.shiftExemption) }}
{{ form_label(filter_form.shiftExemption) }}
</div>
</div>
</div>
{{ form_widget(filter_form.submit) }}
{{ form_end(filter_form) }}
</div>
</li>
</ul>

<table class="responsive-table">
<thead>
<tr>
<th>Etat</th>
<th>Membre</th>
<th>Raison</th>
<th>Motif</th>
<th>Description</th>
<th>Début</th>
<th>Fin</th>
Expand All @@ -40,35 +62,39 @@
<i class="material-icons" title="À venir">schedule</i>
{% endif %}
</td>
<td>{{ membershipShiftExemption.membership.beneficiaries | map(b => "<a href=\'#{path('member_show',{'member_number': b.membership.memberNumber})}\'>#{b}</a>") | join('<br/>') | raw }}</td>
<td>
<a href="{{ path("member_show", { 'member_number': membershipShiftExemption.membership.memberNumber }) }}">
{{ membershipShiftExemption.membership.beneficiaries | join('<br/>') | raw }}
</a>
</td>
<td>{{ membershipShiftExemption.shiftExemption }}</td>
<td>{{ membershipShiftExemption.description }}</td>
<td>
{% if membershipShiftExemption.start %}
{{ membershipShiftExemption.start|date('Y-m-d') }}
{{ membershipShiftExemption.start | date('d/m/Y') }}
{% endif %}
</td>
<td>
{% if membershipShiftExemption.end %}
{{ membershipShiftExemption.end|date('Y-m-d') }}
{{ membershipShiftExemption.end | date('d/m/Y') }}
{% endif %}
</td>
<td>
{% if membershipShiftExemption.createdBy and membershipShiftExemption.createdBy.beneficiary %}
<a href="{{ path("member_show",{'member_number': membershipShiftExemption.createdBy.beneficiary.membership.memberNumber}) }}">
<a href="{{ path("member_show", { 'member_number': membershipShiftExemption.createdBy.beneficiary.membership.memberNumber }) }}">
{{ membershipShiftExemption.createdBy.beneficiary }}
</a>
{% else %}
{{membershipShiftExemption.createdBy}}
{{ membershipShiftExemption.createdBy }}
{% endif %}
</td>
<td>
{% if membershipShiftExemption.createdAt %}
{{ membershipShiftExemption.createdAt|date('Y-m-d H:i:s') }}
{% endif %}
<td title="{{ membershipShiftExemption.createdAt | date('d/m/Y H:i') }}">
{{ membershipShiftExemption.createdAt | date('d/m/Y') }}
</td>
<td>
<a href="{{ path('admin_membershipshiftexemption_edit', { 'id': membershipShiftExemption.id }) }}"><i class="material-icons">edit</i>editer</a>
<a href="{{ path('admin_membershipshiftexemption_edit', { 'id': membershipShiftExemption.id }) }}">
<i class="material-icons">edit</i>Editer
</a>
</td>
</tr>
{% endfor %}
Expand All @@ -93,7 +119,9 @@

<ul>
<li>
<a href="{{ path('admin_membershipshiftexemption_new') }}" class="btn"><i class="material-icons left">add</i>Ajouter une exemption</a>
<a href="{{ path('admin_membershipshiftexemption_new') }}" class="btn">
<i class="material-icons left">add</i>Ajouter une exemption
</a>
</li>
</ul>
{% endblock %}
6 changes: 4 additions & 2 deletions app/Resources/views/admin/shiftexemption/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
{% 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>
<i class="material-icons">list</i>&nbsp;Liste des exemptions de bénévolat
<i class="material-icons">list</i>&nbsp;Liste des motifs d'exemptions de bénévolat
{% endblock %}

{% block content %}
<h4>Liste des exemptions de bénévolat ({{ shiftExemptions | length }})</h4>
<h4>Liste des motifs d'exemptions de bénévolat ({{ shiftExemptions | length }})</h4>

<table class="responsive-table">
<thead>
<tr>
<th>Exemption</th>
<th>Nombre d'exemptions</th>
<th>Actions</th>
</tr>
</thead>
Expand All @@ -23,6 +24,7 @@
{% for shiftExemption in shiftExemptions %}
<tr>
<td>{{ shiftExemption.name }}</td>
<td>{{ shiftExemption.membershipShiftExemptions | length }}</td>
<td>
<a href="{{ path('admin_shiftexemption_edit', { 'id': shiftExemption.id }) }}"><i class="material-icons">edit</i>editer</a>
</td>
Expand Down
60 changes: 54 additions & 6 deletions src/AppBundle/Controller/MembershipShiftExemptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

use AppBundle\Entity\Beneficiary;
use AppBundle\Entity\MembershipShiftExemption;
use AppBundle\Repository\ShiftExemptionRepository;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use \Datetime;

/**
Expand All @@ -18,30 +21,75 @@
*/
class MembershipShiftExemptionController extends Controller
{
/**
* Filter form.
*/
private function filterFormFactory(Request $request): array
{
// default values
$res = [
"shiftExemption" => null,
];

// filter creation ----------------------
$res["form"] = $this->createFormBuilder()
->setAction($this->generateUrl('admin_membershipshiftexemption_index'))
->add('shiftExemption', EntityType::class, array(
'label' => 'Motif',
'class' => 'AppBundle:ShiftExemption',
'choice_label' => 'name',
'multiple' => false,
'required' => false,
))
->add('submit', SubmitType::class, array(
'label' => 'Filtrer',
'attr' => array('class' => 'btn', 'value' => 'filtrer')
))
->getForm();

$res['form']->handleRequest($request);

if ($res['form']->isSubmitted() && $res['form']->isValid()) {
$res["shiftExemption"] = $res["form"]->get("shiftExemption")->getData();
}

return $res;
}

/**
* Lists all membershipShiftExemption entities.
*
* @Route("/", name="admin_membershipshiftexemption_index", methods={"GET"})
* @Route("/", name="admin_membershipshiftexemption_index", methods={"GET","POST"})
* @Security("has_role('ROLE_USER_MANAGER')")
*/
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$filter = $this->filterFormFactory($request);
$findByFilter = array();
$sort = 'createdAt';
$order = 'DESC';

if ($filter["shiftExemption"]) {
$findByFilter["shiftExemption"] = $filter["shiftExemption"];
}

$page = $request->get('page', 1);
$limit = 50;
$em = $this->getDoctrine()->getManager();

$nb_exemptions = $em->getRepository('AppBundle:MembershipShiftExemption')->count([]);
if ($nb_exemptions == 0) {
$max_page = 1;
} else {
$max_page = intval(($nb_exemptions-1) / $limit) + 1;
}
$em = $this->getDoctrine()->getManager();

$membershipShiftExemptions = $em->getRepository('AppBundle:MembershipShiftExemption')
->findBy([], ['createdAt' => 'DESC'], $limit, ($page - 1) * $limit);
->findBy($findByFilter, array($sort => $order), $limit, ($page - 1) * $limit);

return $this->render('admin/membershipshiftexemption/index.html.twig', array(
'membershipShiftExemptions' => $membershipShiftExemptions,
'filter_form' => $filter['form']->createView(),
'current_page' => $page,
'max_page' => $max_page,
));
Expand Down
7 changes: 5 additions & 2 deletions src/AppBundle/Controller/PeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public function indexAction(Request $request, EntityManagerInterface $em): Respo
{
$filter = $this->filterFormFactory($request);
$periodsByDay = array();
$order = array('start' => 'ASC');

for($i=0;$i<7;$i++){
$findByFilter = array('dayOfWeek'=>$i);

Expand All @@ -128,9 +130,10 @@ public function indexAction(Request $request, EntityManagerInterface $em): Respo
}

$periodsByDay[$i] = $em->getRepository('AppBundle:Period')
->findBy($findByFilter,array('start'=>'ASC'));
->findBy($findByFilter, $order);
}
return $this->render('admin/period/index.html.twig',array(

return $this->render('admin/period/index.html.twig', array(
"periods_by_day" => $periodsByDay,
"filter_form" => $filter['form']->createView(),
"week_filter" => $filter['week'],
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Entity/MembershipShiftExemption.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MembershipShiftExemption
private $createdBy;

/**
* @ORM\ManyToOne(targetEntity="ShiftExemption")
* @ORM\ManyToOne(targetEntity="ShiftExemption", inversedBy="membershipShiftExemptions")
* @ORM\JoinColumn(name="shift_exemption_id", referencedColumnName="id")
*/
private $shiftExemption;
Expand Down
44 changes: 43 additions & 1 deletion src/AppBundle/Entity/ShiftExemption.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* ShiftExemption
*
* @ORM\Table(name="shift_exemption")
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="AppBundle\Repository\ShiftExemptionRepository")
*/
class ShiftExemption
Expand All @@ -28,15 +29,36 @@ class ShiftExemption
*/
private $name;

/**
* @ORM\OneToMany(targetEntity="MembershipShiftExemption", mappedBy="shiftExemption", cascade={"persist"})
*/
private $membershipShiftExemptions;

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

/**
* Define toString.
*
* @return string
*/
public function __toString() {
public function __toString()
{
return $this->name;
}

/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->createdAt = new \DateTime();
}

/**
* Get id.
*
Expand Down Expand Up @@ -70,4 +92,24 @@ public function getName()
{
return $this->name;
}

/**
* Get membershipShiftExemptions
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getMembershipShiftExemptions()
{
return $this->membershipShiftExemptions;
}

/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
}

0 comments on commit 9b90f75

Please sign in to comment.