2022-07-21 16:15:47 +02:00
|
|
|
<?php
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
namespace App\Controller;
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
use App\Entity\Niveau01 as Entity;
|
|
|
|
use App\Form\Niveau01Type as Form;
|
|
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
use Ramsey\Uuid\Uuid;
|
2022-07-21 16:15:47 +02:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2022-09-23 16:14:15 +02:00
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
2022-07-21 16:15:47 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
class Niveau01Controller extends AbstractController
|
|
|
|
{
|
2022-09-23 16:14:15 +02:00
|
|
|
private $data = 'niveau01';
|
|
|
|
private $entity = "App\Entity\Niveau01";
|
|
|
|
private $twig = 'Niveau01/';
|
|
|
|
private $route = 'app_admin_niveau01';
|
|
|
|
|
2022-07-26 16:03:53 +02:00
|
|
|
public function list($access): Response
|
2022-09-23 16:14:15 +02:00
|
|
|
{
|
|
|
|
return $this->render($this->twig.'list.html.twig', [
|
|
|
|
'useheader' => true,
|
|
|
|
'usemenu' => false,
|
|
|
|
'usesidebar' => true,
|
|
|
|
'access' => $access,
|
2022-07-21 16:15:47 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function tablelist(Request $request, ManagerRegistry $em): Response
|
|
|
|
{
|
|
|
|
$query = $request->query->all();
|
|
|
|
$start = $query['start'];
|
|
|
|
$length = $query['length'];
|
|
|
|
$search = $query['search'];
|
|
|
|
$draw = $query['draw'];
|
|
|
|
$ordercolumn = $query['order'][0]['column'];
|
|
|
|
$orderdir = $query['order'][0]['dir'];
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Nombre total d'enregistrement
|
2022-09-23 16:14:15 +02:00
|
|
|
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Nombre d'enregistrement filtré
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$search || '' == $search['value']) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$totalf = $total;
|
2022-09-23 16:14:15 +02:00
|
|
|
} else {
|
|
|
|
$totalf = $em->getManager()->createQueryBuilder()
|
2022-07-21 16:15:47 +02:00
|
|
|
->select('COUNT(entity)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from($this->entity, 'entity')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where('entity.label LIKE :value')
|
2022-09-23 16:14:15 +02:00
|
|
|
->setParameter('value', '%'.$search['value'].'%')
|
2022-07-21 16:15:47 +02:00
|
|
|
->getQuery()
|
|
|
|
->getSingleScalarResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construction du tableau de retour
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = [
|
2022-07-21 16:15:47 +02:00
|
|
|
'draw' => $draw,
|
|
|
|
'recordsFiltered' => $totalf,
|
|
|
|
'recordsTotal' => $total,
|
2022-09-23 16:14:15 +02:00
|
|
|
'data' => [],
|
|
|
|
];
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Parcours des Enregistrement
|
|
|
|
$qb = $em->getManager()->createQueryBuilder();
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->select('entity')->from($this->entity, 'entity');
|
|
|
|
if ($search && '' != $search['value']) {
|
|
|
|
$qb->andWhere('entity.label LIKE :value')
|
|
|
|
->setParameter('value', '%'.$search['value'].'%');
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
if ($ordercolumn) {
|
|
|
|
switch ($ordercolumn) {
|
|
|
|
case 1:
|
|
|
|
$qb->orderBy('entity.label', $orderdir);
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
foreach ($datas as $data) {
|
2022-07-21 16:15:47 +02:00
|
|
|
// Action
|
2022-09-23 16:14:15 +02:00
|
|
|
$action = '';
|
|
|
|
$action .= "<a href='".$this->generateUrl($this->route.'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$tmp = [];
|
|
|
|
array_push($tmp, $action);
|
|
|
|
array_push($tmp, $data->getLabel());
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
if ('LDAP' == $this->getParameter('appMasteridentity') || 'LDAP2NINE' == $this->getParameter('appSynchro')) {
|
|
|
|
array_push($tmp, $data->getLdapfilter());
|
|
|
|
}
|
|
|
|
if ('SSO' == $this->getParameter('appMasteridentity')) {
|
|
|
|
array_push($tmp, $data->getAttributes());
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
array_push($output['data'], $tmp);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retour
|
|
|
|
return new JsonResponse($output);
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function submit($access, Request $request, ManagerRegistry $em): Response
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Initialisation de l'enregistrement
|
|
|
|
$data = new Entity();
|
|
|
|
$data->setApikey(Uuid::uuid4());
|
|
|
|
|
|
|
|
// Création du formulaire
|
2022-09-23 16:14:15 +02:00
|
|
|
$form = $this->createForm(Form::class, $data, [
|
|
|
|
'mode' => 'submit',
|
|
|
|
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
|
|
|
'appSynchro' => $this->GetParameter('appSynchro'),
|
|
|
|
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
|
|
|
]);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Récupération des data du formulaire
|
|
|
|
$form->handleRequest($request);
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Sur validation
|
2022-09-23 16:14:15 +02:00
|
|
|
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
|
|
|
$data = $form->getData();
|
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Sauvegarde
|
|
|
|
$em->getManager()->persist($data);
|
|
|
|
$em->getManager()->flush();
|
|
|
|
|
|
|
|
// Retour à la liste
|
|
|
|
return $this->redirectToRoute($this->route);
|
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Affichage du formulaire
|
|
|
|
return $this->render($this->twig.'edit.html.twig', [
|
2022-09-23 16:14:15 +02:00
|
|
|
'useheader' => true,
|
|
|
|
'usemenu' => false,
|
|
|
|
'usesidebar' => true,
|
|
|
|
'mode' => 'submit',
|
|
|
|
'form' => $form->createView(),
|
|
|
|
$this->data => $data,
|
|
|
|
'access' => $access,
|
2022-07-21 16:15:47 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function update($id, $access, Request $request, ManagerRegistry $em): Response
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Initialisation de l'enregistrement
|
2022-09-23 16:14:15 +02:00
|
|
|
$data = $em->getRepository($this->entity)->find($id);
|
|
|
|
if (!$data) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Création du formulaire
|
2022-09-23 16:14:15 +02:00
|
|
|
$form = $this->createForm(Form::class, $data, [
|
|
|
|
'mode' => 'update',
|
|
|
|
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
|
|
|
'appSynchro' => $this->GetParameter('appSynchro'),
|
|
|
|
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
|
|
|
]);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Récupération des data du formulaire
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
// Sur validation
|
2022-09-23 16:14:15 +02:00
|
|
|
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
|
|
|
$data = $form->getData();
|
2022-07-21 16:15:47 +02:00
|
|
|
$em->getManager()->flush();
|
|
|
|
|
|
|
|
// Retour à la liste
|
|
|
|
return $this->redirectToRoute($this->route);
|
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Affichage du formulaire
|
|
|
|
return $this->render($this->twig.'edit.html.twig', [
|
2022-09-23 16:14:15 +02:00
|
|
|
'useheader' => true,
|
|
|
|
'usemenu' => false,
|
|
|
|
'usesidebar' => true,
|
|
|
|
$this->data => $data,
|
|
|
|
'mode' => 'update',
|
|
|
|
'form' => $form->createView(),
|
|
|
|
'access' => $access,
|
2022-07-21 16:15:47 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function delete($id, $access, Request $request, ManagerRegistry $em): Response
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Récupération de l'enregistrement courant
|
2022-09-23 16:14:15 +02:00
|
|
|
$data = $em->getRepository($this->entity)->find($id);
|
|
|
|
if (!$data) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Tentative de suppression
|
2022-09-23 16:14:15 +02:00
|
|
|
try {
|
2022-07-21 16:15:47 +02:00
|
|
|
$em->getManager()->remove($data);
|
|
|
|
$em->getManager()->flush();
|
2022-09-23 16:14:15 +02:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
|
|
|
|
|
|
|
|
return $this->redirectToRoute($this->route.'_update', ['id' => $id]);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
return $this->redirectToRoute($this->route);
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
|
|
|
}
|