fix(morelevel): ajout de niveau03 et niveau04
All checks were successful
Cadoles/nineskeletor/pipeline/head This commit looks good

This commit is contained in:
2022-09-27 11:52:49 +02:00
parent 89cb0433c0
commit d1431bcce4
46 changed files with 7163 additions and 3839 deletions

View File

@ -200,7 +200,9 @@ class GroupController extends AbstractController
}
// Controler les permissions
$this->cansubmit($access, $em);
if (!$this->cansubmit($access, $request)) {
throw $this->createAccessDeniedException('Permission denied');
}
// Création du formulaire
$form = $this->createForm(Form::class, $data, [
@ -363,6 +365,8 @@ class GroupController extends AbstractController
$usermodo = null;
$niveau01 = null;
$niveau02 = null;
$niveau03 = null;
$niveau04 = null;
// Nombre total d'enregistrement
$qb = $em->getManager()->createQueryBuilder();
@ -389,6 +393,8 @@ class GroupController extends AbstractController
case 'user':
$niveau01 = $this->getUser()->getNiveau01();
$niveau02 = $this->getUser()->getNiveau02();
$niveau03 = $this->getUser()->getNiveau03();
$niveau04 = $this->getUser()->getNiveau04();
$qb->select('COUNT(user)')
->from('App:User', 'user')
@ -396,13 +402,21 @@ class GroupController extends AbstractController
->setParameter('groupid', $id);
switch ($request->getSession()->get('scopeannu')) {
case 'SAME_NIVEAU01':
case 1:
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
break;
case 'SAME_NIVEAU02':
case 2:
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
break;
case 3:
$qb->andWhere('user.niveau03 = :niveau03')->setParameter('niveau02', $niveau03);
break;
case 4:
$qb->andWhere('user.niveau04 = :niveau04')->setParameter('niveau04', $niveau04);
break;
}
break;
}
@ -452,13 +466,21 @@ class GroupController extends AbstractController
->setParameter('groupid', $id);
switch ($request->getSession()->get('scopeannu')) {
case 'SAME_NIVEAU01':
case 1:
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
break;
case 'SAME_NIVEAU02':
case 2:
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
break;
case 3:
$qb->andWhere('user.niveau03 = :niveau03')->setParameter('niveau02', $niveau03);
break;
case 4:
$qb->andWhere('user.niveau04 = :niveau04')->setParameter('niveau04', $niveau04);
break;
}
$totalf = $qb->getQuery()->getSingleScalarResult();
@ -494,13 +516,21 @@ class GroupController extends AbstractController
case 'user':
$qb->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
switch ($request->getSession()->get('scopeannu')) {
case 'SAME_NIVEAU01':
case 1:
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
break;
case 'SAME_NIVEAU02':
case 2:
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
break;
case 3:
$qb->andWhere('user.niveau03 = :niveau03')->setParameter('niveau02', $niveau03);
break;
case 4:
$qb->andWhere('user.niveau04 = :niveau04')->setParameter('niveau04', $niveau04);
break;
}
break;
}
@ -805,12 +835,14 @@ class GroupController extends AbstractController
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
}
private function cansubmit($access, $em)
private function cansubmit($access, $request)
{
switch ($access) {
case 'admin': return true;
break;
case 'user': return true;
case 'modo': return false;
break;
case 'user': return $request->getSession()->get('submitgroup');
break;
}
throw $this->createAccessDeniedException('Permission denied');

View File

@ -0,0 +1,354 @@
<?php
namespace App\Controller;
use App\Entity\Niveau03 as Entity;
use App\Form\Niveau03Type as Form;
use Doctrine\Persistence\ManagerRegistry;
use Ramsey\Uuid\Uuid;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class Niveau03Controller extends AbstractController
{
private $data = 'niveau03';
private $entity = "App\Entity\Niveau03";
private $twig = 'Niveau03/';
private $route = 'app_admin_niveau03';
public function list($access): Response
{
return $this->render($this->twig.'list.html.twig', [
'useheader' => true,
'usemenu' => false,
'usesidebar' => true,
'access' => $access,
]);
}
public function tablelist($access, 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'];
$total = null;
$totalf = null;
// Nombre total d'enregistrement
switch ($access) {
case 'admin':
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
break;
case 'modo':
$total = $em->getManager()->createQueryBuilder()
->select('COUNT(entity)')
->from($this->entity, 'entity')
->from("App\Entity\UserModo", 'usermodo')
->from("App\Entity\Niveau02", 'niveau02')
->where('entity.niveau02 = niveau02.id')
->andwhere('usermodo.niveau01 = niveau02.niveau01')
->andWhere('usermodo.user = :user')
->setParameter('user', $this->getUser())
->getQuery()->getSingleScalarResult();
break;
}
// Nombre d'enregistrement filtré
if (!$search || '' == $search['value']) {
$totalf = $total;
} else {
switch ($access) {
case 'admin':
$totalf = $em->getManager()->createQueryBuilder()
->select('COUNT(entity)')
->from($this->entity, 'entity')
->from("App\Entity\Niveau01", 'niveau01')
->from("App\Entity\Niveau02", 'niveau02')
->where('entity.niveau02 = niveau02.id')
->andwhere('niveau02.niveau01=niveau01.id')
->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value')
->setParameter('value', '%'.$search['value'].'%')
->getQuery()
->getSingleScalarResult();
break;
case 'modo':
$totalf = $em->getManager()->createQueryBuilder()
->select('COUNT(entity)')
->from($this->entity, 'entity')
->from("App\Entity\Niveau01", 'niveau01')
->from("App\Entity\Niveau02", 'niveau02')
->from("App\Entity\UserModo", 'usermodo')
->where('entity.niveau02 = niveau02.id')
->andwhere('niveau02.niveau01=niveau01.id')
->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value')
->andWhere('usermodo.niveau01 = niveau01.id')
->andWhere('usermodo.user = :user')
->setParameter('value', '%'.$search['value'].'%')
->setParameter('user', $this->getUser())
->getQuery()
->getSingleScalarResult();
break;
}
}
// Construction du tableau de retour
$output = [
'draw' => $draw,
'recordsFiltered' => $totalf,
'recordsTotal' => $total,
'data' => [],
];
// Parcours des Enregistrement
$qb = $em->getManager()->createQueryBuilder();
switch ($access) {
case 'admin':
$qb->select('entity')
->from($this->entity, 'entity')
->from('App:Niveau01', 'niveau01')
->from('App:Niveau02', 'niveau02')
->where('entity.niveau02=niveau02.id')
->andwhere('niveau02.niveau01=niveau01.id');
break;
case 'modo':
$qb->select('entity')
->from($this->entity, 'entity')
->from('App:Niveau01', 'niveau01')
->from('App:Niveau02', 'niveau02')
->from("App\Entity\UserModo", 'usermodo')
->where('entity.niveau02=niveau02.id')
->andwhere('niveau02.niveau01=niveau01.id')
->andWhere('usermodo.niveau01 = niveau01.id')
->andWhere('usermodo.user = :user')
->setParameter('user', $this->getUser());
break;
}
if ($search && '' != $search['value']) {
$qb->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value')
->setParameter('value', '%'.$search['value'].'%');
}
if ($ordercolumn) {
switch ($ordercolumn) {
case 1:
$qb->orderBy('niveau01.label', $orderdir);
break;
case 2:
$qb->orderBy('niveau02.label', $orderdir);
break;
case 3:
$qb->orderBy('entity.label', $orderdir);
break;
}
}
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
foreach ($datas as $data) {
// Action
$action = '';
switch ($access) {
case 'admin':
$action .= "<a href='".$this->generateUrl($this->route.'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
break;
case 'modo':
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_modo_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
break;
}
$tmp = [];
array_push($tmp, $action);
array_push($tmp, $data->getNiveau02()->getNiveau01()->getLabel());
array_push($tmp, $data->getNiveau02()->getLabel());
array_push($tmp, $data->getLabel());
array_push($output['data'], $tmp);
}
// Retour
return new JsonResponse($output);
}
public function selectlist(Request $request, ManagerRegistry $em): Response
{
$output = [];
$page_limit = $request->query->get('page_limit');
$q = $request->query->get('q');
$niveau02id = $request->get('niveau02');
$qb = $em->getManager()->createQueryBuilder();
$qb->select('entity')
->from($this->entity, 'entity')
->where('entity.label LIKE :value')
->andwhere('entity.niveau02=:niveau02')
->setParameter('value', '%'.$q.'%')
->setParameter('niveau02', $niveau02id)
->orderBy('entity.label');
$datas = $qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
foreach ($datas as $data) {
array_push($output, ['id' => $data->getId(), 'text' => $data->getLabel()]);
}
$ret_string['results'] = $output;
$response = new Response(json_encode($ret_string));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
public function submit($access, Request $request, ManagerRegistry $em): Response
{
// Initialisation de l'enregistrement
$data = new Entity();
$data->setApikey(Uuid::uuid4());
// Controler les permissions
$this->cansubmit($access, $em);
// Création du formulaire
$form = $this->createForm(Form::class, $data, [
'mode' => 'submit',
'access' => $access,
'userid' => $this->getUser()->getId(),
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
'appNiveau03label' => $this->GetParameter('appNiveau03label'),
]);
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
// Sauvegarde
$em->getManager()->persist($data);
$em->getManager()->flush();
// Retour à la liste
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
}
// Affichage du formulaire
return $this->render($this->twig.'edit.html.twig', [
'useheader' => true,
'usemenu' => false,
'usesidebar' => true,
'mode' => 'submit',
'access' => $access,
'form' => $form->createView(),
$this->data => $data,
]);
}
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.');
}
// Controler les permissions
$this->canupdate($access, $data, $em);
// Création du formulaire
$form = $this->createForm(Form::class, $data, [
'mode' => 'update',
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
'appNiveau03label' => $this->GetParameter('appNiveau03label'),
]);
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
$em->getManager()->flush();
// Retour à la liste
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
}
// Affichage du formulaire
return $this->render($this->twig.'edit.html.twig', [
'useheader' => true,
'usemenu' => false,
'usesidebar' => true,
$this->data => $data,
'mode' => 'update',
'access' => $access,
'form' => $form->createView(),
]);
}
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.');
}
// Controler les permissions
$this->canupdate($access, $data, $em);
// Tentative de suppression
try {
$em->getManager()->remove($data);
$em->getManager()->flush();
} catch (\Exception $e) {
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]);
}
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
}
private function cansubmit($access, $em)
{
switch ($access) {
case 'admin': return true;
break;
case 'modo': return true;
break;
}
throw $this->createAccessDeniedException('Permission denied');
}
private function canupdate($access, $entity, $em)
{
switch ($access) {
case 'admin': return true;
break;
case 'modo':
$usermodo = $em->getRepository("App\Entity\UserModo")->findOneBy(['user' => $this->getUser(), 'niveau01' => $entity->getNiveau02()->getNiveau01()]);
if (!$usermodo) {
throw $this->createAccessDeniedException('Permission denied');
}
return true;
break;
}
throw $this->createAccessDeniedException('Permission denied');
}
}

