146 lines
4.6 KiB
PHP
146 lines
4.6 KiB
PHP
|
<?php
|
||
|
namespace App\Controller;
|
||
|
|
||
|
use App\Entity\Patient;
|
||
|
use App\Form\PatientType;
|
||
|
use App\Form\Handler\PatientHandler;
|
||
|
use App\Repository\PatientRepository;
|
||
|
use App\Services\Tools;
|
||
|
use Doctrine\ORM\EntityManagerInterface;
|
||
|
use Psr\Container\ContainerInterface;
|
||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||
|
use Symfony\Component\HttpFoundation\Request;
|
||
|
use Symfony\Component\HttpFoundation\Response;
|
||
|
use Symfony\Component\Routing\Annotation\Route;
|
||
|
use Knp\Component\Pager\PaginatorInterface;
|
||
|
|
||
|
/**
|
||
|
* Class PatientController
|
||
|
* @package App\Controller
|
||
|
* @Route("/admin/patient", name="admin_app_patient_")
|
||
|
*/
|
||
|
class PatientController extends AbstractController
|
||
|
{
|
||
|
private EntityManagerInterface $entityManager;
|
||
|
public function __construct(EntityManagerInterface $entityManager)
|
||
|
{
|
||
|
$this->entityManager = $entityManager;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @Route("/", name="index", methods={"GET"})
|
||
|
* @param PatientRepository $patientRepository
|
||
|
* PaginatorInterface $paginator
|
||
|
* Request $request
|
||
|
*/
|
||
|
public function index(PatientRepository $patientRepository, PaginatorInterface $paginator, Request $request): Response
|
||
|
{
|
||
|
$els = $paginator->paginate(
|
||
|
$patientRepository->createQueryBuilder('a')->getQuery(),
|
||
|
$request->query->getInt('page', 1),
|
||
|
10
|
||
|
);
|
||
|
return $this->render('admin/crud/index.html.twig', [
|
||
|
'els'=>$els,
|
||
|
'paginator'=>false,
|
||
|
'search'=>false,
|
||
|
'class'=> Patient::class,
|
||
|
'route'=> 'admin_app_patient',
|
||
|
'breadcrumb'=>[
|
||
|
[
|
||
|
'text'=>'tous les éléments'
|
||
|
]
|
||
|
],
|
||
|
'fields' => [
|
||
|
'Id' => 'Id',
|
||
|
'Nom' => 'Lastname',
|
||
|
'Prénom' => 'Firstname',
|
||
|
'Date naissance' => 'Birthdate',
|
||
|
'Identifiant' => 'DonneurNumber',
|
||
|
|
||
|
],
|
||
|
'title' => 'Tous les élements',
|
||
|
'add_button_label'=>'Ajouter un élément'
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @Route("/new", name="new", methods={"GET","POST"})
|
||
|
* @param Request $request
|
||
|
* @param PatientHandler $patientHandler
|
||
|
* @param Tools $tools
|
||
|
* @return Response
|
||
|
*/
|
||
|
public function new(Request $request, Tools $tools, PatientHandler $patientHandler): Response
|
||
|
{
|
||
|
$patient = new Patient();
|
||
|
$form = $this->createForm(PatientType::class, $patient);
|
||
|
if ($patientHandler->new($form, $request)) {
|
||
|
return $this->redirectToRoute('admin_app_patient_index');
|
||
|
}
|
||
|
|
||
|
return $this->render('admin/crud/_form.html.twig', [
|
||
|
'form'=>$form->createView(),
|
||
|
'el'=>$patient,
|
||
|
'button_label'=>'Créer',
|
||
|
'route'=>'admin_app_patient',
|
||
|
'title'=>'Ajouter un élément',
|
||
|
'breadcrumb'=>[
|
||
|
[
|
||
|
'route'=>'admin_app_patient_index',
|
||
|
'text'=>'tous les éléments'
|
||
|
],
|
||
|
[
|
||
|
'text'=>'ajouter un élément'
|
||
|
]
|
||
|
],
|
||
|
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @Route("/edit/{id}", name="edit")
|
||
|
* @param Request $request
|
||
|
* @param Patient $patient
|
||
|
* @param Tools $tools
|
||
|
* @return Response
|
||
|
*/
|
||
|
public function edit(Request $request, Patient $patient, PatientHandler $patientHandler): Response
|
||
|
{
|
||
|
$form = $this->createForm(PatientType::class, $patient);
|
||
|
if ($patientHandler->edit($form, $request)) {
|
||
|
return $this->redirectToRoute('admin_app_patient_edit', ['id'=>$patient->getId()]);
|
||
|
}
|
||
|
return $this->render('admin/crud/_form.html.twig', [
|
||
|
'el' => $patient,
|
||
|
'route'=> 'admin_app_patient',
|
||
|
'form' => $form->createView(),
|
||
|
'button_label' => 'Mettre à jour',
|
||
|
'title' => 'Edition',
|
||
|
'breadcrumb'=>[
|
||
|
[
|
||
|
'route'=>'admin_app_patient_index',
|
||
|
'text'=>'patients'
|
||
|
],
|
||
|
[
|
||
|
'text'=>'édition '
|
||
|
]
|
||
|
],
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @Route("/{id}", name="delete", methods={"DELETE"})
|
||
|
* @param Request $request
|
||
|
* @return Response
|
||
|
*/
|
||
|
public function delete(Request $request,Patient $patient): Response
|
||
|
{
|
||
|
if ($this->isCsrfTokenValid('delete'.$patient->getId(), $request->request->get('_token'))) {
|
||
|
$this->entityManager->remove($patient);
|
||
|
$this->entityManager->flush();
|
||
|
}
|
||
|
return $this->redirectToRoute('admin_app_patient_index');
|
||
|
}
|
||
|
}
|