src/Twig/AppExtension.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Twig;
  3. use App\Entity\ActualityCategory;
  4. use App\Entity\DefinitionPage;
  5. use App\Entity\Manuel;
  6. use App\Entity\ManuelPage;
  7. use App\Entity\Page;
  8. use App\Entity\PublicationPage;
  9. use App\Entity\Theme;
  10. use App\Entity\ThemePublication;
  11. use App\Entity\ThesePage;
  12. use App\Repository\DefinitionPageRepository;
  13. use App\Repository\ManuelPageRepository;
  14. use App\Repository\PageRepository;
  15. use App\Repository\PublicationPageRepository;
  16. use App\Repository\ThemePublicationRepository;
  17. use App\Repository\ThemeRepository;
  18. use App\Repository\ThesePageRepository;
  19. use Cofondateur\SocleTechniqueBundle\Twig\AppExtension as BaseAppExtension;
  20. use Twig\TwigFunction;
  21. use IntlDateFormatter;
  22. class AppExtension extends BaseAppExtension
  23. {
  24.     public function getFilters(): array
  25.     {
  26.         $result parent::getFilters();
  27.         return $result;
  28.     }
  29.     public function getFunctions(): array
  30.     {
  31.         $result parent::getFunctions();
  32.         $result[] = new TwigFunction('getThemes', array($this'getThemes'));
  33.         $result[] = new TwigFunction('getThemePublication', array($this'getThemePublication'));
  34.         $result[] = new TwigFunction('getPagesPublication', array($this'getPagesPublication'));
  35.         $result[] = new TwigFunction('getManuels', array($this'getManuels'));
  36.         $result[] = new TwigFunction('getCategoriesActu', array($this'getCategoriesActu'));
  37.         $result[] = new TwigFunction('formatDateMoisAnnee', array($this'formatDateMoisAnnee'));
  38.         $result[] = new TwigFunction('getFirstPageOfTheme', array($this'getFirstPageOfTheme'));
  39.         $result[] = new TwigFunction('getPublicationPage', array($this'getPublicationPage'));
  40.         $result[] = new TwigFunction('getThesePage', array($this'getThesePage'));
  41.         $result[] = new TwigFunction('getManuelPage', array($this'getManuelPage'));
  42.         $result[] = new TwigFunction('getDefinitionPage', array($this'getDefinitionPage'));
  43.         return $result;
  44.     }
  45.     public function getThemes()
  46.     {
  47.         /** @var ThemeRepository $repo */
  48.         $repo $this->em->getRepository(Theme::class);
  49.         return $repo->findBy([], ['position' => 'ASC']);
  50.     }
  51.     public function getThemePublication()
  52.     {
  53.         /** @var ThemePublicationRepository $repo */
  54.         $repo $this->em->getRepository(ThemePublication::class);
  55.         return $repo->findUnique();
  56.     }
  57.     public function getPublicationPage()
  58.     {
  59.         /** @var PublicationPageRepository $repo */
  60.         $repo $this->em->getRepository(PublicationPage::class);
  61.         return $repo->findUnique();
  62.     }
  63.     public function getThesePage()
  64.     {
  65.         /** @var ThesePageRepository $repo */
  66.         $repo $this->em->getRepository(ThesePage::class);
  67.         return $repo->findUnique();
  68.     }
  69.     public function getManuelPage()
  70.     {
  71.         /** @var ManuelPageRepository $repo */
  72.         $repo $this->em->getRepository(ManuelPage::class);
  73.         return $repo->findUnique();
  74.     }
  75.     public function getDefinitionPage()
  76.     {
  77.         /** @var DefinitionPageRepository $repo */
  78.         $repo $this->em->getRepository(DefinitionPage::class);
  79.         return $repo->findUnique();
  80.     }
  81.     public function getManuels()
  82.     {
  83.         /** @var ThemeRepository $repo */
  84.         $repo $this->em->getRepository(Manuel::class);
  85.         return $repo->findBy(['display' => true], ['id' => 'DESC']);
  86.     }
  87.     public function getPagesPublication()
  88.     {
  89.         /** @var PageRepository $repo */
  90.         $repo $this->em->getRepository(Page::class);
  91.         return $repo->findBy(['activate' => true'themePublication' => true], ['position' => 'ASC']);
  92.     }
  93.     public function getCategoriesActu()
  94.     {
  95.         /** @var ThemeRepository $repo */
  96.         $repo $this->em->getRepository(ActualityCategory::class);
  97.         return $repo->findAll();
  98.     }
  99.     public function formatDateMoisAnnee(\DateTimeInterface $date)
  100.     {
  101.         $formatter = new IntlDateFormatter('fr_FR'IntlDateFormatter::LONGIntlDateFormatter::NONEnullnull'MMMM yyyy');
  102.         return ucfirst($formatter->format($date));
  103.     }
  104.     // function to get the page with the lowest id of a theme in parameter
  105.     public function getFirstPageOfTheme(Theme $theme)
  106.     {
  107.         $repo $this->em->getRepository(Page::class);
  108.         return $repo->findOneBy(['theme' => $theme'activate' => true], ['id' => 'ASC']);
  109.     }
  110. }