src/Twig/ItemsInsertionExtension.php line 89

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Copyright (C) Office National de Publication et de Communication - All Rights Reserved
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited by law
  7.  * This file is proprietary and confidential
  8.  *
  9.  * Renvoi le nom final d'un item : libelleSpecifique sinon libelleMEP sinon libelle
  10.  */
  11. namespace App\Twig;
  12. use Twig\TwigFilter;
  13. use App\Entity\Items;
  14. use App\Entity\ItemsInsertion;
  15. use Twig\Extension\AbstractExtension;
  16. use Doctrine\Persistence\ManagerRegistry;
  17. final class ItemsInsertionExtension extends AbstractExtension
  18. {
  19.     private $doctrine;
  20.     public function __construct(ManagerRegistry $doctrine)
  21.     {
  22.         $this->doctrine $doctrine;
  23.     }
  24.     public function getFilters(): array
  25.     {
  26.         return [
  27.             new TwigFilter('itemLibelle', [$this'itemLibelle']),
  28.             new TwigFilter('itemsLibelle', [$this'itemsLibelle']),
  29.             new TwigFilter('itemOptions', [$this'itemOptions']),
  30.             new TwigFilter('itemIdLibelle', [$this'itemIdLibelle']),
  31.         ];
  32.     }
  33.     public function itemLibelle(ItemsInsertion $ii): ?string
  34.     {
  35.         $libelle $ii->getLibelleSpecifique();
  36.         if (empty($libelle) ) {
  37.             $libelle $ii->getLibelleMEP();
  38.         }
  39.         if (empty($libelle) ) {
  40.             $libelle $ii->getLibelle();
  41.         }
  42.         if (strpos($libelle'VIDE') !== false)
  43.             return "";
  44.         return trim($libelle);
  45.     }
  46.     public function itemsLibelle(Items $ii): ?string
  47.     {
  48.         $libelle $ii->getLibelleWeb() ?? $ii->getLibelleMEP();
  49.         if (empty($libelle) ) {
  50.             $libelle $ii->getLibelle();
  51.         }
  52.         if (strpos($libelle'VIDE') !== false)
  53.             return "";
  54.         return trim($libelle);
  55.     }
  56.     public function itemOptions(ItemsInsertion $ii): ?string
  57.     {
  58.         $libelle $ii->getOptionsSpecifique();
  59.         if (empty($libelle) )
  60.             $libelle $ii->getOptions();
  61.         return trim($libelle);
  62.     }
  63.     public function itemIdLibelle(string $id): ?string
  64.     {
  65.         if ($id == "-3") {
  66.             return "Moins de 3 ans";
  67.         }
  68.         /*
  69.         $dpt = $this->doctrine->getRepository(Items::class)->findOneById($id);
  70.         return $dpt ? $dpt->getLibelle() : "";
  71.         */
  72.         $dpt $this->doctrine->getRepository(Items::class)->findOneById($id);
  73.         // return $dpt ? $dpt->getLibelle() : "";
  74.         if ($dpt === null) {
  75.             return "";
  76.         }
  77.         $libelle $dpt->getLibelleMEP() ?? $dpt->getLibelle() ?? "";
  78.         $option $dpt->getOptions() ?? "";
  79.         return trim($libelle " " $option);
  80.     }
  81. }