M2T2 : gérer les playlists
This commit is contained in:
parent
82fa6eca52
commit
9bf8205b4d
7 changed files with 265 additions and 2 deletions
|
|
@ -62,7 +62,7 @@ class AdminFormationsController extends AbstractController
|
||||||
|
|
||||||
#[Route('/admin/creerFormation', name: 'admin.creerFormation')]
|
#[Route('/admin/creerFormation', name: 'admin.creerFormation')]
|
||||||
public function afficherCreerFormation(Request $request) : Response{
|
public function afficherCreerFormation(Request $request) : Response{
|
||||||
$formation = new Formation;
|
$formation = new Formation();
|
||||||
$formCreateFormation = $this->createForm(FormationType::class, $formation);
|
$formCreateFormation = $this->createForm(FormationType::class, $formation);
|
||||||
$formCreateFormation->handleRequest($request);
|
$formCreateFormation->handleRequest($request);
|
||||||
|
|
||||||
|
|
@ -77,6 +77,24 @@ class AdminFormationsController extends AbstractController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('admin/formations/modifier/{id}', name: 'admin.formations.modifier')]
|
||||||
|
public function modifier(Request $request, int $id){
|
||||||
|
$formation = $this->formationRepository->find($id);
|
||||||
|
|
||||||
|
$formModifierFormation = $this->createForm(FormationType::class, $formation);
|
||||||
|
$formModifierFormation->handleRequest($request);
|
||||||
|
|
||||||
|
if($formModifierFormation->isSubmitted() && $formModifierFormation->isValid()){
|
||||||
|
$this->formationRepository->add($formation);
|
||||||
|
$this->addFlash('success', 'La formation a bien été créée !');
|
||||||
|
return $this->redirectToRoute('admin.formations');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('pages/admin/admin.addFormation.html.twig', [
|
||||||
|
'formCreateFormation'=> $formModifierFormation->createView()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/admin/remove/{id}', name: 'admin.formations.remove')]
|
#[Route('/admin/remove/{id}', name: 'admin.formations.remove')]
|
||||||
public function remove(int $id)
|
public function remove(int $id)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
120
src/Controller/admin/AdminPlaylistsController.php
Normal file
120
src/Controller/admin/AdminPlaylistsController.php
Normal file
|
|
@ -0,0 +1,120 @@
|
||||||
|
<?php
|
||||||
|
namespace App\Controller\admin;
|
||||||
|
|
||||||
|
use App\Entity\Playlist;
|
||||||
|
use App\Form\PlaylistType;
|
||||||
|
use App\Repository\CategorieRepository;
|
||||||
|
use App\Repository\FormationRepository;
|
||||||
|
use App\Repository\PlaylistRepository;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class AdminPlaylistsController extends AbstractController
|
||||||
|
{
|
||||||
|
private $playlistPage = "pages/admin/admin.playlists.html.twig";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PlaylistRepository
|
||||||
|
*/
|
||||||
|
private $playlistRepository;
|
||||||
|
private $formationRepository;
|
||||||
|
private $categorieRepository;
|
||||||
|
|
||||||
|
public function __construct(PlaylistRepository $playlistRepository, FormationRepository $formationRepository, CategorieRepository $categorieRepository)
|
||||||
|
{
|
||||||
|
$this->playlistRepository = $playlistRepository;
|
||||||
|
$this->formationRepository = $formationRepository;
|
||||||
|
$this->categorieRepository = $categorieRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/playlists', name: 'admin.playlists')]
|
||||||
|
public function index() : Response
|
||||||
|
{
|
||||||
|
$playlists = $this->playlistRepository->findAllOrderByName('ASC');
|
||||||
|
return $this->render($this->playlistPage, [
|
||||||
|
"playlists" => $playlists,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/playlists/delete/{id}', name:'admin.playlists.remove')]
|
||||||
|
public function remove($id){
|
||||||
|
$playlist = $this->playlistRepository->find($id);
|
||||||
|
if($this->playlistRepository->countFormationsByPlaylist($playlist) > 0){
|
||||||
|
return $this->redirectToRoute('admin.playlists');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->playlistRepository->remove($playlist);
|
||||||
|
return $this->redirectToRoute('admin.playlists');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/playlists/modifier/{id}', name:'admin.playlists.modifier')]
|
||||||
|
public function modifier(Request $request, int $id){
|
||||||
|
$playlist = $this->playlistRepository->find($id);
|
||||||
|
$formModifierPlaylist = $this->createForm(PlaylistType::class, $playlist);
|
||||||
|
$formModifierPlaylist->handleRequest($request);
|
||||||
|
|
||||||
|
$formations = $this->formationRepository->findAllForOnePlaylist($id);
|
||||||
|
|
||||||
|
if($formModifierPlaylist->isSubmitted() && $formModifierPlaylist->isValid()){
|
||||||
|
$this->playlistRepository->add($playlist);
|
||||||
|
$this->addFlash('success', 'La playlist a bien été modifiée !');
|
||||||
|
return $this->redirectToRoute('admin.playlists');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('pages/admin/admin.addPlaylist.html.twig', [
|
||||||
|
'formModifierPlaylist'=> $formModifierPlaylist->createView(),
|
||||||
|
'formations'=> $formations,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/playlists/create', name:'admin.playlists.create')]
|
||||||
|
public function create(Request $request){
|
||||||
|
$playlist = new Playlist;
|
||||||
|
$formCreerPlaylist = $this->createForm(PlaylistType::class, $playlist);
|
||||||
|
$formCreerPlaylist->handleRequest($request);
|
||||||
|
|
||||||
|
$formations = [];
|
||||||
|
|
||||||
|
if($formCreerPlaylist->isSubmitted() && $formCreerPlaylist->isValid()){
|
||||||
|
$this->playlistRepository->add($playlist);
|
||||||
|
$this->addFlash('success', 'La playlist a bien été créée !');
|
||||||
|
return $this->redirectToRoute('admin.playlists');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('pages/admin/admin.addPlaylist.html.twig', [
|
||||||
|
'formModifierPlaylist'=> $formCreerPlaylist->createView(),
|
||||||
|
'formations'=> $formations,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/playlists/sort/{champ}/{ordre}', name:'admin.playlists.sort')]
|
||||||
|
public function sort(string $champ, string $ordre){
|
||||||
|
//
|
||||||
|
$playlists = $this->playlistRepository->findAllOrderByName($ordre);
|
||||||
|
return $this->render($this->playlistPage, [
|
||||||
|
"playlists" => $playlists,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/playlists/recherche/{champ}/{table}', name: 'adminplaylists.findallcontain')]
|
||||||
|
public function findAllContain($champ, Request $request, $table=""): Response{
|
||||||
|
$valeur = $request->get("recherche");
|
||||||
|
$playlists = $this->playlistRepository->findByContainValue($champ, $valeur, $table);
|
||||||
|
$categories = $this->categorieRepository->findAll();
|
||||||
|
|
||||||
|
$nombreFormations = [];
|
||||||
|
foreach ($playlists as $p) {
|
||||||
|
$nombreFormations[$p->getId()] = $this->playlistRepository->countFormationsByPlaylist($p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render($this->playlistPage, [
|
||||||
|
'playlists' => $playlists,
|
||||||
|
'categories' => $categories,
|
||||||
|
'valeur' => $valeur,
|
||||||
|
'table' => $table,
|
||||||
|
'nombreFormations' => $nombreFormations
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -107,5 +107,13 @@ class Playlist
|
||||||
}
|
}
|
||||||
return $categories;
|
return $categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getCountFormation() : int
|
||||||
|
{
|
||||||
|
return $this->formations->count();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
src/Form/PlaylistType.php
Normal file
32
src/Form/PlaylistType.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Entity\Playlist;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class PlaylistType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('name', null, [
|
||||||
|
'required' => true
|
||||||
|
])
|
||||||
|
->add('description')
|
||||||
|
->add('submit', SubmitType::class, [
|
||||||
|
'label' => 'Enregistrer'
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => Playlist::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
templates/pages/admin/admin.addPlaylist.html.twig
Normal file
22
templates/pages/admin/admin.addPlaylist.html.twig
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
{% extends "baseadmin.html.twig" %}
|
||||||
|
{% block body %}
|
||||||
|
{{ form_start(formModifierPlaylist) }}
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col">
|
||||||
|
{{ form_row(formModifierPlaylist.name) }}
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
{{ form_row(formModifierPlaylist.description) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ form_end(formModifierPlaylist) }}
|
||||||
|
{% if formations %}
|
||||||
|
<br>
|
||||||
|
<h3>Liste des formations dans la playlist :</h3>
|
||||||
|
<ul>
|
||||||
|
{% for formation in formations %}
|
||||||
|
<li>{{ formation.title }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -75,7 +75,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ path('admin.formations.remove', {'id': formation.id}) }}" class="btn btn-danger" onclick="return confirm('Êtes vous sûr de vouloir supprimer {{ formation.title }} ?')">Supprimer</a>
|
<a href="{{ path('admin.formations.remove', {'id': formation.id}) }}" class="btn btn-danger" onclick="return confirm('Êtes vous sûr de vouloir supprimer {{ formation.title }} ?')">Supprimer</a>
|
||||||
<a href="#" class="btn btn-danger">Modifier</a>
|
<a href="{{ path('admin.formations.modifier', {'id': formation.id}) }}" class="btn btn-danger">Modifier</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
63
templates/pages/admin/admin.playlists.html.twig
Normal file
63
templates/pages/admin/admin.playlists.html.twig
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
{% extends 'baseadmin.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<table class="table table-stripped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Nom
|
||||||
|
<a href="{{ path('admin.playlists.sort', {champ:'name', ordre:'ASC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true"><</a>
|
||||||
|
<a href="{{ path('admin.playlists.sort', {champ:'name', ordre:'DESC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true">></a>
|
||||||
|
<form class="form-inline mt-1" method="POST" action="{{ path('adminplaylists.findallcontain', {champ:'name'}) }}">
|
||||||
|
<div class="form-group mr-1 mb-2">
|
||||||
|
<input type="text" class="sm" name="recherche"
|
||||||
|
value="{% if valeur|default and not table|default %}{{ valeur }}{% endif %}">
|
||||||
|
<input type="hidden" name="_token" value="{{ csrf_token('filtre_name') }}">
|
||||||
|
<button type="submit" class="btn btn-info mb-2 btn-sm">filtrer</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Description
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Catégories
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Nombre de formations
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Actions
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for playlist in playlists %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{{ playlist.name }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ playlist.description }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% set categories = playlist.categoriesplaylist %}
|
||||||
|
{% if categories|length > 0 %}
|
||||||
|
{% for c in 0..categories|length-1 %}
|
||||||
|
{{ categories[c] }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ playlist.getCountFormation() }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ path('admin.playlists.remove', {'id': playlist.id}) }}" class="btn btn-danger" onclick="return confirm('Êtes vous sûr de vouloir supprimer {{ playlist.name }} ?')">Supprimer</a>
|
||||||
|
<a href="{{ path('admin.playlists.modifier', {'id': playlist.id}) }}" class="btn btn-danger">Modifier</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<a href="{{ path('admin.playlists.create') }}" class="btn btn-primary">Ajouter une playlist</a>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Reference in a new issue