View File

@ -0,0 +1,371 @@
<?php
namespace App\Controller;
use App\Entity\Niveau04 as Entity;
use App\Form\Niveau04Type as Form;
use Doctrine\Persistence\ManagerRegistry;
use Ramsey\Uuid\Uuid;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class Niveau04Controller extends AbstractController
{
private $data = 'niveau04';
private $entity = "App\Entity\Niveau04";
private $twig = 'Niveau04/';
private $route = 'app_admin_niveau04';
public function list($access): Response
{
return $this->render($this->twig.'list.html.twig', [
'useheader' => true,
'usemenu' => false,
'usesidebar' => true,
'access' => $access,
]);
}
public function tablelist($access, 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'];
$total = null;
$totalf = null;
// Nombre total d'enregistrement
switch ($access) {
case 'admin':
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
break;
case 'modo':
$total = $em->getManager()->createQueryBuilder()
->select('COUNT(entity)')
->from($this->entity, 'entity')
->from("App\Entity\UserModo", 'usermodo')
->from("App\Entity\Niveau02", 'niveau02')
->from("App\Entity\Niveau03", 'niveau03')
->where('entity.niveau03 = niveau03.id')
->andWhere('niveau03.niveau02=niveau02.id')
->andwhere('usermodo.niveau01 = niveau02.niveau01')
->andWhere('usermodo.user = :user')
->setParameter('user', $this->getUser())
->getQuery()->getSingleScalarResult();
break;
}
// Nombre d'enregistrement filtré
if (!$search || '' == $search['value']) {
$totalf = $total;
} else {
switch ($access) {
case 'admin':
$totalf = $em->getManager()->createQueryBuilder()
->select('COUNT(entity)')
->from($this->entity, 'entity')
->from("App\Entity\Niveau01", 'niveau01')
->from("App\Entity\Niveau02", 'niveau02')
->from("App\Entity\Niveau03", 'niveau03')
->where('entity.niveau03 = niveau03.id')
->andWhere('niveau03.niveau02=niveau02.id')
->andwhere('niveau02.niveau01=niveau01.id')
->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value OR niveau03.label LIKE :value')
->setParameter('value', '%'.$search['value'].'%')
->getQuery()
->getSingleScalarResult();
break;
case 'modo':
$totalf = $em->getManager()->createQueryBuilder()
->select('COUNT(entity)')
->from($this->entity, 'entity')
->from("App\Entity\Niveau01", 'niveau01')
->from("App\Entity\Niveau02", 'niveau02')
->from("App\Entity\Niveau03", 'niveau03')
->from("App\Entity\UserModo", 'usermodo')
->where('entity.niveau03 = niveau03.id')
->andWhere('niveau03.niveau02=niveau02.id')
->andwhere('niveau02.niveau01=niveau01.id')
->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value OR niveau03.label LIKE :value')
->andWhere('usermodo.niveau01 = niveau01.id')
->andWhere('usermodo.user = :user')
->setParameter('value', '%'.$search['value'].'%')
->setParameter('user', $this->getUser())
->getQuery()
->getSingleScalarResult();
break;
}
}
// Construction du tableau de retour
$output = [
'draw' => $draw,
'recordsFiltered' => $totalf,
'recordsTotal' => $total,
'data' => [],
];
// Parcours des Enregistrement
$qb = $em->getManager()->createQueryBuilder();
switch ($access) {
case 'admin':
$qb->select('entity')
->from($this->entity, 'entity')
->from('App:Niveau01', 'niveau01')
->from('App:Niveau02', 'niveau02')
->from("App\Entity\Niveau03", 'niveau03')
->where('entity.niveau03 = niveau03.id')
->andWhere('niveau03.niveau02=niveau02.id')
->andwhere('niveau02.niveau01=niveau01.id');
break;
case 'modo':
$qb->select('entity')
->from($this->entity, 'entity')
->from('App:Niveau01', 'niveau01')
->from('App:Niveau02', 'niveau02')
->from("App\Entity\Niveau03", 'niveau03')
->from("App\Entity\UserModo", 'usermodo')
->where('entity.niveau03 = niveau03.id')
->andWhere('niveau03.niveau02=niveau02.id')
->andwhere('niveau02.niveau01=niveau01.id')
->andWhere('usermodo.niveau01 = niveau01.id')
->andWhere('usermodo.user = :user')
->setParameter('user', $this->getUser());
break;
}
if ($search && '' != $search['value']) {
$qb->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value OR niveau03.label LIKE :value')
->setParameter('value', '%'.$search['value'].'%');
}
if ($ordercolumn) {
switch ($ordercolumn) {
case 1:
$qb->orderBy('niveau01.label', $orderdir);
break;
case 2:
$qb->orderBy('niveau02.label', $orderdir);
break;
case 3:
$qb->orderBy('niveau03.label', $orderdir);
break;
case 4:
$qb->orderBy('entity.label', $orderdir);
break;
}
}
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
foreach ($datas as $data) {
// Action
$action = '';
switch ($access) {
case 'admin':
$action .= "<a href='".$this->generateUrl($this->route.'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
break;
case 'modo':
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_modo_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
break;
}
$tmp = [];
array_push($tmp, $action);
array_push($tmp, $data->getNiveau03()->getNiveau02()->getNiveau01()->getLabel());
array_push($tmp, $data->getNiveau03()->getNiveau02()->getLabel());
array_push($tmp, $data->getNiveau03()->getLabel());
array_push($tmp, $data->getLabel());
array_push($output['data'], $tmp);
}
// Retour
return new JsonResponse($output);
}
public function selectlist(Request $request, ManagerRegistry $em): Response
{
$output = [];
$page_limit = $request->query->get('page_limit');
$q = $request->query->get('q');
$niveau03id = $request->get('niveau03');
$qb = $em->getManager()->createQueryBuilder();
$qb->select('entity')
->from($this->entity, 'entity')
->where('entity.label LIKE :value')
->andwhere('entity.niveau03=:niveau03')
->setParameter('value', '%'.$q.'%')
->setParameter('niveau03', $niveau03id)
->orderBy('entity.label');
$datas = $qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
foreach ($datas as $data) {
array_push($output, ['id' => $data->getId(), 'text' => $data->getLabel()]);
}
$ret_string['results'] = $output;
$response = new Response(json_encode($ret_string));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
public function submit($access, Request $request, ManagerRegistry $em): Response
{
// Initialisation de l'enregistrement
$data = new Entity();
$data->setApikey(Uuid::uuid4());
// Controler les permissions
$this->cansubmit($access, $em);
// Création du formulaire
$form = $this->createForm(Form::class, $data, [
'mode' => 'submit',
'access' => $access,
'userid' => $this->getUser()->getId(),
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
'appNiveau03label' => $this->GetParameter('appNiveau03label'),
'appNiveau04label' => $this->GetParameter('appNiveau04label'),
]);
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
// Sauvegarde
$em->getManager()->persist($data);
$em->getManager()->flush();
// Retour à la liste
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
}
// Affichage du formulaire
return $this->render($this->twig.'edit.html.twig', [
'useheader' => true,
'usemenu' => false,
'usesidebar' => true,
'mode' => 'submit',
'access' => $access,
'form' => $form->createView(),
$this->data => $data,
]);
}
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.');
}
// Controler les permissions
$this->canupdate($access, $data, $em);
// Création du formulaire
$form = $this->createForm(Form::class, $data, [
'mode' => 'update',
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
'appNiveau03label' => $this->GetParameter('appNiveau03label'),
'appNiveau04label' => $this->GetParameter('appNiveau04label'),
]);
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
$em->getManager()->flush();
// Retour à la liste
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
}
// Affichage du formulaire
return $this->render($this->twig.'edit.html.twig', [
'useheader' => true,
'usemenu' => false,
'usesidebar' => true,
$this->data => $data,
'mode' => 'update',
'access' => $access,
'form' => $form->createView(),
]);
}
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.');
}
// Controler les permissions
$this->canupdate($access, $data, $em);
// Tentative de suppression
try {
$em->getManager()->remove($data);
$em->getManager()->flush();
} catch (\Exception $e) {
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]);
}
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
}
private function cansubmit($access, $em)
{
switch ($access) {
case 'admin': return true;
break;
case 'modo': return true;
break;
}
throw $this->createAccessDeniedException('Permission denied');
}
private function canupdate($access, $entity, $em)
{
switch ($access) {
case 'admin': return true;
break;
case 'modo':
$usermodo = $em->getRepository("App\Entity\UserModo")->findOneBy(['user' => $this->getUser(), 'niveau01' => $entity->getNiveau03()->getNiveau02()->getNiveau01()]);
if (!$usermodo) {
throw $this->createAccessDeniedException('Permission denied');
}
return true;
break;
}
throw $this->createAccessDeniedException('Permission denied');
}
}

