M2T1 : gérer les formations
This commit is contained in:
parent
7aa5c3d816
commit
82fa6eca52
8 changed files with 297 additions and 2 deletions
87
src/Controller/admin/AdminFormationsController.php
Normal file
87
src/Controller/admin/AdminFormationsController.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
namespace App\Controller\admin;
|
||||
|
||||
use App\Entity\Formation;
|
||||
use App\Form\FormationType;
|
||||
use App\Repository\CategorieRepository;
|
||||
use App\Repository\FormationRepository;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AdminFormationsController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var FormationRepository
|
||||
*/
|
||||
private $formationRepository;
|
||||
private $categorieRepository;
|
||||
|
||||
private $adminPage = "pages/admin/admin.formations.html.twig";
|
||||
|
||||
public function __construct(FormationRepository $formationRepository, CategorieRepository $categorieRepository)
|
||||
{
|
||||
$this->formationRepository = $formationRepository;
|
||||
$this->categorieRepository = $categorieRepository;
|
||||
}
|
||||
|
||||
#[Route('/admin', name: 'admin.formations')]
|
||||
public function index() : Response
|
||||
{
|
||||
$formations = $this->formationRepository->findAllOrderBy('publishedAt', 'DESC');
|
||||
$categories = $this->categorieRepository->findAll();
|
||||
return $this->render("pages/admin/admin.formations.html.twig", [
|
||||
'formations' => $formations,
|
||||
'categories' => $categories
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/formations/tri/{champ}/{ordre}/{table}', name: 'admin.formations.sort')]
|
||||
public function sort($champ, $ordre, $table=""): Response{
|
||||
$formations = $this->formationRepository->findAllOrderBy($champ, $ordre, $table);
|
||||
$categories = $this->categorieRepository->findAll();
|
||||
return $this->render($this->adminPage, [
|
||||
'formations' => $formations,
|
||||
'categories' => $categories
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/recherche/{champ}/{table}', name: 'admin.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($this->adminPage, [
|
||||
'formations' => $formations,
|
||||
'categories' => $categories,
|
||||
'valeur' => $valeur,
|
||||
'table' => $table
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/creerFormation', name: 'admin.creerFormation')]
|
||||
public function afficherCreerFormation(Request $request) : Response{
|
||||
$formation = new Formation;
|
||||
$formCreateFormation = $this->createForm(FormationType::class, $formation);
|
||||
$formCreateFormation->handleRequest($request);
|
||||
|
||||
if($formCreateFormation->isSubmitted() && $formCreateFormation->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'=> $formCreateFormation->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/remove/{id}', name: 'admin.formations.remove')]
|
||||
public function remove(int $id)
|
||||
{
|
||||
$formation = $this->formationRepository->find($id);
|
||||
$this->formationRepository->remove($formation);
|
||||
return $this->redirectToRoute('admin.formations');
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FormationRepository::class)]
|
||||
class Formation
|
||||
|
|
@ -23,6 +24,7 @@ class Formation
|
|||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
||||
#[Assert\LessThanOrEqual('now', message:"La date ne peut pas être postétrieure à aujourd'hui.")]
|
||||
private ?\DateTimeInterface $publishedAt = null;
|
||||
|
||||
#[ORM\Column(length: 100, nullable: true)]
|
||||
|
|
|
|||
55
src/Form/FormationType.php
Normal file
55
src/Form/FormationType.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Categorie;
|
||||
use App\Entity\Formation;
|
||||
use App\Entity\Playlist;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
|
||||
class FormationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('publishedAt', null, [
|
||||
'widget' => 'single_text',
|
||||
'required' => 'true'
|
||||
])
|
||||
->add('title', null, [
|
||||
'required' => 'true'
|
||||
])
|
||||
->add('description', null, [
|
||||
'required' => 'false'
|
||||
])
|
||||
->add('videoId', null, [
|
||||
'required' => 'true'
|
||||
])
|
||||
->add('playlist', EntityType::class, [
|
||||
'class' => Playlist::class,
|
||||
'choice_label' => 'name',
|
||||
'required' => 'true'
|
||||
])
|
||||
->add('categories', EntityType::class, [
|
||||
'class' => Categorie::class,
|
||||
'choice_label' => 'name',
|
||||
'multiple' => true,
|
||||
'required' => false,
|
||||
])
|
||||
->add('submit', SubmitType::class, [
|
||||
'label' => 'Enregistrer'
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Formation::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
templates/baseadmin.html.twig
Normal file
41
templates/baseadmin.html.twig
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
{% extends "base.html.twig" %}
|
||||
|
||||
{% block title %}{% endblock %}
|
||||
{% block stylesheets %}{% endblock %}
|
||||
{% block top %}
|
||||
<div class="container">
|
||||
<!-- titre -->
|
||||
<div class="text-left">
|
||||
<img src="{{ app.request.getBasePath()~'/banniere.jpg' }}" alt="Bannière Mediatek Formation">
|
||||
</div>
|
||||
<!-- menu -->
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ path('accueil') }}">Accueil</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ path('formations') }}">Formations</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ path('playlists') }}">Playlists</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block body %}{% endblock %}
|
||||
{% block footer %}
|
||||
<div class="container text-center">
|
||||
<footer>
|
||||
<hr>
|
||||
<p><small><i>
|
||||
Consultez nos <a class="link-secondary" href="{{ path('cgu') }}">Conditions Générales d'Utilisation</a>
|
||||
</i></small></p>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block javascripts %}{% endblock %}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<div class="container">
|
||||
<!-- titre -->
|
||||
<div class="text-left">
|
||||
<img src="{{ app.request.getBasePath()~'/banniere.jpg' }}" >
|
||||
<img src="{{ app.request.getBasePath()~'/banniere.jpg' }}" alt="Bannière Mediatek Formation">
|
||||
</div>
|
||||
<!-- menu -->
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
|
|
|
|||
25
templates/pages/admin/admin.addFormation.html.twig
Normal file
25
templates/pages/admin/admin.addFormation.html.twig
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{% extends "baseadmin.html.twig" %}
|
||||
{% block body %}
|
||||
{{ form_start(formCreateFormation) }}
|
||||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
{{ form_row(formCreateFormation.title) }}
|
||||
</div>
|
||||
<div class="col">
|
||||
{{ form_row(formCreateFormation.description) }}
|
||||
</div>
|
||||
<div class="col">
|
||||
{{ form_row(formCreateFormation.playlist) }}
|
||||
</div>
|
||||
<div class="col">
|
||||
{{ form_row(formCreateFormation.categories) }}
|
||||
</div>
|
||||
<div class="col">
|
||||
{{ form_row(formCreateFormation.videoId) }}
|
||||
</div>
|
||||
<div class="col">
|
||||
{{ form_row(formCreateFormation.publishedAt) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ form_end(formCreateFormation) }}
|
||||
{% endblock %}
|
||||
85
templates/pages/admin/admin.formations.html.twig
Normal file
85
templates/pages/admin/admin.formations.html.twig
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
{% extends "baseadmin.html.twig" %}
|
||||
|
||||
{% block body %}
|
||||
<table class="table table-stripped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Nom
|
||||
<a href="{{ path('admin.formations.sort', {champ:'title', ordre:'ASC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true"><</a>
|
||||
<a href="{{ path('admin.formations.sort', {champ:'title', 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('admin.formations.findallcontain', {champ:'title'}) }}">
|
||||
<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_title') }}">
|
||||
<button type="submit" class="btn btn-info mb-2 btn-sm">filtrer</button>
|
||||
</div>
|
||||
</form>
|
||||
</th>
|
||||
<th>
|
||||
Playlist
|
||||
<a href="{{ path('admin.formations.sort', {table:'playlist', champ:'name', ordre:'ASC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true"><</a>
|
||||
<a href="{{ path('admin.formations.sort', {table:'playlist', champ:'name', ordre:'ASC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true">></a>
|
||||
<form class="form-inline mt-1" method="POST" action="{{ path('admin.formations.findallcontain', {champ:'name', table:'playlist'}) }}">
|
||||
<div class="form-group mr-1 mb-2">
|
||||
<input type="text" class="sm" name="recherche"
|
||||
value="{% if valeur|default and table|default and table=='playlist' %}{{ 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>
|
||||
Catégories
|
||||
<form class="form-inline mt-1" method="POST" action="{{ path('formations.findallcontain', {champ:'id', table:'categories'}) }}">
|
||||
<select class="form-select form-select-sm" name="recherche" id="recherche" onchange="this.form.submit()">
|
||||
<option value=""></option>
|
||||
{% for categorie in categories %}
|
||||
<option
|
||||
{% if valeur|default and valeur==categorie.id %}
|
||||
selected
|
||||
{% endif %}
|
||||
value="{{ categorie.id }}">{{ categorie.name }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</form>
|
||||
</th>
|
||||
<th>
|
||||
Date
|
||||
<a href="{{ path('admin.formations.sort', {champ:'publishedAt', ordre:'ASC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true"><</a>
|
||||
<a href="{{ path('admin.formations.sort', {champ:'publishedAt', ordre:'DESC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true">></a>
|
||||
</th>
|
||||
<th>
|
||||
Actions
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for formation in formations %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ formation.title }}
|
||||
</td>
|
||||
<td>
|
||||
{{ formation.playlist.name }}
|
||||
</td>
|
||||
<td>
|
||||
{% for categorie in formation.categories %}
|
||||
{{ categorie.name }}<br />
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>
|
||||
{{ formation.publishedatstring }}
|
||||
</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="#" class="btn btn-danger">Modifier</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<a href="{{ path('admin.creerFormation')}}" class="btn btn-primary">Ajouter une formation</a>
|
||||
{% endblock %}
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
<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>
|
||||
</form>
|
||||
</th>
|
||||
<th class="text-left align-top" scope="col">
|
||||
catégories
|
||||
|
|
|
|||
Loading…
Reference in a new issue