Commit b0b9b2b1 by Damien Moulard

homepage presta map: add param to admin to select filters & display and filter…

homepage presta map: add param to admin to select filters & display and filter accordingly in presta map
parent 05e11820
...@@ -93,6 +93,11 @@ class RubriqueAdmin extends AbstractAdmin ...@@ -93,6 +93,11 @@ class RubriqueAdmin extends AbstractAdmin
'required' => false, 'required' => false,
'label_attr' => ['class' => 'checkbox-inline'], 'label_attr' => ['class' => 'checkbox-inline'],
]) ])
->add('isPrestaMapFilter', CheckboxType::class, [
'label' => 'Est un filtre de la carte des Points de vente ?',
'required' => false,
'label_attr' => ['class' => 'checkbox-inline'],
])
->end() ->end()
->with('Image', ['class' => 'col-md-6']) ->with('Image', ['class' => 'col-md-6'])
->add('media', MediaType::class, [ ->add('media', MediaType::class, [
......
...@@ -147,9 +147,21 @@ class PrestatairesController extends FrontController ...@@ -147,9 +147,21 @@ class PrestatairesController extends FrontController
return $this->redirectToRoute('index'); return $this->redirectToRoute('index');
} }
$rubriques = $this->em->getRepository(Rubrique::class)->findBy(['enabled' => true], ['name' => 'ASC']); $rubriques = $this->em->getRepository(Rubrique::class)->findBy(['enabled' => true], ['name' => 'ASC']);
$newPresta = $this->em->getRepository(Prestataire::class)->findNewPrestataires();
$res = array_merge([
[
'id' => 'new_prestataires',
'slug' => 'new_prestataires',
'name' => 'Nouveaux points de vente',
'media' => null,
'content' => '',
'prestataires' => $newPresta
]
], $rubriques);
return $this->render('@kohinos/presta/rubriques.html.twig', [ return $this->render('@kohinos/presta/rubriques.html.twig', [
'rubriques' => $rubriques, 'rubriques' => $res,
]); ]);
} }
......
...@@ -57,6 +57,11 @@ class Rubrique ...@@ -57,6 +57,11 @@ class Rubrique
*/ */
protected $media; protected $media;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": false})
*/
private $isPrestaMapFilter;
public function __construct() public function __construct()
{ {
$this->prestataires = new ArrayCollection(); $this->prestataires = new ArrayCollection();
...@@ -136,4 +141,16 @@ class Rubrique ...@@ -136,4 +141,16 @@ class Rubrique
{ {
return $this->getTitle() ? $this->getTitle() : 'Rubrique'; return $this->getTitle() ? $this->getTitle() : 'Rubrique';
} }
public function getIsPrestaMapFilter(): ?bool
{
return $this->isPrestaMapFilter;
}
public function setIsPrestaMapFilter(bool $isPrestaMapFilter): self
{
$this->isPrestaMapFilter = $isPrestaMapFilter;
return $this;
}
} }
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260408075326 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->addSql('ALTER TABLE rubrique ADD is_presta_map_filter TINYINT(1) DEFAULT \'0\' NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE rubrique DROP is_presta_map_filter');
}
}
...@@ -337,4 +337,26 @@ class PrestataireRepository extends ServiceEntityRepository ...@@ -337,4 +337,26 @@ class PrestataireRepository extends ServiceEntityRepository
return $return; return $return;
} }
/**
* For Prestataire front Rubriques page.
*
* @return Prestataire[] Returns an array of Prestataire objects
*/
public function findNewPrestataires()
{
$qb = $this->createQueryBuilder('p');
$qb = $this->addDefaultFilter($qb);
$from = date('Y-m-d H:i:s',strtotime("-2 months"));
return $qb
->andWhere('p.enabled = true')
->andWhere('p.createdAt > :from')
->setParameter('from', $from)
->orderBy('p.raison', 'ASC')
->getQuery()
->getResult()
;
}
} }
...@@ -114,6 +114,7 @@ class AppExtension extends AbstractExtension ...@@ -114,6 +114,7 @@ class AppExtension extends AbstractExtension
}), }),
new \Twig_SimpleFunction('showInformationModal', [$this, 'showInformationModal']), new \Twig_SimpleFunction('showInformationModal', [$this, 'showInformationModal']),
new \Twig_SimpleFunction('getInformationPopupData', [$this, 'getInformationPopupData']), new \Twig_SimpleFunction('getInformationPopupData', [$this, 'getInformationPopupData']),
new \Twig_SimpleFunction('getRubriqueFiltersForPrestaMap', [$this, 'getRubriqueFiltersForPrestaMap']),
]; ];
} }
...@@ -617,4 +618,12 @@ class AppExtension extends AbstractExtension ...@@ -617,4 +618,12 @@ class AppExtension extends AbstractExtension
{ {
return $this->em->getRepository(InformationPopup::class)->findOneBy(['enabled' => true]); return $this->em->getRepository(InformationPopup::class)->findOneBy(['enabled' => true]);
} }
/**
* If the information modale is shown, get its data
*/
public function getRubriqueFiltersForPrestaMap()
{
return $this->em->getRepository(Rubrique::class)->findBy(['enabled' => true, 'isPrestaMapFilter' => true], ['name' => 'ASC']);
}
} }
{% set id = id|default('mapid') %} {% set id = id|default('mapid') %}
{% set style = style|default('') %} {% set style = style|default('') %}
{% set title = title|default('Carte') %} {% set title = title|default('Carte') %}
{% set rubriquesFilter = getRubriqueFiltersForPrestaMap() %}
<div class='cartetitle mb-3'> <div class='cartetitle mb-3'>
<h4><i class="fa fa-map"></i> {{title}}</h4> <h4><i class="fa fa-map"></i> {{title}}</h4>
</div> </div>
<div id="{{id}}" style="{{style}}" class='my-3'></div> <div id="{{id}}" style="{{style}}" class='my-3'></div>
<div> <div>
<button class="btn btn-primary" id="map-filter-food-shops">Commerces alimentaires</button> {% for rubrique in rubriquesFilter %}
<button class="btn btn-primary" id="map-filter-markets">Marchés</button> <button class="btn btn-primary presta-map-filter" data-rubrique-slug="{{rubrique.slug}}">{{ rubrique.name }}</button>
{% endfor %}
</div> </div>
\ No newline at end of file
...@@ -18,13 +18,17 @@ ...@@ -18,13 +18,17 @@
{% if presta.geolocs|length > 0 %} {% if presta.geolocs|length > 0 %}
{% for geolocp in presta.geolocs %} {% for geolocp in presta.geolocs %}
{% if geolocp.enabled and geolocp.geoloc.lat != null and geolocp.geoloc.lon != null %} {% if geolocp.enabled and geolocp.geoloc.lat != null and geolocp.geoloc.lon != null %}
var prestaRubriquesCount = parseInt('{{ presta.rubriques|length }}'); // get presta rubriques
var prestaRubriqueSlug = prestaRubriquesCount > 0 ? '{{ presta.rubriques.first.slug }}' : ''; var prestaRubriquesSlug = [];
{% for rubrique in presta.rubriques %}
prestaRubriquesSlug.push('{{ rubrique.slug }}')
{% endfor %}
// add presta to map if there's no filter or if one of its rubriques match any active filter
if ( if (
mapFilters.length === 0 mapFilters.length === 0
|| mapFilters.length > 0 || mapFilters.length > 0
&& mapFilters.includes(prestaRubriqueSlug) && mapFilters.some(el => prestaRubriquesSlug.includes(el))
) { ) {
{% if presta.rubriques|length > 0 and presta.rubriques.first.media is not null %} {% if presta.rubriques|length > 0 and presta.rubriques.first.media is not null %}
var iconClassName = 'kohinos-map-icon'; var iconClassName = 'kohinos-map-icon';
...@@ -67,38 +71,27 @@ ...@@ -67,38 +71,27 @@
drawMap(); drawMap();
if ($('#map-filter-food-shops').length) { // Listeners for map filters buttons
$('#map-filter-food-shops').click(() => { $('.presta-map-filter').each(function() {
let index = mapFilters.indexOf('commerce-alimentaire'); $(this).click(() => {
if (index === -1) { let slug = $(this).data('rubriqueSlug');
mapFilters.push('commerce-alimentaire');
$('#map-filter-food-shops').removeClass('btn-primary').addClass('btn-success');
} else {
mapFilters.splice(index, 1);
$('#map-filter-food-shops').addClass('btn-primary').removeClass('btn-success');
}
// Redraw map
mymap.remove();
drawMap();
});
}
if ($('#map-filter-markets').length) { let activeFilterIndex = mapFilters.indexOf(slug);
$('#map-filter-markets').click(() => { if (activeFilterIndex === -1) {
let index = mapFilters.indexOf('marches-amap'); // add rubrique slug to fiters array if it doesn't exist...
if (index === -1) { mapFilters.push(slug);
mapFilters.push('marches-amap'); $(this).removeClass('btn-primary').addClass('btn-success');
$('#map-filter-markets').removeClass('btn-primary').addClass('btn-success');
} else { } else {
mapFilters.splice(index, 1); // ... else, add it
$('#map-filter-markets').addClass('btn-primary').removeClass('btn-success'); mapFilters.splice(activeFilterIndex, 1);
$(this).addClass('btn-primary').removeClass('btn-success');
} }
// Redraw map // Redraw map
mymap.remove(); mymap.remove();
drawMap(); drawMap();
}); });
} });
})
});
</script> </script>
...@@ -13,7 +13,12 @@ ...@@ -13,7 +13,12 @@
{% if rubrique.media is not null %} {% if rubrique.media is not null %}
{% thumbnail rubrique.media, 'small' %} {% thumbnail rubrique.media, 'small' %}
{% endif %} {% endif %}
<a class='rubrique' href='{{ path('show_rubrique', {'slug': rubrique.slug}) }}'>{{rubrique.name}}</a> {% if rubrique.id == 'new_prestataires' %}
{# TODO: change color to black OR create details page for new pdv #}
<span class='rubrique'>{{rubrique.name}}</span>
{% else %}
<a class='rubrique' href='{{ path('show_rubrique', {'slug': rubrique.slug}) }}'>{{rubrique.name}}</a>
{% endif %}
</h5> </h5>
{% if rubrique.content|length > 0 %} {% if rubrique.content|length > 0 %}
<div class="card-body"> <div class="card-body">
......
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