<?php
/**
* Created by PhpStorm.
* User: ubik
* Date: 03/11/19
* Time: 22:06
*/
namespace App\Controller;
use App\Entity\Plongeur;
use App\Entity\Licence;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Filesystem\Filesystem;
class HomeController extends ToolsController
{
/**
* @return Response
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function index(): Response
{
$repoLicence = $this->getDoctrine()->getRepository(Licence::class);
$repoPlongeur = $this->getDoctrine()->getRepository(Plongeur::class);
$nbassuresSaison = $repoLicence->nbInscrit();
$nbvpdive = $repoPlongeur->nbInscrit();
return $this->render('pages/home.html.twig', [
'nbassuresSaison' => $nbassuresSaison,
'nbassuresTotal' => $nbvpdive,
]);
}
/**
* @return Response
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function sites(): Response
{
$finder = new Finder();
$sites = [];
$sitesFolder = $finder->in(__DIR__.'/../../public/img/sites/*');
if(count($sitesFolder)>0) {
foreach ($sitesFolder as $s) {
$folder = substr($s->getPath(), strrpos($s->getPath(), '/')+1);
if(!in_array($folder, $sites)) {
$sites[$folder]=[];
}
}
foreach ($sitesFolder as $s) {
$folder = substr($s->getPath(), strrpos($s->getPath(), '/')+1);
array_push($sites[$folder],$s->getFilename());
}
}
return $this->render('pages/sites.html.twig', [
'sites' => $sites,
]);
}
/**
* @return Response
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function livres(): Response
{
$livres = [];
$finder = new Finder();
// $livres = $finder->files()->name('*')->in(__DIR__.'/../../public/img/livres/*.jpg');
$livresFolder = $finder->files()->name('*.jpg')->in(__DIR__.'/../../public/img/livres/');
foreach ($livresFolder as $l) {
array_push($livres,$l->getFilename());
}
return $this->render('pages/livres.html.twig', [
'livres' => $livres,
]);
}
}