src/Controller/HomeController.php line 26

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: ubik
  5.  * Date: 03/11/19
  6.  * Time: 22:06
  7.  */
  8. namespace App\Controller;
  9. use App\Entity\Plongeur;
  10. use App\Entity\Licence;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Finder\Finder;
  14. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  15. use Symfony\Component\Filesystem\Filesystem;
  16. class HomeController extends ToolsController
  17. {
  18.     /**
  19.      * @return Response
  20.      * @throws \Twig\Error\LoaderError
  21.      * @throws \Twig\Error\RuntimeError
  22.      * @throws \Twig\Error\SyntaxError
  23.      */
  24.     public function index(): Response
  25.     {
  26.         $repoLicence $this->getDoctrine()->getRepository(Licence::class);
  27.         $repoPlongeur $this->getDoctrine()->getRepository(Plongeur::class);
  28.         $nbassuresSaison $repoLicence->nbInscrit();
  29.         $nbvpdive        $repoPlongeur->nbInscrit();
  30.         return $this->render('pages/home.html.twig', [
  31.                 'nbassuresSaison' => $nbassuresSaison,
  32.                 'nbassuresTotal' => $nbvpdive,
  33.             ]);
  34.     }
  35.     /**
  36.      * @return Response
  37.      * @throws \Twig\Error\LoaderError
  38.      * @throws \Twig\Error\RuntimeError
  39.      * @throws \Twig\Error\SyntaxError
  40.      */
  41.     public function sites(): Response
  42.     {
  43.         $finder = new Finder();
  44.         $sites  = [];
  45.         $sitesFolder  $finder->in(__DIR__.'/../../public/img/sites/*');
  46.         if(count($sitesFolder)>0) {
  47.             foreach ($sitesFolder as $s) {
  48.                 $folder substr($s->getPath(), strrpos($s->getPath(), '/')+1);
  49.                 if(!in_array($folder$sites)) {
  50.                     $sites[$folder]=[];
  51.                 }
  52.             }
  53.             foreach ($sitesFolder as $s) {
  54.                 $folder substr($s->getPath(), strrpos($s->getPath(), '/')+1);
  55.                 array_push($sites[$folder],$s->getFilename());
  56.             }
  57.         }
  58.         return $this->render('pages/sites.html.twig', [
  59.             'sites' => $sites,
  60.         ]);
  61.     }
  62.     /**
  63.      * @return Response
  64.      * @throws \Twig\Error\LoaderError
  65.      * @throws \Twig\Error\RuntimeError
  66.      * @throws \Twig\Error\SyntaxError
  67.      */
  68.     public function livres(): Response
  69.     {
  70.         $livres = [];
  71.         $finder = new Finder();
  72. //        $livres = $finder->files()->name('*')->in(__DIR__.'/../../public/img/livres/*.jpg');
  73.         $livresFolder  $finder->files()->name('*.jpg')->in(__DIR__.'/../../public/img/livres/');
  74.         foreach ($livresFolder as $l) {
  75.         array_push($livres,$l->getFilename());
  76.         }
  77.         return $this->render('pages/livres.html.twig', [
  78.             'livres' => $livres,
  79.         ]);
  80.     }
  81. }