fix(continuous-integration): correction php-cs-fixer
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
This commit is contained in:
@ -2,118 +2,121 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use App\Entity\Whitelist as Entity;
|
||||
use App\Form\WhitelistType as Form;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class WhitelistController extends AbstractController
|
||||
{
|
||||
private $data="whitelist";
|
||||
private $entity="App\Entity\Whitelist";
|
||||
private $twig="Whitelist/";
|
||||
private $route="app_admin_whitelist";
|
||||
private $data = 'whitelist';
|
||||
private $entity = "App\Entity\Whitelist";
|
||||
private $twig = 'Whitelist/';
|
||||
private $route = 'app_admin_whitelist';
|
||||
|
||||
public function list($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"access"=>$access,
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
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'];
|
||||
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'];
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity,'entity')->getQuery()->getSingleScalarResult();
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if(!$search||$search["value"]=="")
|
||||
if (!$search || '' == $search['value']) {
|
||||
$totalf = $total;
|
||||
else {
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->where('entity.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('entity')->from($this->entity,'entity');
|
||||
if($search&&$search["value"]!="") {
|
||||
$qb ->andWhere('entity.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
$qb->select('entity')->from($this->entity, 'entity');
|
||||
if ($search && '' != $search['value']) {
|
||||
$qb->andWhere('entity.label LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
|
||||
if($ordercolumn) {
|
||||
switch($ordercolumn) {
|
||||
case 1 :
|
||||
$qb->orderBy('entity.label',$orderdir);
|
||||
break;
|
||||
if ($ordercolumn) {
|
||||
switch ($ordercolumn) {
|
||||
case 1:
|
||||
$qb->orderBy('entity.label', $orderdir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach($datas as $data) {
|
||||
foreach ($datas as $data) {
|
||||
// Action
|
||||
$action = "";
|
||||
$action.="<a href='".$this->generateUrl($this->route.'_update', array('id'=>$data->getId()))."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
$action = '';
|
||||
$action .= "<a href='".$this->generateUrl($this->route.'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
|
||||
$tmp=array();
|
||||
array_push($tmp,$action);
|
||||
array_push($tmp,$data->getLabel());
|
||||
$tmp = [];
|
||||
array_push($tmp, $action);
|
||||
array_push($tmp, $data->getLabel());
|
||||
|
||||
if($this->getParameter("appMasteridentity")=="LDAP"||$this->getParameter("appSynchro")=="LDAP2NINE") array_push($tmp,$data->getLdapfilter());
|
||||
if($this->getParameter("appMasteridentity")=="SSO") array_push($tmp,$data->getAttributes());
|
||||
if ('LDAP' == $this->getParameter('appMasteridentity') || 'LDAP2NINE' == $this->getParameter('appSynchro')) {
|
||||
array_push($tmp, $data->getLdapfilter());
|
||||
}
|
||||
if ('SSO' == $this->getParameter('appMasteridentity')) {
|
||||
array_push($tmp, $data->getAttributes());
|
||||
}
|
||||
|
||||
array_push($output["data"],$tmp);
|
||||
array_push($output['data'], $tmp);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
}
|
||||
|
||||
public function submit($access,Request $request,ManagerRegistry $em): Response
|
||||
public function submit($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data = new Entity();
|
||||
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
$form = $this->createForm(Form::class, $data, ['mode' => 'submit']);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->persist($data);
|
||||
$em->getManager()->flush();
|
||||
@ -121,82 +124,87 @@ class WhitelistController extends AbstractController
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"mode"=>"submit",
|
||||
"form"=>$form->createView(),
|
||||
$this->data=>$data,
|
||||
"access"=>$access,
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
$this->data => $data,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function update($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
$form = $this->createForm(Form::class, $data, ['mode' => 'update']);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
"access"=>$access,
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function delete($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Tentative de suppression
|
||||
try{
|
||||
try {
|
||||
$em->getManager()->remove($data);
|
||||
$em->getManager()->flush();
|
||||
} catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
|
||||
|
||||
return $this->redirectToRoute($this->route.'_update', ['id' => $id]);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add("error", $e->getMessage());
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute($this->route);
|
||||
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
public function is(Request $request,ManagerRegistry $em)
|
||||
public function is(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
$email=$request->request->get('email');
|
||||
$email=explode("@",$email);
|
||||
$domaine=end($email);
|
||||
$email = $request->request->get('email');
|
||||
$email = explode('@', $email);
|
||||
$domaine = end($email);
|
||||
|
||||
// Rechercher le mail dans la liste blanche
|
||||
$whitelist=$em->getRepository($this->entity)->findOneBy(["label"=>$domaine]);
|
||||
if($whitelist)
|
||||
return new Response("OK", 200);
|
||||
else
|
||||
return new Response("KO", 200);
|
||||
}
|
||||
$whitelist = $em->getRepository($this->entity)->findOneBy(['label' => $domaine]);
|
||||
if ($whitelist) {
|
||||
return new Response('OK', 200);
|
||||
} else {
|
||||
return new Response('KO', 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user