Commit 686c2aba by Julien Jorry

Front : prestataire liste : order by groupe or name + show presta by groupe

parent 9c8f0142
......@@ -2,6 +2,7 @@
namespace App\Controller;
use App\Entity\Groupe;
use App\Entity\Prestataire;
use App\Entity\Rubrique;
use Doctrine\ORM\EntityManagerInterface;
......@@ -39,13 +40,22 @@ class PrestatairesController extends FrontController
}
/**
* @Route("/prestataires/liste", name="liste_prestataire")
* @Route("/prestataires/liste/{order}", name="liste_prestataire", defaults={"order": "raison"})
*/
public function listePrestaAction()
public function listePrestaAction($order = 'raison')
{
if (!$this->isFrontActivated()) {
return $this->redirectToRoute('index');
}
if ($order == 'groupelocal') {
$prestas = $this->em->getRepository(Prestataire::class)->findDefault('prestataire', 'groupelocal');
return $this->render('@kohinos/presta/liste_prestataires_bygroupelocal.html.twig', [
'prestas' => $prestas,
'type' => 'Prestataires',
]);
}
$prestas = $this->em->getRepository(Prestataire::class)->findDefault('prestataire');
return $this->render('@kohinos/presta/liste_prestataires.html.twig', [
......@@ -55,6 +65,23 @@ class PrestatairesController extends FrontController
}
/**
* @Route("/prestataires/groupe/{slug}/liste", name="liste_presta_by_groupe")
*/
public function listePrestaByGroupeAction(Groupe $groupe)
{
if (!$this->isFrontActivated()) {
return $this->redirectToRoute('index');
}
$prestas = $this->em->getRepository(Prestataire::class)->findByGroupe($groupe);
return $this->render('@kohinos/presta/liste_prestataires.html.twig', [
'prestas' => $prestas,
'type' => 'Prestataires du groupe local '.$groupe->getName(),
]);
}
/**
* @Route("/partenaires/liste", name="liste_partenaire")
*/
public function listePartnerAction()
......
......@@ -31,7 +31,13 @@ class PrestataireRepository extends ServiceEntityRepository
{
$qb = $this->createQueryBuilder('p');
$qb = $this->addDefaultFilter($qb);
if ($orderBy == 'groupelocal' && !empty($direction) && ('ASC' === $direction || 'DESC' === $direction)) {
$qb->leftJoin('p.groupe', 'g')
->orderBy('g.name', $direction)
->addOrderBy('p.raison', 'ASC');
} else if (!empty($orderBy) && !empty($direction) && ('ASC' === $direction || 'DESC' === $direction)) {
$qb->orderBy('p.' . $orderBy, $direction);
}
if (null != $limit) {
$qb->limit($limit);
}
......@@ -198,6 +204,28 @@ class PrestataireRepository extends ServiceEntityRepository
}
/**
* For Prestataire front search.
*
* @return Prestataire[] Returns an array of Prestataire objects
*/
public function findByGroupe(Groupe $groupe)
{
$qb = $this->createQueryBuilder('p');
$qb = $this->addDefaultFilter($qb);
return $qb
->andWhere('p.groupe = :groupe')
->setParameter('groupe', $groupe)
->orderBy('p.raison', 'ASC')
->leftJoin('p.typeprestataire', 't')
->andWhere('t.name = :nametype OR t.name IS NULL')
->setParameter('nametype', 'prestataire')
->getQuery()
->getResult()
;
}
/**
* For Prestataire Admin search.
*
* @return Prestataire[] Returns an array of Prestataire objects
......
......@@ -3,7 +3,12 @@
{% block content %}
<div class='container prestalist mt-2'>
{% include '@kohinos/block/breadcrumb.html.twig' with {'label' : type} %}
<h1 class='pagetitle'>{{type}} :</h1>
<div class="d-flex justify-content-center">
<div class="btn-group text-center mb-2" role="group" aria-label="Basic example">
<a href='#' type="button" class="btn btn-primary">Par nom</a>
<a href='{{ path('liste_prestataire', {'order': 'groupelocal'}) }}' type="button" class="btn btn-secondary">Par groupe local</a>
</div>
</div>
<div class="row">
{% for presta in prestas %}
<div class="col-12 col-md-6 mb-2">
......
{% extends '@kohinos/common/layout.html.twig' %}
{% block content %}
<div class='container prestalist mt-2'>
{% include '@kohinos/block/breadcrumb.html.twig' with {'label' : type} %}
<div class="d-flex justify-content-center">
<div class="btn-group text-center mb-2" role="group" aria-label="Basic example">
<a href='#' type="button" class="btn btn-secondary">Par nom</a>
<a href='{{ path('liste_prestataire', {'order': 'groupelocal'}) }}' type="button" class="btn btn-primary">Par groupe local</a>
</div>
</div>
{% set groupe = '' %}
{% set groupePrestaHtml = [] %}
{% for presta in prestas %}
{% if groupe != presta.groupe.name %}
{% if loop.index != 1 %}
</div>
</div>
{% endif %}
{% set groupe = presta.groupe.name %}
<h5 class="w-100 card-header mb-3 text-primary border border-primary" style='cursor:pointer;'>
<a class='d-inline' href='{{ path('liste_presta_by_groupe', {'slug': presta.groupe.slug}) }}'>GROUPE LOCAL : {{ presta.groupe.name|upper }}</a>
<a href='#' class='nounderline d-inline float-right' tyle='cursor:pointer;' data-toggle="collapse" data-target="#collapsepresta{{ presta.groupe.id }}" aria-expanded="false" aria-controls="collapsepresta{{ presta.groupe.id }}"><i class="fa fa-caret-down ml-2" aria-hidden="true"></i></a>
</h5>
<div id="collapsepresta{{ presta.groupe.id }}" class='collapse show'>
{% if loop.index != 1 %}
<div class='row'>
{% endif %}
{% endif %}
{% if loop.index == 1 %}
<div class="row">
{% endif %}
<div class="col-12 col-md-6 mb-2">
{% include '@kohinos/presta/onepresta.html.twig' %}
</div>
{% if loop.index%2 == 0 %}
</div>
<div class="row">
{% endif %}
{% endfor %}
</div>
</div>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment