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
'required' => false,
'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()
->with('Image', ['class' => 'col-md-6'])
->add('media', MediaType::class, [
......
......@@ -147,9 +147,21 @@ class PrestatairesController extends FrontController
return $this->redirectToRoute('index');
}
$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', [
'rubriques' => $rubriques,
'rubriques' => $res,
]);
}
......
......@@ -57,6 +57,11 @@ class Rubrique
*/
protected $media;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": false})
*/
private $isPrestaMapFilter;
public function __construct()
{
$this->prestataires = new ArrayCollection();
......@@ -136,4 +141,16 @@ class 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
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
}),
new \Twig_SimpleFunction('showInformationModal', [$this, 'showInformationModal']),
new \Twig_SimpleFunction('getInformationPopupData', [$this, 'getInformationPopupData']),
new \Twig_SimpleFunction('getRubriqueFiltersForPrestaMap', [$this, 'getRubriqueFiltersForPrestaMap']),
];
}
......@@ -617,4 +618,12 @@ class AppExtension extends AbstractExtension
{
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 style = style|default('') %}
{% set title = title|default('Carte') %}
{% set rubriquesFilter = getRubriqueFiltersForPrestaMap() %}
<div class='cartetitle mb-3'>
<h4><i class="fa fa-map"></i> {{title}}</h4>
</div>
<div id="{{id}}" style="{{style}}" class='my-3'></div>
<div>
<button class="btn btn-primary" id="map-filter-food-shops">Commerces alimentaires</button>
<button class="btn btn-primary" id="map-filter-markets">Marchés</button>
{% for rubrique in rubriquesFilter %}
<button class="btn btn-primary presta-map-filter" data-rubrique-slug="{{rubrique.slug}}">{{ rubrique.name }}</button>
{% endfor %}
</div>
\ No newline at end of file
......@@ -18,13 +18,17 @@
{% if presta.geolocs|length > 0 %}
{% for geolocp in presta.geolocs %}
{% if geolocp.enabled and geolocp.geoloc.lat != null and geolocp.geoloc.lon != null %}
var prestaRubriquesCount = parseInt('{{ presta.rubriques|length }}');
var prestaRubriqueSlug = prestaRubriquesCount > 0 ? '{{ presta.rubriques.first.slug }}' : '';
// get presta rubriques
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 (
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 %}
var iconClassName = 'kohinos-map-icon';
......@@ -67,38 +71,27 @@
drawMap();
if ($('#map-filter-food-shops').length) {
$('#map-filter-food-shops').click(() => {
let index = mapFilters.indexOf('commerce-alimentaire');
if (index === -1) {
mapFilters.push('commerce-alimentaire');
$('#map-filter-food-shops').removeClass('btn-primary').addClass('btn-success');
// Listeners for map filters buttons
$('.presta-map-filter').each(function() {
$(this).click(() => {
let slug = $(this).data('rubriqueSlug');
let activeFilterIndex = mapFilters.indexOf(slug);
if (activeFilterIndex === -1) {
// add rubrique slug to fiters array if it doesn't exist...
mapFilters.push(slug);
$(this).removeClass('btn-primary').addClass('btn-success');
} else {
mapFilters.splice(index, 1);
$('#map-filter-food-shops').addClass('btn-primary').removeClass('btn-success');
// ... else, add it
mapFilters.splice(activeFilterIndex, 1);
$(this).addClass('btn-primary').removeClass('btn-success');
}
// Redraw map
mymap.remove();
drawMap();
});
}
if ($('#map-filter-markets').length) {
$('#map-filter-markets').click(() => {
let index = mapFilters.indexOf('marches-amap');
if (index === -1) {
mapFilters.push('marches-amap');
$('#map-filter-markets').removeClass('btn-primary').addClass('btn-success');
} else {
mapFilters.splice(index, 1);
$('#map-filter-markets').addClass('btn-primary').removeClass('btn-success');
}
});
// Redraw map
mymap.remove();
drawMap();
});
}
})
</script>
......@@ -13,7 +13,12 @@
{% if rubrique.media is not null %}
{% thumbnail rubrique.media, 'small' %}
{% endif %}
{% 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>
{% if rubrique.content|length > 0 %}
<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