M1.1 : nettoyer le code
This commit is contained in:
parent
30010bce1f
commit
f9c0ed3a63
7 changed files with 64 additions and 60 deletions
|
|
@ -19,23 +19,23 @@ class AccueilController extends AbstractController{
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param FormationRepository $repository
|
* @param FormationRepository $repository
|
||||||
*/
|
*/
|
||||||
public function __construct(FormationRepository $repository) {
|
public function __construct(FormationRepository $repository) {
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/', name: 'accueil')]
|
#[Route('/', name: 'accueil')]
|
||||||
public function index(): Response{
|
public function index(): Response{
|
||||||
$formations = $this->repository->findAllLasted(2);
|
$formations = $this->repository->findAllLasted(2);
|
||||||
return $this->render("pages/accueil.html.twig", [
|
return $this->render("pages/accueil.html.twig", [
|
||||||
'formations' => $formations
|
'formations' => $formations
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/cgu', name: 'cgu')]
|
#[Route('/cgu', name: 'cgu')]
|
||||||
public function cgu(): Response{
|
public function cgu(): Response{
|
||||||
return $this->render("pages/cgu.html.twig");
|
return $this->render("pages/cgu.html.twig");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,18 +16,19 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||||
class FormationsController extends AbstractController {
|
class FormationsController extends AbstractController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var FormationRepository
|
* @var FormationRepository
|
||||||
*/
|
*/
|
||||||
private $formationRepository;
|
private $formationRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var CategorieRepository
|
* @var CategorieRepository
|
||||||
*/
|
*/
|
||||||
private $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->formationRepository = $formationRepository;
|
||||||
$this->categorieRepository= $categorieRepository;
|
$this->categorieRepository= $categorieRepository;
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +37,7 @@ class FormationsController extends AbstractController {
|
||||||
public function index(): Response{
|
public function index(): Response{
|
||||||
$formations = $this->formationRepository->findAll();
|
$formations = $this->formationRepository->findAll();
|
||||||
$categories = $this->categorieRepository->findAll();
|
$categories = $this->categorieRepository->findAll();
|
||||||
return $this->render("pages/formations.html.twig", [
|
return $this->render($this->formationPage, [
|
||||||
'formations' => $formations,
|
'formations' => $formations,
|
||||||
'categories' => $categories
|
'categories' => $categories
|
||||||
]);
|
]);
|
||||||
|
|
@ -46,31 +47,31 @@ class FormationsController extends AbstractController {
|
||||||
public function sort($champ, $ordre, $table=""): Response{
|
public function sort($champ, $ordre, $table=""): Response{
|
||||||
$formations = $this->formationRepository->findAllOrderBy($champ, $ordre, $table);
|
$formations = $this->formationRepository->findAllOrderBy($champ, $ordre, $table);
|
||||||
$categories = $this->categorieRepository->findAll();
|
$categories = $this->categorieRepository->findAll();
|
||||||
return $this->render("pages/formations.html.twig", [
|
return $this->render($this->formationPage, [
|
||||||
'formations' => $formations,
|
'formations' => $formations,
|
||||||
'categories' => $categories
|
'categories' => $categories
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/formations/recherche/{champ}/{table}', name: 'formations.findallcontain')]
|
#[Route('/formations/recherche/{champ}/{table}', name: 'formations.findallcontain')]
|
||||||
public function findAllContain($champ, Request $request, $table=""): Response{
|
public function findAllContain($champ, Request $request, $table=""): Response{
|
||||||
$valeur = $request->get("recherche");
|
$valeur = $request->get("recherche");
|
||||||
$formations = $this->formationRepository->findByContainValue($champ, $valeur, $table);
|
$formations = $this->formationRepository->findByContainValue($champ, $valeur, $table);
|
||||||
$categories = $this->categorieRepository->findAll();
|
$categories = $this->categorieRepository->findAll();
|
||||||
return $this->render("pages/formations.html.twig", [
|
return $this->render($this->formationPage, [
|
||||||
'formations' => $formations,
|
'formations' => $formations,
|
||||||
'categories' => $categories,
|
'categories' => $categories,
|
||||||
'valeur' => $valeur,
|
'valeur' => $valeur,
|
||||||
'table' => $table
|
'table' => $table
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/formations/formation/{id}', name: 'formations.showone')]
|
#[Route('/formations/formation/{id}', name: 'formations.showone')]
|
||||||
public function showOne($id): Response{
|
public function showOne($id): Response{
|
||||||
$formation = $this->formationRepository->find($id);
|
$formation = $this->formationRepository->find($id);
|
||||||
return $this->render("pages/formation.html.twig", [
|
return $this->render("pages/formation.html.twig", [
|
||||||
'formation' => $formation
|
'formation' => $formation
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,24 +17,25 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||||
class PlaylistsController extends AbstractController {
|
class PlaylistsController extends AbstractController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var PlaylistRepository
|
* @var PlaylistRepository
|
||||||
*/
|
*/
|
||||||
private $playlistRepository;
|
private $playlistRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var FormationRepository
|
* @var FormationRepository
|
||||||
*/
|
*/
|
||||||
private $formationRepository;
|
private $formationRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var CategorieRepository
|
* @var CategorieRepository
|
||||||
*/
|
*/
|
||||||
private $categorieRepository;
|
private $categorieRepository;
|
||||||
|
private $playlistPage = "/pages/playlists.html.twig";
|
||||||
|
|
||||||
function __construct(PlaylistRepository $playlistRepository,
|
public function __construct(PlaylistRepository $playlistRepository,
|
||||||
CategorieRepository $categorieRepository,
|
CategorieRepository $categorieRepository,
|
||||||
FormationRepository $formationRespository) {
|
FormationRepository $formationRespository) {
|
||||||
$this->playlistRepository = $playlistRepository;
|
$this->playlistRepository = $playlistRepository;
|
||||||
|
|
@ -52,7 +53,7 @@ class PlaylistsController extends AbstractController {
|
||||||
$categories = $this->categorieRepository->findAll();
|
$categories = $this->categorieRepository->findAll();
|
||||||
return $this->render("pages/playlists.html.twig", [
|
return $this->render("pages/playlists.html.twig", [
|
||||||
'playlists' => $playlists,
|
'playlists' => $playlists,
|
||||||
'categories' => $categories
|
'categories' => $categories
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,26 +63,28 @@ class PlaylistsController extends AbstractController {
|
||||||
case "name":
|
case "name":
|
||||||
$playlists = $this->playlistRepository->findAllOrderByName($ordre);
|
$playlists = $this->playlistRepository->findAllOrderByName($ordre);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$categories = $this->categorieRepository->findAll();
|
$categories = $this->categorieRepository->findAll();
|
||||||
return $this->render("pages/playlists.html.twig", [
|
return $this->render($this->playlistPage, [
|
||||||
'playlists' => $playlists,
|
'playlists' => $playlists,
|
||||||
'categories' => $categories
|
'categories' => $categories
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/playlists/recherche/{champ}/{table}', name: 'playlists.findallcontain')]
|
#[Route('/playlists/recherche/{champ}/{table}', name: 'playlists.findallcontain')]
|
||||||
public function findAllContain($champ, Request $request, $table=""): Response{
|
public function findAllContain($champ, Request $request, $table=""): Response{
|
||||||
$valeur = $request->get("recherche");
|
$valeur = $request->get("recherche");
|
||||||
$playlists = $this->playlistRepository->findByContainValue($champ, $valeur, $table);
|
$playlists = $this->playlistRepository->findByContainValue($champ, $valeur, $table);
|
||||||
$categories = $this->categorieRepository->findAll();
|
$categories = $this->categorieRepository->findAll();
|
||||||
return $this->render("pages/playlists.html.twig", [
|
return $this->render($this->playlistPage, [
|
||||||
'playlists' => $playlists,
|
'playlists' => $playlists,
|
||||||
'categories' => $categories,
|
'categories' => $categories,
|
||||||
'valeur' => $valeur,
|
'valeur' => $valeur,
|
||||||
'table' => $table
|
'table' => $table
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/playlists/playlist/{id}', name: 'playlists.showone')]
|
#[Route('/playlists/playlist/{id}', name: 'playlists.showone')]
|
||||||
public function showOne($id): Response{
|
public function showOne($id): Response{
|
||||||
|
|
@ -92,7 +95,7 @@ class PlaylistsController extends AbstractController {
|
||||||
'playlist' => $playlist,
|
'playlist' => $playlist,
|
||||||
'playlistcategories' => $playlistCategories,
|
'playlistcategories' => $playlistCategories,
|
||||||
'playlistformations' => $playlistFormations
|
'playlistformations' => $playlistFormations
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class Formation
|
||||||
/**
|
/**
|
||||||
* Début de chemin vers les images
|
* 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\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
|
|
@ -69,8 +69,8 @@ class Formation
|
||||||
if($this->publishedAt == null){
|
if($this->publishedAt == null){
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return $this->publishedAt->format('d/m/Y');
|
return $this->publishedAt->format('d/m/Y');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(): ?string
|
public function getTitle(): ?string
|
||||||
{
|
{
|
||||||
|
|
@ -110,12 +110,12 @@ class Formation
|
||||||
|
|
||||||
public function getMiniature(): ?string
|
public function getMiniature(): ?string
|
||||||
{
|
{
|
||||||
return self::cheminImage.$this->videoId."/default.jpg";
|
return self::CHEMINIMAGE.$this->videoId."/default.jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPicture(): ?string
|
public function getPicture(): ?string
|
||||||
{
|
{
|
||||||
return self::cheminImage.$this->videoId."/hqdefault.jpg";
|
return self::CHEMINIMAGE.$this->videoId."/hqdefault.jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPlaylist(): ?playlist
|
public function getPlaylist(): ?playlist
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ class CategorieRepository extends ServiceEntityRepository
|
||||||
->join('f.playlist', 'p')
|
->join('f.playlist', 'p')
|
||||||
->where('p.id=:id')
|
->where('p.id=:id')
|
||||||
->setParameter('id', $idPlaylist)
|
->setParameter('id', $idPlaylist)
|
||||||
->orderBy('c.name', 'ASC')
|
->orderBy('c.name', 'ASC')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,11 @@ class FormationRepository extends ServiceEntityRepository
|
||||||
/**
|
/**
|
||||||
* Retourne toutes les formations triées sur un champ
|
* Retourne toutes les formations triées sur un champ
|
||||||
* @param type $champ
|
* @param type $champ
|
||||||
* @param type $ordre
|
* @param string $ordre
|
||||||
* @param type $table si $champ dans une autre table
|
* @param type $table si $champ dans une autre table
|
||||||
* @return Formation[]
|
* @return Formation[]
|
||||||
*/
|
*/
|
||||||
public function findAllOrderBy($champ, $ordre, $table=""): array{
|
public function findAllOrderBy($champ, string $ordre, $table=""): array{
|
||||||
if($table==""){
|
if($table==""){
|
||||||
return $this->createQueryBuilder('f')
|
return $this->createQueryBuilder('f')
|
||||||
->orderBy('f.'.$champ, $ordre)
|
->orderBy('f.'.$champ, $ordre)
|
||||||
|
|
@ -46,7 +46,7 @@ class FormationRepository extends ServiceEntityRepository
|
||||||
->join('f.'.$table, 't')
|
->join('f.'.$table, 't')
|
||||||
->orderBy('t.'.$champ, $ordre)
|
->orderBy('t.'.$champ, $ordre)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,30 +68,30 @@ class FormationRepository extends ServiceEntityRepository
|
||||||
->orderBy('f.publishedAt', 'DESC')
|
->orderBy('f.publishedAt', 'DESC')
|
||||||
->setParameter('valeur', '%'.$valeur.'%')
|
->setParameter('valeur', '%'.$valeur.'%')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}else{
|
}else{
|
||||||
return $this->createQueryBuilder('f')
|
return $this->createQueryBuilder('f')
|
||||||
->join('f.'.$table, 't')
|
->join('f.'.$table, 't')
|
||||||
->where('t.'.$champ.' LIKE :valeur')
|
->where('t.'.$champ.' LIKE :valeur')
|
||||||
->orderBy('f.publishedAt', 'DESC')
|
->orderBy('f.publishedAt', 'DESC')
|
||||||
->setParameter('valeur', '%'.$valeur.'%')
|
->setParameter('valeur', '%'.$valeur.'%')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne les n formations les plus récentes
|
* Retourne les n formations les plus récentes
|
||||||
* @param type $nb
|
* @param int $nb
|
||||||
* @return Formation[]
|
* @return Formation[]
|
||||||
*/
|
*/
|
||||||
public function findAllLasted($nb) : array {
|
public function findAllLasted(int $nb) : array {
|
||||||
return $this->createQueryBuilder('f')
|
return $this->createQueryBuilder('f')
|
||||||
->orderBy('f.publishedAt', 'DESC')
|
->orderBy('f.publishedAt', 'DESC')
|
||||||
->setMaxResults($nb)
|
->setMaxResults($nb)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne la liste des formations d'une playlist
|
* Retourne la liste des formations d'une playlist
|
||||||
|
|
@ -103,9 +103,9 @@ class FormationRepository extends ServiceEntityRepository
|
||||||
->join('f.playlist', 'p')
|
->join('f.playlist', 'p')
|
||||||
->where('p.id=:id')
|
->where('p.id=:id')
|
||||||
->setParameter('id', $idPlaylist)
|
->setParameter('id', $idPlaylist)
|
||||||
->orderBy('f.publishedAt', 'ASC')
|
->orderBy('f.publishedAt', 'ASC')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class PlaylistRepository extends ServiceEntityRepository
|
||||||
/**
|
/**
|
||||||
* Retourne toutes les playlists triées sur le nom de la playlist
|
* Retourne toutes les playlists triées sur le nom de la playlist
|
||||||
* @param type $champ
|
* @param type $champ
|
||||||
* @param type $ordre
|
* @param string $ordre
|
||||||
* @return Playlist[]
|
* @return Playlist[]
|
||||||
*/
|
*/
|
||||||
public function findAllOrderByName($ordre): array{
|
public function findAllOrderByName($ordre): array{
|
||||||
|
|
@ -40,8 +40,8 @@ class PlaylistRepository extends ServiceEntityRepository
|
||||||
->groupBy('p.id')
|
->groupBy('p.id')
|
||||||
->orderBy('p.name', $ordre)
|
->orderBy('p.name', $ordre)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enregistrements dont un champ contient une valeur
|
* Enregistrements dont un champ contient une valeur
|
||||||
|
|
@ -54,8 +54,8 @@ class PlaylistRepository extends ServiceEntityRepository
|
||||||
public function findByContainValue($champ, $valeur, $table=""): array{
|
public function findByContainValue($champ, $valeur, $table=""): array{
|
||||||
if($valeur==""){
|
if($valeur==""){
|
||||||
return $this->findAllOrderByName('ASC');
|
return $this->findAllOrderByName('ASC');
|
||||||
}
|
}
|
||||||
if($table==""){
|
if($table==""){
|
||||||
return $this->createQueryBuilder('p')
|
return $this->createQueryBuilder('p')
|
||||||
->leftjoin('p.formations', 'f')
|
->leftjoin('p.formations', 'f')
|
||||||
->where('p.'.$champ.' LIKE :valeur')
|
->where('p.'.$champ.' LIKE :valeur')
|
||||||
|
|
@ -63,8 +63,8 @@ class PlaylistRepository extends ServiceEntityRepository
|
||||||
->groupBy('p.id')
|
->groupBy('p.id')
|
||||||
->orderBy('p.name', 'ASC')
|
->orderBy('p.name', 'ASC')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}else{
|
}else{
|
||||||
return $this->createQueryBuilder('p')
|
return $this->createQueryBuilder('p')
|
||||||
->leftjoin('p.formations', 'f')
|
->leftjoin('p.formations', 'f')
|
||||||
->leftjoin('f.categories', 'c')
|
->leftjoin('f.categories', 'c')
|
||||||
|
|
@ -73,8 +73,8 @@ class PlaylistRepository extends ServiceEntityRepository
|
||||||
->groupBy('p.id')
|
->groupBy('p.id')
|
||||||
->orderBy('p.name', 'ASC')
|
->orderBy('p.name', 'ASC')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue