M1.1 : nettoyer le code

This commit is contained in:
Erwann PHILIPPE 2026-01-16 16:07:48 +01:00
parent 30010bce1f
commit f9c0ed3a63
7 changed files with 64 additions and 60 deletions

View file

@ -19,23 +19,23 @@ class AccueilController extends AbstractController{
private $repository;
/**
*
*
* @param FormationRepository $repository
*/
public function __construct(FormationRepository $repository) {
$this->repository = $repository;
}
}
#[Route('/', name: 'accueil')]
public function index(): Response{
$formations = $this->repository->findAllLasted(2);
return $this->render("pages/accueil.html.twig", [
'formations' => $formations
]);
]);
}
#[Route('/cgu', name: 'cgu')]
public function cgu(): Response{
return $this->render("pages/cgu.html.twig");
return $this->render("pages/cgu.html.twig");
}
}

View file

@ -16,18 +16,19 @@ use Symfony\Component\Routing\Annotation\Route;
class FormationsController extends AbstractController {
/**
*
*
* @var FormationRepository
*/
private $formationRepository;
/**
*
*
* @var CategorieRepository
*/
private $categorieRepository;
private $formationPage = "/pages/formations.html.twig";
function __construct(FormationRepository $formationRepository, CategorieRepository $categorieRepository) {
public function __construct(FormationRepository $formationRepository, CategorieRepository $categorieRepository) {
$this->formationRepository = $formationRepository;
$this->categorieRepository= $categorieRepository;
}
@ -36,7 +37,7 @@ class FormationsController extends AbstractController {
public function index(): Response{
$formations = $this->formationRepository->findAll();
$categories = $this->categorieRepository->findAll();
return $this->render("pages/formations.html.twig", [
return $this->render($this->formationPage, [
'formations' => $formations,
'categories' => $categories
]);
@ -46,31 +47,31 @@ class FormationsController extends AbstractController {
public function sort($champ, $ordre, $table=""): Response{
$formations = $this->formationRepository->findAllOrderBy($champ, $ordre, $table);
$categories = $this->categorieRepository->findAll();
return $this->render("pages/formations.html.twig", [
return $this->render($this->formationPage, [
'formations' => $formations,
'categories' => $categories
]);
}
}
#[Route('/formations/recherche/{champ}/{table}', name: 'formations.findallcontain')]
public function findAllContain($champ, Request $request, $table=""): Response{
$valeur = $request->get("recherche");
$formations = $this->formationRepository->findByContainValue($champ, $valeur, $table);
$categories = $this->categorieRepository->findAll();
return $this->render("pages/formations.html.twig", [
return $this->render($this->formationPage, [
'formations' => $formations,
'categories' => $categories,
'valeur' => $valeur,
'table' => $table
]);
}
}
#[Route('/formations/formation/{id}', name: 'formations.showone')]
public function showOne($id): Response{
$formation = $this->formationRepository->find($id);
return $this->render("pages/formation.html.twig", [
'formation' => $formation
]);
}
]);
}
}

View file

@ -17,24 +17,25 @@ use Symfony\Component\Routing\Annotation\Route;
class PlaylistsController extends AbstractController {
/**
*
*
* @var PlaylistRepository
*/
private $playlistRepository;
/**
*
*
* @var FormationRepository
*/
private $formationRepository;
/**
*
*
* @var CategorieRepository
*/
private $categorieRepository;
private $categorieRepository;
private $playlistPage = "/pages/playlists.html.twig";
function __construct(PlaylistRepository $playlistRepository,
public function __construct(PlaylistRepository $playlistRepository,
CategorieRepository $categorieRepository,
FormationRepository $formationRespository) {
$this->playlistRepository = $playlistRepository;
@ -52,7 +53,7 @@ class PlaylistsController extends AbstractController {
$categories = $this->categorieRepository->findAll();
return $this->render("pages/playlists.html.twig", [
'playlists' => $playlists,
'categories' => $categories
'categories' => $categories
]);
}
@ -62,26 +63,28 @@ class PlaylistsController extends AbstractController {
case "name":
$playlists = $this->playlistRepository->findAllOrderByName($ordre);
break;
default:
break;
}
$categories = $this->categorieRepository->findAll();
return $this->render("pages/playlists.html.twig", [
return $this->render($this->playlistPage, [
'playlists' => $playlists,
'categories' => $categories
'categories' => $categories
]);
}
}
#[Route('/playlists/recherche/{champ}/{table}', name: 'playlists.findallcontain')]
public function findAllContain($champ, Request $request, $table=""): Response{
$valeur = $request->get("recherche");
$playlists = $this->playlistRepository->findByContainValue($champ, $valeur, $table);
$categories = $this->categorieRepository->findAll();
return $this->render("pages/playlists.html.twig", [
return $this->render($this->playlistPage, [
'playlists' => $playlists,
'categories' => $categories,
'categories' => $categories,
'valeur' => $valeur,
'table' => $table
]);
}
}
#[Route('/playlists/playlist/{id}', name: 'playlists.showone')]
public function showOne($id): Response{
@ -92,7 +95,7 @@ class PlaylistsController extends AbstractController {
'playlist' => $playlist,
'playlistcategories' => $playlistCategories,
'playlistformations' => $playlistFormations
]);
}
]);
}
}

View file

@ -15,7 +15,7 @@ class Formation
/**
* Début de chemin vers les images
*/
private const cheminImage = "https://i.ytimg.com/vi/";
private const CHEMINIMAGE = "https://i.ytimg.com/vi/";
#[ORM\Id]
#[ORM\GeneratedValue]
@ -69,8 +69,8 @@ class Formation
if($this->publishedAt == null){
return "";
}
return $this->publishedAt->format('d/m/Y');
}
return $this->publishedAt->format('d/m/Y');
}
public function getTitle(): ?string
{
@ -110,12 +110,12 @@ class Formation
public function getMiniature(): ?string
{
return self::cheminImage.$this->videoId."/default.jpg";
return self::CHEMINIMAGE.$this->videoId."/default.jpg";
}
public function getPicture(): ?string
{
return self::cheminImage.$this->videoId."/hqdefault.jpg";
return self::CHEMINIMAGE.$this->videoId."/hqdefault.jpg";
}
public function getPlaylist(): ?playlist

View file

@ -39,9 +39,9 @@ class CategorieRepository extends ServiceEntityRepository
->join('f.playlist', 'p')
->where('p.id=:id')
->setParameter('id', $idPlaylist)
->orderBy('c.name', 'ASC')
->orderBy('c.name', 'ASC')
->getQuery()
->getResult();
}
->getResult();
}
}