View File

@ -138,11 +138,11 @@ class RegistrationController extends AbstractController
$qb->orderBy('entity.label', $orderdir);
break;
case 4:
case 7:
$qb->orderBy('entity.statut', $orderdir);
break;
case 5:
case 8:
$qb->orderBy('entity.keyexpire', $orderdir);
break;
}
@ -171,6 +171,9 @@ class RegistrationController extends AbstractController
$data->getUsername(),
$data->getEmail(),
$data->getNiveau01()->getLabel(),
$data->getNiveau02() ? $data->getNiveau02()->getLabel() : '',
$data->getNiveau03() ? $data->getNiveau03()->getLabel() : '',
$data->getNiveau04() ? $data->getNiveau04()->getLabel() : '',
$statut,
is_null($data->getKeyexpire()) ? '' : $data->getKeyexpire()->format('d/m/Y H:i:s'),
]);
@ -199,7 +202,12 @@ class RegistrationController extends AbstractController
'userid' => null,
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
'appNiveau02use' => $this->GetParameter('appNiveau02use'),
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
'appNiveau03use' => $this->GetParameter('appNiveau03use'),
'appNiveau03label' => $this->GetParameter('appNiveau03label'),
'appNiveau04use' => $this->GetParameter('appNiveau04use'),
'appNiveau04label' => $this->GetParameter('appNiveau04label'),
]);
// Récupération des data du formulaire
@ -383,7 +391,12 @@ class RegistrationController extends AbstractController
'userid' => $this->getUser()->getId(),
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
'appNiveau02use' => $this->GetParameter('appNiveau02use'),
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
'appNiveau03use' => $this->GetParameter('appNiveau03use'),
'appNiveau03label' => $this->GetParameter('appNiveau03label'),
'appNiveau04use' => $this->GetParameter('appNiveau04use'),
'appNiveau04label' => $this->GetParameter('appNiveau04label'),
]);
// Récupération des data du formulaire
@ -499,6 +512,8 @@ class RegistrationController extends AbstractController
$user->setNiveau01($data->getNiveau01());
$user->setNiveau02($data->getNiveau02());
$user->setNiveau03($data->getNiveau03());
$user->setNiveau04($data->getNiveau04());
$user->setTelephonenumber($data->getTelephonenumber());
$user->setPostaladress($data->getPostaladress());

