Commit ae24d0f7 by Damien Moulard

add new prestataires rubrique management

parent 11f4efdc
......@@ -201,6 +201,10 @@ Quand CCAS_MODE = 1, pour que les reconversions CCAS soient effectuées et les e
57 1 1 * * kohinos php /home/kohinos/kohinos/bin/console kohinos:ssa:export-ccas-transactions
27 2 10 * * kohinos rm -f /home/kohinos/kohinos/ccastransactions/*
Pour activer la gestion automatique de la rubrique des nouveaux prestataires :
0 0 1 * * kohinos php /home/kohinos/kohinos/bin/console kohinos:ssa:manage-new-prestas-rubrique
## Lancer le Kohinos en local
Installer le client symfony
......
......@@ -439,6 +439,9 @@ form[name="formEncaissement"] label {
word-break: break-all;
}
#new-prestataires-rubrique-title {
color: #222;
.presta-map-filter-container {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 5px;
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -6,7 +6,7 @@
"/build/app.3644f7b2.js"
],
"css": [
"/build/app.b5da936b.css"
"/build/app.13f8bbf1.css"
]
},
"admin": {
......
{
"build/app.css": "/build/app.b5da936b.css",
"build/app.css": "/build/app.13f8bbf1.css",
"build/app.js": "/build/app.3644f7b2.js",
"build/admin.css": "/build/admin.4de55830.css",
"build/admin.js": "/build/admin.63735322.js",
......
......@@ -98,6 +98,12 @@ class RubriqueAdmin extends AbstractAdmin
'required' => false,
'label_attr' => ['class' => 'checkbox-inline'],
])
->add('isRubriqueForNewPresta', CheckboxType::class, [
'label' => 'Est la rubrique des nouveaux points de vente ?',
'help' => 'Les nouveaux points de vente y sont automatiquement ajoutés une fois par jour. Il ne peut y avoir qu\'une seule rubrique pour les nouveaux points de vente.',
'required' => false,
'label_attr' => ['class' => 'checkbox-inline'],
])
->end()
->with('Image', ['class' => 'col-md-6'])
->add('media', MediaType::class, [
......
<?php
declare(strict_types=1);
namespace App\Command;
use App\Entity\Rubrique;
use App\Entity\Prestataire;
use App\Utils\CustomEntityManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* This command is used to add or delete prestataire to/from the nes prestataires rubrique.
* This way, this rubrique always only contains the new prestataires (created in the last 2 months).
*/
class ManageNewPrestaRubriqueCommand extends Command
{
protected static $defaultName = 'kohinos:ssa:manage-new-prestas-rubrique';
protected $em;
protected $io;
public function __construct(CustomEntityManager $em) {
$this->em = $em;
parent::__construct();
}
protected function configure()
{
$this
->setDescription('SSA : ajouter ou supprimer les prestaires de la rubrique des nouveaux prestataires')
;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io = new SymfonyStyle($input, $output);
$this->io->title('START');
$rubrique = $this->em->getRepository(Rubrique::class)->findOneBy(['isRubriqueForNewPresta' => true, 'enabled' => true]);
if (null === $rubrique) {
return 0;
}
$newPrestas = $this->em->getRepository(Prestataire::class)->findNewPrestataires();
foreach ($newPrestas as $p) {
// add if doesn't exist
$p->addRubrique($rubrique);
$this->em->persist($p);
}
// get all other prestas
$otherPrestas = $this->em->getRepository(Prestataire::class)->findbyListExclude($newPrestas);
foreach ($otherPrestas as $p) {
// remove if exists
$p->removeRubrique($rubrique);
$this->em->persist($p);
}
$this->em->flush();
$this->em->clear();
$this->io->success('End');
$memoryUsage = memory_get_usage(true) / 1024 / 1024;
$this->io->text("Batch finished with memory: ${memoryUsage}M");
return 0;
}
}
......@@ -147,22 +147,9 @@ class PrestatairesController extends FrontController
if (!$this->isFrontActivated()) {
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' => $this->em->getRepository(Media::class)->findOneBy(['name' => 'wosmpl-marker-icon21-divers.png']),
'content' => '',
'prestataires' => $newPresta
]
], $rubriques);
return $this->render('@kohinos/presta/rubriques.html.twig', [
'rubriques' => $res,
'rubriques' => $this->em->getRepository(Rubrique::class)->findBy(['enabled' => true], ['isRubriqueForNewPresta' => 'DESC', 'name' => 'ASC']),
]);
}
......
......@@ -62,6 +62,14 @@ class Rubrique
*/
private $isPrestaMapFilter;
/**
* One Rubrique is dedicated to new prestataires.
* Prestataires will be automatically added to or deleted from this Rubrique to it containse only the most recently added Prestataires.
*
* @ORM\Column(type="boolean", nullable=false, options={"default": false})
*/
private $isRubriqueForNewPresta;
public function __construct()
{
$this->prestataires = new ArrayCollection();
......@@ -153,4 +161,16 @@ class Rubrique
return $this;
}
public function getIsRubriqueForNewPresta(): ?bool
{
return $this->isRubriqueForNewPresta;
}
public function setIsRubriqueForNewPresta(bool $isRubriqueForNewPresta): self
{
$this->isRubriqueForNewPresta = $isRubriqueForNewPresta;
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 Version20260513075023 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_rubrique_for_new_presta 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_rubrique_for_new_presta');
}
}
......@@ -339,8 +339,29 @@ class PrestataireRepository extends ServiceEntityRepository
}
/**
* For Prestataire front Rubriques page.
*
* Find by excluding prestataires in parameter list
* @return Prestataire[] Returns an array of Prestataire objects
*/
public function findbyListExclude(Array $prestas)
{
$excludeIds = [];
foreach ($prestas as $p) {
$excludeIds[] = strval($p->getId());
}
$qb = $this->createQueryBuilder('p');
$qb = $this->addDefaultFilter($qb);
return $qb
->andWhere('p.id NOT IN (:ids)')
->setParameter('ids', $excludeIds)
->orderBy('p.raison', 'ASC')
->getQuery()
->getResult()
;
}
/**
* @return Prestataire[] Returns an array of Prestataire objects
*/
public function findNewPrestataires()
......@@ -351,7 +372,6 @@ class PrestataireRepository extends ServiceEntityRepository
$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')
......@@ -359,26 +379,4 @@ class PrestataireRepository extends ServiceEntityRepository
->getResult()
;
}
// /**
// * For Prestataire front Rubriques page.
// *
// * @return Prestataire[] Returns an array of Prestataire objects
// */
// public function f indNewPrestataires()
// {
// $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()
// ;
// }
}
<?php
namespace App\Repository;
use App\Entity\Rubrique;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method RubriqueItem|null find($id, $lockMode = null, $lockVersion = null)
* @method RubriqueItem|null findOneBy(array $criteria, array $orderBy = null)
* @method RubriqueItem[] findAll()
* @method RubriqueItem[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class RubriqueRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Rubrique::class);
}
}
......@@ -7,8 +7,8 @@
<h4><i class="fa fa-map"></i> {{title}}</h4>
</div>
<div id="{{id}}" style="{{style}}" class='my-3'></div>
<div>
{% for rubrique in rubriquesFilter %}
<button class="btn btn-primary presta-map-filter" data-rubrique-slug="{{rubrique.slug}}">{{ rubrique.name }}</button>
{% endfor %}
<div class="presta-map-filter-container">
{% 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,6 +18,7 @@
{% if presta.geolocs|length > 0 %}
{% for geolocp in presta.geolocs %}
{% if geolocp.enabled and geolocp.geoloc.lat != null and geolocp.geoloc.lon != null %}
// get presta rubriques
var prestaRubriquesSlug = [];
{% for rubrique in presta.rubriques %}
......@@ -30,16 +31,24 @@
|| mapFilters.length > 0
&& mapFilters.some(el => prestaRubriquesSlug.includes(el))
) {
{% if presta.rubriques|length > 0 and presta.rubriques.first.media is not null %}
var iconClassName = 'kohinos-map-icon';
{% if date(presta.getCreatedAt()) > date('-2months') %}
iconClassName = 'kohinos-map-icon new-presta-icon';
{% endif %}
// On récupère la rubrique des nouveaux prestataires en priorité, sinon la première rubrique de la liste
{% set media = null %}
{% if presta.rubriques|length > 0 %}
{% for rubrique in presta.rubriques %}
{% if rubrique.isRubriqueForNewPresta %}
{% set media = rubrique.media %}
{% elseif media is null and rubrique.media is not null %}
{% set media = rubrique.media %}
{% endif %}
{% endfor %}
{% endif %}
{% if media is not null %}
var icon = L.icon({
iconSize: [50, 50],
iconAnchor: [25,50],
className: iconClassName,
iconUrl : '{% path presta.rubriques.first.media, "preview" %}'
className: 'kohinos-map-icon',
iconUrl : '{% path media, "preview" %}'
});
var marker_{{count}} = L.marker([{{geolocp.geoloc.lat}}, {{geolocp.geoloc.lon}}], {icon: icon}).addTo(mymap);
{% else %}
......
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