View file

@ -31,11 +31,11 @@ class FormationRepository extends ServiceEntityRepository
/**
* Retourne toutes les formations triées sur un champ
* @param type $champ
* @param type $ordre
* @param string $ordre
* @param type $table si $champ dans une autre table
* @return Formation[]
*/
public function findAllOrderBy($champ, $ordre, $table=""): array{
public function findAllOrderBy($champ, string $ordre, $table=""): array{
if($table==""){
return $this->createQueryBuilder('f')
->orderBy('f.'.$champ, $ordre)
@ -46,7 +46,7 @@ class FormationRepository extends ServiceEntityRepository
->join('f.'.$table, 't')
->orderBy('t.'.$champ, $ordre)
->getQuery()
->getResult();
->getResult();
}
}
@ -68,30 +68,30 @@ class FormationRepository extends ServiceEntityRepository
->orderBy('f.publishedAt', 'DESC')
->setParameter('valeur', '%'.$valeur.'%')
->getQuery()
->getResult();
->getResult();
}else{
return $this->createQueryBuilder('f')
->join('f.'.$table, 't')
->join('f.'.$table, 't')
->where('t.'.$champ.' LIKE :valeur')
->orderBy('f.publishedAt', 'DESC')
->setParameter('valeur', '%'.$valeur.'%')
->getQuery()
->getResult();
}
}
->getResult();
}
}
/**
* Retourne les n formations les plus récentes
* @param type $nb
* @param int $nb
* @return Formation[]
*/
public function findAllLasted($nb) : array {
public function findAllLasted(int $nb) : array {
return $this->createQueryBuilder('f')
->orderBy('f.publishedAt', 'DESC')
->setMaxResults($nb)
->setMaxResults($nb)
->getQuery()
->getResult();
}
}
/**
* Retourne la liste des formations d'une playlist
@ -103,9 +103,9 @@ class FormationRepository extends ServiceEntityRepository
->join('f.playlist', 'p')
->where('p.id=:id')
->setParameter('id', $idPlaylist)
->orderBy('f.publishedAt', 'ASC')
->orderBy('f.publishedAt', 'ASC')
->getQuery()
->getResult();
->getResult();
}
}

View file

@ -31,7 +31,7 @@ class PlaylistRepository extends ServiceEntityRepository
/**
* Retourne toutes les playlists triées sur le nom de la playlist
* @param type $champ
* @param type $ordre
* @param string $ordre
* @return Playlist[]
*/
public function findAllOrderByName($ordre): array{
@ -40,8 +40,8 @@ class PlaylistRepository extends ServiceEntityRepository
->groupBy('p.id')
->orderBy('p.name', $ordre)
->getQuery()
->getResult();
}
->getResult();
}
/**
* Enregistrements dont un champ contient une valeur
@ -54,8 +54,8 @@ class PlaylistRepository extends ServiceEntityRepository
public function findByContainValue($champ, $valeur, $table=""): array{
if($valeur==""){
return $this->findAllOrderByName('ASC');
}
if($table==""){
}
if($table==""){
return $this->createQueryBuilder('p')
->leftjoin('p.formations', 'f')
->where('p.'.$champ.' LIKE :valeur')
@ -63,8 +63,8 @@ class PlaylistRepository extends ServiceEntityRepository
->groupBy('p.id')
->orderBy('p.name', 'ASC')
->getQuery()
->getResult();
}else{
->getResult();
}else{
return $this->createQueryBuilder('p')
->leftjoin('p.formations', 'f')
->leftjoin('f.categories', 'c')
@ -73,8 +73,8 @@ class PlaylistRepository extends ServiceEntityRepository
->groupBy('p.id')
->orderBy('p.name', 'ASC')
->getQuery()
->getResult();
}
}
->getResult();
}
}
}