View File

@ -283,6 +283,186 @@ class RestController extends AbstractFOSRestController
return $this->handleView($view);
}
/**
* getAllNiveau03s.
*
* @FOSRest\Get("/rest/getAllNiveau03s")
* @OA\Response(
* response=200,
* description="get all niveau03"
* )
* )
* @OA\Parameter(
* name="key",
* in="header",
* required=true,
* description="APIKey",
* @OA\Schema(type="string")
* )
*/
public function getAllNiveau03s(Request $request, ManagerRegistry $em)
{
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Récupération des parametres
if (!$this->iskey($request->headers->get('key'))) {
$view = $this->view('API Key inconnue', 403);
return $this->handleView($view);
}
$output = [];
$niveau03s = $em->getRepository("App\Entity\Niveau03")->findAll();
foreach ($niveau03s as $niveau03) {
array_push($output, $this->niveau03Format($niveau03, true));
}
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* getOneNiveau03.
*
* @FOSRest\Get("/rest/getOneNiveau03")
* @OA\Response(
* response=200,
* description="get one niveau03 by label"
* )
* )
* @OA\Parameter(
* name="key",
* in="header",
* required=true,
* description="APIKey",
* @OA\Schema(type="string")
* )
* @OA\Parameter(
* name="label",
* in="header",
* required=true,
* description="Label",
* @OA\Schema(type="string")
* )
*/
public function getOneNiveau03(Request $request, ManagerRegistry $em)
{
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Récupération des parametres
if (!$this->iskey($request->headers->get('key'))) {
$view = $this->view('API Key inconnue', 403);
return $this->handleView($view);
}
$output = [];
$niveau03 = $em->getRepository("App\Entity\Niveau03")->findOneBy(['label' => $request->headers->get('label')]);
if (!$niveau03) {
$view = $this->view('Niveau03 inconnu', 403);
return $this->handleView($view);
}
$output = $this->niveau03Format($niveau03, true);
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* getAllNiveau04s.
*
* @FOSRest\Get("/rest/getAllNiveau04s")
* @OA\Response(
* response=200,
* description="get all niveau04"
* )
* )
* @OA\Parameter(
* name="key",
* in="header",
* required=true,
* description="APIKey",
* @OA\Schema(type="string")
* )
*/
public function getAllNiveau04s(Request $request, ManagerRegistry $em)
{
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Récupération des parametres
if (!$this->iskey($request->headers->get('key'))) {
$view = $this->view('API Key inconnue', 403);
return $this->handleView($view);
}
$output = [];
$niveau04s = $em->getRepository("App\Entity\Niveau04")->findAll();
foreach ($niveau04s as $niveau04) {
array_push($output, $this->niveau04Format($niveau04, true));
}
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* getOneNiveau04.
*
* @FOSRest\Get("/rest/getOneNiveau04")
* @OA\Response(
* response=200,
* description="get one niveau04 by label"
* )
* )
* @OA\Parameter(
* name="key",
* in="header",
* required=true,
* description="APIKey",
* @OA\Schema(type="string")
* )
* @OA\Parameter(
* name="label",
* in="header",
* required=true,
* description="Label",
* @OA\Schema(type="string")
* )
*/
public function getOneNiveau04(Request $request, ManagerRegistry $em)
{
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Récupération des parametres
if (!$this->iskey($request->headers->get('key'))) {
$view = $this->view('API Key inconnue', 403);
return $this->handleView($view);
}
$output = [];
$niveau04 = $em->getRepository("App\Entity\Niveau04")->findOneBy(['label' => $request->headers->get('label')]);
if (!$niveau04) {
$view = $this->view('Niveau04 inconnu', 403);
return $this->handleView($view);
}
$output = $this->niveau04Format($niveau04, true);
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* getAllGroups.
*
@ -397,6 +577,8 @@ class RestController extends AbstractFOSRestController
$output['useravatar'] = 'https://'.str_replace('//', '/', $this->getParameter('appWeburl').$this->getParameter('appAlias').$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$user->getAvatar()], true));
$output['userniveau01'] = $this->niveau01Format($user->getNiveau01());
$output['userniveau02'] = $this->niveau02Format($user->getNiveau02());
$output['userniveau03'] = $this->niveau03Format($user->getNiveau03());
$output['userniveau04'] = $this->niveau03Format($user->getNiveau04());
$output['usergroups'] = [];
foreach ($user->getGroups() as $usergroup) {
$groupFormat = $this->groupFormat($usergroup->getGroup());
@ -456,6 +638,55 @@ class RestController extends AbstractFOSRestController
return $output;
}
private function niveau03Format($niveau03, $withmembers = false)
{
if (!$niveau03) {
return null;
}
$output = [];
$output['niveau03id'] = $niveau03->getId();
$output['niveau03label'] = $niveau03->getLabel();
if ($withmembers) {
$output['niveau03niveau01'] = $this->niveau01Format($niveau03->getNiveau02()->getNiveau01());
$output['niveau03niveau02'] = $this->niveau02Format($niveau03->getNiveau02());
$output['niveau03users'] = [];
foreach ($niveau03->getUsers() as $user) {
array_push($output['niveau03users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]);
}
if (empty($output['niveau03users'])) {
$output['niveau03users'] = null;
}
}
return $output;
}
private function niveau04Format($niveau04, $withmembers = false)
{
if (!$niveau04) {
return null;
}
$output = [];
$output['niveau04id'] = $niveau04->getId();
$output['niveau04label'] = $niveau04->getLabel();
if ($withmembers) {
$output['niveau04niveau01'] = $this->niveau01Format($niveau04->getNiveau03()->getNiveau02()->getNiveau01());
$output['niveau04niveau02'] = $this->niveau02Format($niveau04->getNiveau03()->getNiveau02());
$output['niveau04niveau03'] = $this->niveau02Format($niveau04->getNiveau03());
$output['niveau04users'] = [];
foreach ($niveau04->getUsers() as $user) {
array_push($output['niveau04users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]);
}
if (empty($output['niveau04users'])) {
$output['niveau04users'] = null;
}
}
return $output;
}
private function groupFormat($group, $withmembers = false)
{
if (!$group || $group->getId() < 0) {

View File

@ -45,6 +45,8 @@ class UserController extends AbstractController
$orderdir = $query['order'][0]['dir'];
$niveau01 = null;
$niveau02 = null;
$niveau03 = null;
$niveau04 = null;
// Nombre total d'enregistrement
switch ($access) {
@ -66,16 +68,26 @@ class UserController extends AbstractController
default:
$niveau01 = $this->getUser()->getNiveau01();
$niveau02 = $this->getUser()->getNiveau02();
$niveau03 = $this->getUser()->getNiveau03();
$niveau04 = $this->getUser()->getNiveau04();
$qb = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->where('entity.isvisible=true');
switch ($request->getSession()->get('scopeannu')) {
case 'SAME_NIVEAU01':
case 1:
$qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
break;
case 'SAME_NIVEAU02':
case 2:
$qb->andWhere('entity.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
break;
case 3:
$qb->andWhere('entity.niveau03 = :niveau03')->setParameter('niveau03', $niveau03);
break;
case 4:
$qb->andWhere('entity.niveau04 = :niveau04')->setParameter('niveau04', $niveau04);
break;
}
$total = $qb->getQuery()->getSingleScalarResult();
@ -126,13 +138,21 @@ class UserController extends AbstractController
->setParameter('value', '%'.$search['value'].'%');
switch ($request->getSession()->get('scopeannu')) {
case 'SAME_NIVEAU01':
case 1:
$qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
break;
case 'SAME_NIVEAU02':
case 2:
$qb->andWhere('entity.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
break;
case 3:
$qb->andWhere('entity.niveau03 = :niveau03')->setParameter('niveau03', $niveau03);
break;
case 4:
$qb->andWhere('entity.niveau04 = :niveau04')->setParameter('niveau04', $niveau04);
break;
}
$totalf = $qb->getQuery()->getSingleScalarResult();
@ -170,13 +190,21 @@ class UserController extends AbstractController
$qb->andWhere('entity.isvisible=true');
switch ($request->getSession()->get('scopeannu')) {
case 'SAME_NIVEAU01':
case 1:
$qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
break;
case 'SAME_NIVEAU02':
case 2:
$qb->andWhere('entity.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
break;
case 3:
$qb->andWhere('entity.niveau03 = :niveau03')->setParameter('niveau03', $niveau03);
break;
case 4:
$qb->andWhere('entity.niveau04 = :niveau04')->setParameter('niveau04', $niveau04);
break;
}
break;
}
@ -266,6 +294,8 @@ class UserController extends AbstractController
array_push($tmp, $data->getTelephonenumber());
array_push($tmp, $data->getNiveau01()->getLabel());
array_push($tmp, $data->getNiveau02() ? $data->getNiveau02()->getLabel() : '');
array_push($tmp, $data->getNiveau03() ? $data->getNiveau03()->getLabel() : '');
array_push($tmp, $data->getNiveau04() ? $data->getNiveau04()->getLabel() : '');
array_push($tmp, $data->getVisitedate() ? $data->getVisitedate()->format('d/m/Y H:i').'<br>nb = '.$data->getVisitecpt() : '');
array_push($tmp, $roles);
array_push($tmp, $groups);
@ -323,7 +353,13 @@ class UserController extends AbstractController
'userid' => $this->getUser()->getId(),
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
'appNiveau02use' => $this->GetParameter('appNiveau02use'),
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
'appNiveau03use' => $this->GetParameter('appNiveau03use'),
'appNiveau03label' => $this->GetParameter('appNiveau03label'),
'appNiveau04use' => $this->GetParameter('appNiveau04use'),
'appNiveau04label' => $this->GetParameter('appNiveau04label'),
'appNiveauupdatable' => $this->GetParameter('appNiveauupdatable'),
]);
// Récupération des data du formulaire
@ -436,7 +472,13 @@ class UserController extends AbstractController
'userid' => $this->getUser()->getId(),
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
'appNiveau02use' => $this->GetParameter('appNiveau02use'),
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
'appNiveau03use' => $this->GetParameter('appNiveau03use'),
'appNiveau03label' => $this->GetParameter('appNiveau03label'),
'appNiveau04use' => $this->GetParameter('appNiveau04use'),
'appNiveau04label' => $this->GetParameter('appNiveau04label'),
'appNiveauupdatable' => $this->GetParameter('appNiveauupdatable'),
]);
// Récupération des data du formulaire