fix(morelevel): ajout de niveau03 et niveau04
All checks were successful
Cadoles/nineskeletor/pipeline/head This commit looks good
All checks were successful
Cadoles/nineskeletor/pipeline/head This commit looks good
This commit is contained in:
@ -77,7 +77,10 @@ class CronCommand extends Command
|
||||
$command = $this->getApplication()->find($cron->getCommand());
|
||||
|
||||
// Réccuépration des parametres
|
||||
$jsonparameter = json_decode($cron->getJsonargument(), true);
|
||||
$jsonparameter = null;
|
||||
if ($cron->getJsonargument()) {
|
||||
$jsonparameter = json_decode($cron->getJsonargument(), true);
|
||||
}
|
||||
|
||||
// Formater la chaine de parametre
|
||||
if (!$jsonparameter) {
|
||||
|
@ -174,51 +174,6 @@ class InitCommand extends Command
|
||||
'Forcer la connexion afin de rendre votre site privé'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
200, // order
|
||||
'site', // category
|
||||
'permgroup', // id
|
||||
'Rôle créateur de groupe de travail', // title
|
||||
'', // value
|
||||
'ROLE_MASTER', // default
|
||||
'role', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
'', // grouped
|
||||
'Détermine quel rôle aura la permission de créer des groupes de travail'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
201, // order
|
||||
'site', // category
|
||||
'permannu', // id
|
||||
"Rôle accédant à l'annuaire", // title
|
||||
'', // value
|
||||
'ROLE_USER', // default
|
||||
'role', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
'', // grouped
|
||||
"Détermine quel rôle aura la permission de voir l'annuaire"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
202, // order
|
||||
'site', // category
|
||||
'scopeannu', // id
|
||||
"Scope de l'annuaire", // title
|
||||
'', // value
|
||||
'ALL', // default
|
||||
'scopeannu', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
'', // grouped
|
||||
"Détermine le scope des utilisateurs visibles dans l'annuaire par d'autres utilisateurs"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
500, // order
|
||||
'site', // category
|
||||
|
@ -29,6 +29,8 @@ class SynchroCommand extends Command
|
||||
private $synchro;
|
||||
private $synchropurgeniveau01;
|
||||
private $synchropurgeniveau02;
|
||||
private $synchropurgeniveau03;
|
||||
private $synchropurgeniveau04;
|
||||
private $synchropurgegroup;
|
||||
private $synchropurgeuser;
|
||||
private $host;
|
||||
@ -41,6 +43,8 @@ class SynchroCommand extends Command
|
||||
private $baseorganisation;
|
||||
private $baseniveau01;
|
||||
private $baseniveau02;
|
||||
private $baseniveau03;
|
||||
private $baseniveau04;
|
||||
private $basegroup;
|
||||
private $baseuser;
|
||||
private $username;
|
||||
@ -86,6 +90,8 @@ class SynchroCommand extends Command
|
||||
$this->synchro = $this->container->getParameter('appSynchro');
|
||||
$this->synchropurgeniveau01 = $this->container->getParameter('appSynchroPurgeNiveau01');
|
||||
$this->synchropurgeniveau02 = $this->container->getParameter('appSynchroPurgeNiveau02');
|
||||
$this->synchropurgeniveau03 = $this->container->getParameter('appSynchroPurgeNiveau03');
|
||||
$this->synchropurgeniveau04 = $this->container->getParameter('appSynchroPurgeNiveau04');
|
||||
$this->synchropurgegroup = $this->container->getParameter('appSynchroPurgeGroup');
|
||||
$this->synchropurgeuser = $this->container->getParameter('appSynchroPurgeUser');
|
||||
|
||||
@ -99,6 +105,8 @@ class SynchroCommand extends Command
|
||||
$this->baseorganisation = $this->container->getParameter('ldapBaseorganisation');
|
||||
$this->baseniveau01 = $this->container->getParameter('ldapBaseniveau01');
|
||||
$this->baseniveau02 = $this->container->getParameter('ldapBaseniveau02');
|
||||
$this->baseniveau03 = $this->container->getParameter('ldapBaseniveau03');
|
||||
$this->baseniveau04 = $this->container->getParameter('ldapBaseniveau04');
|
||||
$this->basegroup = $this->container->getParameter('ldapBasegroup');
|
||||
$this->baseuser = $this->container->getParameter('ldapBaseuser');
|
||||
$this->username = $this->container->getParameter('ldapUsername');
|
||||
@ -353,6 +361,8 @@ class SynchroCommand extends Command
|
||||
// Mise à jour du niveau01
|
||||
if ($niveau01 != $user->getNiveau01()) {
|
||||
$user->setNiveau02(null);
|
||||
$user->setNiveau03(null);
|
||||
$user->setNiveau04(null);
|
||||
}
|
||||
$user->setNiveau01($niveau01);
|
||||
|
||||
@ -453,6 +463,8 @@ class SynchroCommand extends Command
|
||||
$resetniveau01 = $this->em->getRepository("App\Entity\User")->find(-1);
|
||||
$user->setNiveau01($resetniveau01);
|
||||
$user->setNiveau02(null);
|
||||
$user->setNiveau03(null);
|
||||
$user->setNiveau04(null);
|
||||
}
|
||||
|
||||
$this->writeln(' > '.$niveau01->getLabel());
|
||||
@ -497,6 +509,8 @@ class SynchroCommand extends Command
|
||||
$this->writeln($this->baseorganisation);
|
||||
$this->writeln($this->baseniveau01);
|
||||
$this->writeln($this->baseniveau02);
|
||||
$this->writeln($this->baseniveau03);
|
||||
$this->writeln($this->baseniveau04);
|
||||
$this->writeln($this->basegroup);
|
||||
$this->writeln($this->baseuser);
|
||||
$this->ldap->addOrganisations();
|
||||
@ -563,6 +577,68 @@ class SynchroCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== NIVEAU04 =========================================');
|
||||
$niveau04s = $this->em->getRepository("App\Entity\Niveau04")->findAll();
|
||||
$attributes = $this->ldap->listAttributesNiveau04();
|
||||
foreach ($niveau04s as $niveau04) {
|
||||
$filter = 'gidnumber='.$niveau04->getId();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau04);
|
||||
if (empty($ldapentrys)) {
|
||||
$filter = str_replace('*', $niveau04->getLabel(), $this->filtergroup);
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau01);
|
||||
}
|
||||
|
||||
if (empty($ldapentrys)) {
|
||||
$this->writeln($niveau04->getLabel().' = SUBMIT');
|
||||
$this->ldap->addNiveau04($niveau04);
|
||||
} elseif ($this->ldap->ismodifyNiveau04($niveau04, $ldapentrys[0])) {
|
||||
$this->writeln($niveau04->getLabel().' = UPDATE');
|
||||
$this->ldap->modifyNiveau04($niveau04, $ldapentrys[0]['cn']);
|
||||
}
|
||||
}
|
||||
|
||||
$ldapentrys = $this->ldap->search($this->filtergroup, $attributes, $this->baseniveau04);
|
||||
foreach ($ldapentrys as $ldapentry) {
|
||||
$niveau04 = $this->em->getRepository("App\Entity\Niveau04")->find($ldapentry['gidnumber']);
|
||||
if (!$niveau04) {
|
||||
$this->writeln($ldapentry['cn'].' = DELETE');
|
||||
$dn = $this->ldap->getNiveau04DN($ldapentry['cn']);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== NIVEAU03 =========================================');
|
||||
$niveau03s = $this->em->getRepository("App\Entity\Niveau03")->findAll();
|
||||
$attributes = $this->ldap->listAttributesNiveau03();
|
||||
foreach ($niveau03s as $niveau03) {
|
||||
$filter = 'gidnumber='.$niveau03->getId();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau03);
|
||||
if (empty($ldapentrys)) {
|
||||
$filter = str_replace('*', $niveau03->getLabel(), $this->filtergroup);
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau01);
|
||||
}
|
||||
|
||||
if (empty($ldapentrys)) {
|
||||
$this->writeln($niveau03->getLabel().' = SUBMIT');
|
||||
$this->ldap->addNiveau03($niveau03);
|
||||
} elseif ($this->ldap->ismodifyNiveau03($niveau03, $ldapentrys[0])) {
|
||||
$this->writeln($niveau03->getLabel().' = UPDATE');
|
||||
$this->ldap->modifyNiveau03($niveau03, $ldapentrys[0]['cn']);
|
||||
}
|
||||
}
|
||||
|
||||
$ldapentrys = $this->ldap->search($this->filtergroup, $attributes, $this->baseniveau03);
|
||||
foreach ($ldapentrys as $ldapentry) {
|
||||
$niveau03 = $this->em->getRepository("App\Entity\Niveau03")->find($ldapentry['gidnumber']);
|
||||
if (!$niveau03) {
|
||||
$this->writeln($ldapentry['cn'].' = DELETE');
|
||||
$dn = $this->ldap->getNiveau03DN($ldapentry['cn']);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== NIVEAU02 =========================================');
|
||||
$niveau02s = $this->em->getRepository("App\Entity\Niveau02")->findAll();
|
||||
@ -824,6 +900,8 @@ class SynchroCommand extends Command
|
||||
// Mise à jour du niveau01
|
||||
if ($niveau01 != $user->getNiveau01()) {
|
||||
$user->setNiveau02(null);
|
||||
$user->setNiveau03(null);
|
||||
$user->setNiveau04(null);
|
||||
}
|
||||
$user->setNiveau01($niveau01);
|
||||
|
||||
@ -919,6 +997,8 @@ class SynchroCommand extends Command
|
||||
$resetniveau01 = $this->em->getRepository("App\Entity\User")->find(-1);
|
||||
$user->setNiveau01($resetniveau01);
|
||||
$user->setNiveau02(null);
|
||||
$user->setNiveau03(null);
|
||||
$user->setNiveau04(null);
|
||||
}
|
||||
|
||||
$this->writeln(' > '.$niveau01->getLabel());
|
||||
|
@ -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');
|
||||
|
354
src/Controller/Niveau03Controller.php
Normal file
354
src/Controller/Niveau03Controller.php
Normal 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');
|
||||
}
|
||||
}
|
371
src/Controller/Niveau04Controller.php
Normal file
371
src/Controller/Niveau04Controller.php
Normal 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');
|
||||
}
|
||||
}
|
@ -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());
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -43,6 +43,14 @@ class Niveau02
|
||||
*/
|
||||
private $niveau01;
|
||||
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
* @var Registration
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="Niveau03", mappedBy="niveau02", cascade={"persist"}, orphanRemoval=false)
|
||||
*/
|
||||
private $niveau03s;
|
||||
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
* @var Registration
|
||||
@ -61,6 +69,7 @@ class Niveau02
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->niveau03s = new ArrayCollection();
|
||||
$this->registrations = new ArrayCollection();
|
||||
$this->users = new ArrayCollection();
|
||||
}
|
||||
@ -106,6 +115,36 @@ class Niveau02
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Niveau03>
|
||||
*/
|
||||
public function getNiveau03s(): Collection
|
||||
{
|
||||
return $this->niveau03s;
|
||||
}
|
||||
|
||||
public function addNiveau03(Niveau03 $niveau03): self
|
||||
{
|
||||
if (!$this->niveau03s->contains($niveau03)) {
|
||||
$this->niveau03s->add($niveau03);
|
||||
$niveau03->setNiveau02($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeNiveau03(Niveau03 $niveau03): self
|
||||
{
|
||||
if ($this->niveau03s->removeElement($niveau03)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($niveau03->getNiveau02() === $this) {
|
||||
$niveau03->setNiveau02(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Registration>
|
||||
*/
|
||||
@ -117,7 +156,7 @@ class Niveau02
|
||||
public function addRegistration(Registration $registration): self
|
||||
{
|
||||
if (!$this->registrations->contains($registration)) {
|
||||
$this->registrations[] = $registration;
|
||||
$this->registrations->add($registration);
|
||||
$registration->setNiveau02($this);
|
||||
}
|
||||
|
||||
@ -147,7 +186,7 @@ class Niveau02
|
||||
public function addUser(User $user): self
|
||||
{
|
||||
if (!$this->users->contains($user)) {
|
||||
$this->users[] = $user;
|
||||
$this->users->add($user);
|
||||
$user->setNiveau02($this);
|
||||
}
|
||||
|
||||
|
223
src/Entity/Niveau03.php
Normal file
223
src/Entity/Niveau03.php
Normal file
@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Validator;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="niveau03")
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
* @ORM\Entity(repositoryClass="App\Repository\Niveau03Repository")
|
||||
*
|
||||
* @UniqueEntity(fields="label", message="Un Niveau de rang 3 existe déjà avec ce label")
|
||||
*/
|
||||
class Niveau03
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=250, unique=true)
|
||||
* @Validator\Grouplabel()
|
||||
* @Validator\Niveau02unique()
|
||||
*/
|
||||
private $label;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
private $apikey;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Niveau02", inversedBy="niveau03s")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $niveau02;
|
||||
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
* @var Registration
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="Niveau04", mappedBy="niveau03", cascade={"persist"}, orphanRemoval=false)
|
||||
*/
|
||||
private $niveau04s;
|
||||
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
* @var Registration
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="Registration", mappedBy="niveau03", cascade={"persist"}, orphanRemoval=false)
|
||||
*/
|
||||
private $registrations;
|
||||
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
* @var User
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="User", mappedBy="niveau03", cascade={"persist"}, orphanRemoval=false)
|
||||
*/
|
||||
private $users;
|
||||
|
||||
// == CODE A NE PAS REGENERER
|
||||
private $niveau01;
|
||||
|
||||
public function getNiveau01(): ?Niveau01
|
||||
{
|
||||
return $this->niveau02 ? $this->niveau02->getNiveau01() : null;
|
||||
}
|
||||
|
||||
public function setNiveau01(?Niveau01 $niveau01): self
|
||||
{
|
||||
$this->niveau01 = $niveau01;
|
||||
|
||||
return $this;
|
||||
}
|
||||
// ==
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->niveau04s = new ArrayCollection();
|
||||
$this->registrations = new ArrayCollection();
|
||||
$this->users = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getApikey(): ?string
|
||||
{
|
||||
return $this->apikey;
|
||||
}
|
||||
|
||||
public function setApikey(string $apikey): self
|
||||
{
|
||||
$this->apikey = $apikey;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNiveau02(): ?Niveau02
|
||||
{
|
||||
return $this->niveau02;
|
||||
}
|
||||
|
||||
public function setNiveau02(?Niveau02 $niveau02): self
|
||||
{
|
||||
$this->niveau02 = $niveau02;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Niveau04>
|
||||
*/
|
||||
public function getNiveau04s(): Collection
|
||||
{
|
||||
return $this->niveau04s;
|
||||
}
|
||||
|
||||
public function addNiveau04(Niveau04 $niveau04): self
|
||||
{
|
||||
if (!$this->niveau04s->contains($niveau04)) {
|
||||
$this->niveau04s->add($niveau04);
|
||||
$niveau04->setNiveau03($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeNiveau04(Niveau04 $niveau04): self
|
||||
{
|
||||
if ($this->niveau04s->removeElement($niveau04)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($niveau04->getNiveau03() === $this) {
|
||||
$niveau04->setNiveau03(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Registration>
|
||||
*/
|
||||
public function getRegistrations(): Collection
|
||||
{
|
||||
return $this->registrations;
|
||||
}
|
||||
|
||||
public function addRegistration(Registration $registration): self
|
||||
{
|
||||
if (!$this->registrations->contains($registration)) {
|
||||
$this->registrations->add($registration);
|
||||
$registration->setNiveau03($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeRegistration(Registration $registration): self
|
||||
{
|
||||
if ($this->registrations->removeElement($registration)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($registration->getNiveau03() === $this) {
|
||||
$registration->setNiveau03(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, User>
|
||||
*/
|
||||
public function getUsers(): Collection
|
||||
{
|
||||
return $this->users;
|
||||
}
|
||||
|
||||
public function addUser(User $user): self
|
||||
{
|
||||
if (!$this->users->contains($user)) {
|
||||
$this->users->add($user);
|
||||
$user->setNiveau03($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeUser(User $user): self
|
||||
{
|
||||
if ($this->users->removeElement($user)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($user->getNiveau03() === $this) {
|
||||
$user->setNiveau03(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
199
src/Entity/Niveau04.php
Normal file
199
src/Entity/Niveau04.php
Normal file
@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Validator;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="niveau04")
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
* @ORM\Entity(repositoryClass="App\Repository\Niveau04Repository")
|
||||
*
|
||||
* @UniqueEntity(fields="label", message="Un Niveau de rang 4 existe déjà avec ce label")
|
||||
*/
|
||||
class Niveau04
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=250, unique=true)
|
||||
* @Validator\Grouplabel()
|
||||
* @Validator\Niveau02unique()
|
||||
*/
|
||||
private $label;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
private $apikey;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Niveau03", inversedBy="niveau04s")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $niveau03;
|
||||
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
* @var Registration
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="Registration", mappedBy="niveau04", cascade={"persist"}, orphanRemoval=false)
|
||||
*/
|
||||
private $registrations;
|
||||
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
* @var User
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="User", mappedBy="niveau04", cascade={"persist"}, orphanRemoval=false)
|
||||
*/
|
||||
private $users;
|
||||
|
||||
// == CODE A NE PAS REGENERER
|
||||
private $niveau01;
|
||||
|
||||
public function getNiveau01(): ?Niveau01
|
||||
{
|
||||
return $this->niveau03 ? $this->niveau03->getNiveau02()->getNiveau01() : null;
|
||||
}
|
||||
|
||||
public function setNiveau01(?Niveau01 $niveau01): self
|
||||
{
|
||||
$this->niveau01 = $niveau01;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private $niveau02;
|
||||
|
||||
public function getNiveau02(): ?Niveau02
|
||||
{
|
||||
return $this->niveau03 ? $this->niveau03->getNiveau02() : null;
|
||||
}
|
||||
|
||||
public function setNiveau02(?Niveau02 $niveau02): self
|
||||
{
|
||||
$this->niveau02 = $niveau02;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// ==
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->registrations = new ArrayCollection();
|
||||
$this->users = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getApikey(): ?string
|
||||
{
|
||||
return $this->apikey;
|
||||
}
|
||||
|
||||
public function setApikey(string $apikey): self
|
||||
{
|
||||
$this->apikey = $apikey;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNiveau03(): ?Niveau03
|
||||
{
|
||||
return $this->niveau03;
|
||||
}
|
||||
|
||||
public function setNiveau03(?Niveau03 $niveau03): self
|
||||
{
|
||||
$this->niveau03 = $niveau03;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Registration>
|
||||
*/
|
||||
public function getRegistrations(): Collection
|
||||
{
|
||||
return $this->registrations;
|
||||
}
|
||||
|
||||
public function addRegistration(Registration $registration): self
|
||||
{
|
||||
if (!$this->registrations->contains($registration)) {
|
||||
$this->registrations->add($registration);
|
||||
$registration->setNiveau04($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeRegistration(Registration $registration): self
|
||||
{
|
||||
if ($this->registrations->removeElement($registration)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($registration->getNiveau04() === $this) {
|
||||
$registration->setNiveau04(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, User>
|
||||
*/
|
||||
public function getUsers(): Collection
|
||||
{
|
||||
return $this->users;
|
||||
}
|
||||
|
||||
public function addUser(User $user): self
|
||||
{
|
||||
if (!$this->users->contains($user)) {
|
||||
$this->users->add($user);
|
||||
$user->setNiveau04($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeUser(User $user): self
|
||||
{
|
||||
if ($this->users->removeElement($user)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($user->getNiveau04() === $this) {
|
||||
$user->setNiveau04(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -122,6 +122,16 @@ class Registration implements UserInterface, LegacyPasswordAuthenticatedUserInte
|
||||
*/
|
||||
private $niveau02;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Niveau03", inversedBy="registrations")
|
||||
*/
|
||||
private $niveau03;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Niveau04", inversedBy="registrations")
|
||||
*/
|
||||
private $niveau04;
|
||||
|
||||
// == CODE A NE PAS REGENERER
|
||||
private $roles;
|
||||
|
||||
@ -410,4 +420,28 @@ class Registration implements UserInterface, LegacyPasswordAuthenticatedUserInte
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNiveau03(): ?Niveau03
|
||||
{
|
||||
return $this->niveau03;
|
||||
}
|
||||
|
||||
public function setNiveau03(?Niveau03 $niveau03): self
|
||||
{
|
||||
$this->niveau03 = $niveau03;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNiveau04(): ?Niveau04
|
||||
{
|
||||
return $this->niveau04;
|
||||
}
|
||||
|
||||
public function setNiveau04(?Niveau04 $niveau04): self
|
||||
{
|
||||
$this->niveau04 = $niveau04;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +152,16 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
|
||||
*/
|
||||
private $niveau02;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Niveau03", inversedBy="users")
|
||||
*/
|
||||
private $niveau03;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Niveau04", inversedBy="users")
|
||||
*/
|
||||
private $niveau04;
|
||||
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
* @var UserGroup
|
||||
@ -621,4 +631,28 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNiveau03(): ?Niveau03
|
||||
{
|
||||
return $this->niveau03;
|
||||
}
|
||||
|
||||
public function setNiveau03(?Niveau03 $niveau03): self
|
||||
{
|
||||
$this->niveau03 = $niveau03;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNiveau04(): ?Niveau04
|
||||
{
|
||||
return $this->niveau04;
|
||||
}
|
||||
|
||||
public function setNiveau04(?Niveau04 $niveau04): self
|
||||
{
|
||||
$this->niveau04 = $niveau04;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,11 @@ class Niveau02Subscriber implements EventSubscriberInterface
|
||||
return;
|
||||
}
|
||||
|
||||
// Impossible de supprimer si présence de niveau03 rattaché
|
||||
if (!$this->entity->getNiveau03s()->isEmpty()) {
|
||||
throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des niveaux de rang 03');
|
||||
}
|
||||
|
||||
// Impossible de supprimer si présence de registration rattaché
|
||||
if (!$this->entity->getRegistrations()->isEmpty()) {
|
||||
throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des inscriptions');
|
||||
|
128
src/EventListener/Niveau03Subscriber.php
Normal file
128
src/EventListener/Niveau03Subscriber.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Entity\Niveau03 as Entity;
|
||||
use App\Service\LdapService;
|
||||
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
|
||||
class Niveau03Subscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $em;
|
||||
private $entity;
|
||||
private $ldap;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, LdapService $ldap)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ldap = $ldap;
|
||||
}
|
||||
|
||||
public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
Events::postPersist,
|
||||
Events::preUpdate,
|
||||
Events::postUpdate,
|
||||
Events::preRemove,
|
||||
Events::postRemove,
|
||||
];
|
||||
}
|
||||
|
||||
public function postPersist(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
}
|
||||
|
||||
public function preUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function postUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Impossible de supprimer si présence de niveau04 rattaché
|
||||
if (!$this->entity->getNiveau04s()->isEmpty()) {
|
||||
throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des niveaux de rang 04');
|
||||
}
|
||||
|
||||
// Impossible de supprimer si présence de registration rattaché
|
||||
if (!$this->entity->getRegistrations()->isEmpty()) {
|
||||
throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des inscriptions');
|
||||
}
|
||||
|
||||
// Impossible de supprimer si présence de user rattaché
|
||||
if (!$this->entity->getUsers()->isEmpty()) {
|
||||
throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des utilisateurs');
|
||||
}
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldapremove();
|
||||
}
|
||||
|
||||
public function postRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private function nine2ldap()
|
||||
{
|
||||
if ($this->ldap->isNine2Ldap()) {
|
||||
// On s'assure que la structure organisationnelle est présente
|
||||
$this->ldap->addOrganisations();
|
||||
|
||||
// Ajout / Modification dans annuaire
|
||||
$filter = 'gidnumber='.$this->entity->getId();
|
||||
$attributes = $this->ldap->listAttributesNiveau03();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau03'));
|
||||
if (empty($ldapentrys)) {
|
||||
$this->ldap->addNiveau03($this->entity);
|
||||
} elseif ($this->ldap->ismodifyNiveau03($this->entity, $ldapentrys[0])) {
|
||||
$this->ldap->modifyNiveau03($this->entity, $ldapentrys[0]['cn']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function nine2ldapremove()
|
||||
{
|
||||
if ($this->ldap->isNine2Ldap()) {
|
||||
$filter = 'gidnumber='.$this->entity->getId();
|
||||
$attributes = $this->ldap->listAttributesNiveau03();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau03'));
|
||||
if (!empty($ldapentrys)) {
|
||||
$this->ldap->deleteNiveau03($this->entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
123
src/EventListener/Niveau04Subscriber.php
Normal file
123
src/EventListener/Niveau04Subscriber.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Entity\Niveau04 as Entity;
|
||||
use App\Service\LdapService;
|
||||
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
|
||||
class Niveau04Subscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $em;
|
||||
private $entity;
|
||||
private $ldap;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, LdapService $ldap)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ldap = $ldap;
|
||||
}
|
||||
|
||||
public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
Events::postPersist,
|
||||
Events::preUpdate,
|
||||
Events::postUpdate,
|
||||
Events::preRemove,
|
||||
Events::postRemove,
|
||||
];
|
||||
}
|
||||
|
||||
public function postPersist(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
}
|
||||
|
||||
public function preUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function postUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Impossible de supprimer si présence de registration rattaché
|
||||
if (!$this->entity->getRegistrations()->isEmpty()) {
|
||||
throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des inscriptions');
|
||||
}
|
||||
|
||||
// Impossible de supprimer si présence de user rattaché
|
||||
if (!$this->entity->getUsers()->isEmpty()) {
|
||||
throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des utilisateurs');
|
||||
}
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldapremove();
|
||||
}
|
||||
|
||||
public function postRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private function nine2ldap()
|
||||
{
|
||||
if ($this->ldap->isNine2Ldap()) {
|
||||
// On s'assure que la structure organisationnelle est présente
|
||||
$this->ldap->addOrganisations();
|
||||
|
||||
// Ajout / Modification dans annuaire
|
||||
$filter = 'gidnumber='.$this->entity->getId();
|
||||
$attributes = $this->ldap->listAttributesNiveau04();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau04'));
|
||||
if (empty($ldapentrys)) {
|
||||
$this->ldap->addNiveau04($this->entity);
|
||||
} elseif ($this->ldap->ismodifyNiveau04($this->entity, $ldapentrys[0])) {
|
||||
$this->ldap->modifyNiveau04($this->entity, $ldapentrys[0]['cn']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function nine2ldapremove()
|
||||
{
|
||||
if ($this->ldap->isNine2Ldap()) {
|
||||
$filter = 'gidnumber='.$this->entity->getId();
|
||||
$attributes = $this->ldap->listAttributesNiveau04();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau04'));
|
||||
if (!empty($ldapentrys)) {
|
||||
$this->ldap->deleteNiveau04($this->entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -106,7 +106,7 @@ class UserSubscriber implements EventSubscriberInterface
|
||||
|
||||
// Ajout / Modification dans annuaire
|
||||
$filter = str_replace('*', $this->entity->getUsername(), $this->ldap->getParameter('filteruser'));
|
||||
$attributes = $this->ldap->listAttributesNiveau02();
|
||||
$attributes = $this->ldap->listAttributesUser();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseuser'));
|
||||
if (empty($ldapentrys)) {
|
||||
$this->ldap->addUser($this->entity);
|
||||
@ -123,7 +123,7 @@ class UserSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
if ($this->ldap->isNine2Ldap()) {
|
||||
$filter = str_replace('*', $this->entity->getUsername(), $this->ldap->getParameter('filteruser'));
|
||||
$attributes = $this->ldap->listAttributesNiveau02();
|
||||
$attributes = $this->ldap->listAttributesUser();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseuser'));
|
||||
if (!empty($ldapentrys)) {
|
||||
$this->ldap->deleteUser($this->entity);
|
||||
|
@ -120,6 +120,7 @@ class ConfigType extends AbstractType
|
||||
'NO_BODY' => 'NO_BODY',
|
||||
'ROLE_USER' => 'ROLE_USER',
|
||||
'ROLE_MASTER' => 'ROLE_MASTER',
|
||||
'ROLE_MANAGER' => 'ROLE_MANAGER',
|
||||
'ROLE_MODO' => 'ROLE_MODO',
|
||||
];
|
||||
|
||||
@ -131,21 +132,6 @@ class ConfigType extends AbstractType
|
||||
'choices' => $choices, ]);
|
||||
break;
|
||||
|
||||
case 'scopeannu':
|
||||
$choices = [
|
||||
'ALL' => 'ALL',
|
||||
'SAME_NIVEAU01' => 'SAME_NIVEAU01',
|
||||
'SAME_NIVEAU02' => 'SAME_NIVEAU02',
|
||||
];
|
||||
|
||||
$builder->add('value', ChoiceType::class,
|
||||
['label' => 'Valeur',
|
||||
'label_attr' => ['style' => 'margin-top:15px;'],
|
||||
'attr' => ['class' => 'form-control'],
|
||||
'required' => (0 == $options['required'] ? false : true),
|
||||
'choices' => $choices, ]);
|
||||
break;
|
||||
|
||||
case 'logo':
|
||||
$builder->add('value', HiddenType::class);
|
||||
break;
|
||||
|
94
src/Form/Niveau03Type.php
Normal file
94
src/Form/Niveau03Type.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
||||
|
||||
class Niveau03Type extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
'label' => 'Valider',
|
||||
'attr' => ['class' => 'btn btn-success'],
|
||||
]
|
||||
);
|
||||
|
||||
$access = $options['access'];
|
||||
$userid = $options['userid'];
|
||||
$builder->add('niveau01',
|
||||
EntityType::class, [
|
||||
'class' => "App\Entity\Niveau01",
|
||||
'label' => $options['appNiveau01label'],
|
||||
'placeholder' => '== Choisir '.$options['appNiveau01label'].' ==',
|
||||
'choice_label' => 'label',
|
||||
'disabled' => ('submit' != $options['mode']),
|
||||
'query_builder' => function (EntityRepository $er) use ($access, $userid) {
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
return $er->createQueryBuilder('niveau01')->orderBy('niveau01.label', 'ASC');
|
||||
break;
|
||||
|
||||
case 'modo':
|
||||
$result = $er->createQueryBuilder('table')->innerJoin('App:UserModo', 'usermodo', Join::WITH, 'table.id = usermodo.niveau01')->orderBy('table.label', 'ASC');
|
||||
$result->andWhere('usermodo.user = :user');
|
||||
$result->setParameter('user', $userid);
|
||||
|
||||
return $result;
|
||||
break;
|
||||
}
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('niveau02',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau02label'],
|
||||
'required' => true,
|
||||
'disabled' => ('submit' != $options['mode']),
|
||||
'remote_route' => 'app_niveau02_selectlist',
|
||||
'class' => "App\Entity\Niveau02",
|
||||
// "req_params" => ["niveau01" => "parent.children[niveau01]"],
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==',
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('label',
|
||||
TextType::class, [
|
||||
'label' => 'Label',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'App\Entity\Niveau03',
|
||||
'mode' => 'string',
|
||||
'access' => 'string',
|
||||
'userid' => 'string',
|
||||
'appMasteridentity' => 'string',
|
||||
'appNiveau01label' => 'string',
|
||||
'appNiveau02label' => 'string',
|
||||
'appNiveau03label' => 'string',
|
||||
]);
|
||||
}
|
||||
}
|
116
src/Form/Niveau04Type.php
Normal file
116
src/Form/Niveau04Type.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
||||
|
||||
class Niveau04Type extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
'label' => 'Valider',
|
||||
'attr' => ['class' => 'btn btn-success'],
|
||||
]
|
||||
);
|
||||
|
||||
$access = $options['access'];
|
||||
$userid = $options['userid'];
|
||||
$builder->add('niveau01',
|
||||
EntityType::class, [
|
||||
'class' => "App\Entity\Niveau01",
|
||||
'label' => $options['appNiveau01label'],
|
||||
'placeholder' => '== Choisir '.$options['appNiveau01label'].' ==',
|
||||
'choice_label' => 'label',
|
||||
'disabled' => ('submit' != $options['mode']),
|
||||
'query_builder' => function (EntityRepository $er) use ($access, $userid) {
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
return $er->createQueryBuilder('niveau01')->orderBy('niveau01.label', 'ASC');
|
||||
break;
|
||||
|
||||
case 'modo':
|
||||
$result = $er->createQueryBuilder('table')->innerJoin('App:UserModo', 'usermodo', Join::WITH, 'table.id = usermodo.niveau01')->orderBy('table.label', 'ASC');
|
||||
$result->andWhere('usermodo.user = :user');
|
||||
$result->setParameter('user', $userid);
|
||||
|
||||
return $result;
|
||||
break;
|
||||
}
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('niveau02',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau02label'],
|
||||
'required' => true,
|
||||
'disabled' => ('submit' != $options['mode']),
|
||||
'remote_route' => 'app_niveau02_selectlist',
|
||||
'class' => "App\Entity\Niveau02",
|
||||
// "req_params" => ["niveau01" => "parent.children[niveau01]"],
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==',
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('niveau03',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau03label'],
|
||||
'required' => true,
|
||||
'disabled' => ('submit' != $options['mode']),
|
||||
'remote_route' => 'app_niveau03_selectlist',
|
||||
'class' => "App\Entity\Niveau03",
|
||||
// "req_params" => ["niveau01" => "parent.children[niveau01]"],
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau03label'].' ==',
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('label',
|
||||
TextType::class, [
|
||||
'label' => 'Label',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'App\Entity\Niveau04',
|
||||
'mode' => 'string',
|
||||
'access' => 'string',
|
||||
'userid' => 'string',
|
||||
'appMasteridentity' => 'string',
|
||||
'appNiveau01label' => 'string',
|
||||
'appNiveau02label' => 'string',
|
||||
'appNiveau03label' => 'string',
|
||||
'appNiveau04label' => 'string',
|
||||
]);
|
||||
}
|
||||
}
|
@ -106,26 +106,68 @@ class RegistrationType extends AbstractType
|
||||
},
|
||||
]
|
||||
);
|
||||
if ($options['appNiveau02use']) {
|
||||
$builder->add('niveau02',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau02label'],
|
||||
'required' => false,
|
||||
'remote_route' => 'app_niveau02_selectlist',
|
||||
'class' => "App\Entity\Niveau02",
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$builder->add('niveau02',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau02label'],
|
||||
'required' => false,
|
||||
'remote_route' => 'app_niveau02_selectlist',
|
||||
'class' => "App\Entity\Niveau02",
|
||||
// "req_params" => ["niveau01" => "parent.children[niveau01]"],
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==',
|
||||
]
|
||||
);
|
||||
if ($options['appNiveau03use']) {
|
||||
$builder->add('niveau03',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau03label'],
|
||||
'required' => false,
|
||||
'remote_route' => 'app_niveau03_selectlist',
|
||||
'class' => "App\Entity\Niveau03",
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau03label'].' ==',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ($options['appNiveau04use']) {
|
||||
$builder->add('niveau04',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau04label'],
|
||||
'required' => false,
|
||||
'remote_route' => 'app_niveau04_selectlist',
|
||||
'class' => "App\Entity\Niveau04",
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau04label'].' ==',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Password
|
||||
if ('submit' == $options['mode']) {
|
||||
@ -204,7 +246,12 @@ class RegistrationType extends AbstractType
|
||||
'userid' => 'string',
|
||||
'appMasteridentity' => 'string',
|
||||
'appNiveau01label' => 'string',
|
||||
'appNiveau02use' => 'string',
|
||||
'appNiveau02label' => 'string',
|
||||
'appNiveau03use' => 'string',
|
||||
'appNiveau03label' => 'string',
|
||||
'appNiveau04use' => 'string',
|
||||
'appNiveau04label' => 'string',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ class UserType extends AbstractType
|
||||
'label' => $options['appNiveau01label'],
|
||||
'placeholder' => '== Choisir '.$options['appNiveau01label'].' ==',
|
||||
'choice_label' => 'label',
|
||||
'disabled' => ('SQL' != $options['appMasteridentity'] && 'submit' != $options['mode']),
|
||||
'disabled' => (('SQL' != $options['appMasteridentity'] && 'submit' != $options['mode']) || ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 1)),
|
||||
'query_builder' => function (EntityRepository $er) use ($access, $userid) {
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
@ -105,25 +105,71 @@ class UserType extends AbstractType
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('niveau02',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau02label'],
|
||||
'required' => false,
|
||||
'remote_route' => 'app_niveau02_selectlist',
|
||||
'class' => "App\Entity\Niveau02",
|
||||
// "req_params" => ["niveau01" => "parent.children[niveau01]"],
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==',
|
||||
]
|
||||
);
|
||||
if ($options['appNiveau02use']) {
|
||||
$builder->add('niveau02',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau02label'],
|
||||
'required' => false,
|
||||
'disabled' => ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 2),
|
||||
'remote_route' => 'app_niveau02_selectlist',
|
||||
'class' => "App\Entity\Niveau02",
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ($options['appNiveau03use']) {
|
||||
$builder->add('niveau03',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau03label'],
|
||||
'required' => false,
|
||||
'disabled' => ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 3),
|
||||
'remote_route' => 'app_niveau03_selectlist',
|
||||
'class' => "App\Entity\Niveau03",
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau03label'].' ==',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ($options['appNiveau04use']) {
|
||||
$builder->add('niveau04',
|
||||
Select2EntityType::class, [
|
||||
'label' => $options['appNiveau04label'],
|
||||
'required' => false,
|
||||
'disabled' => ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 4),
|
||||
'remote_route' => 'app_niveau04_selectlist',
|
||||
'class' => "App\Entity\Niveau04",
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => '== Choisir '.$options['appNiveau04label'].' ==',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$choices = ['oui' => '1', 'non' => '0'];
|
||||
$builder->add('isvisible',
|
||||
@ -192,7 +238,7 @@ class UserType extends AbstractType
|
||||
$builder->add('linkmodos', HiddenType::class, ['mapped' => false]);
|
||||
|
||||
if ('admin' == $options['access'] || 'modo' == $options['access']) {
|
||||
$choices = ['ROLE_ADMIN' => 'ROLE_ADMIN', 'ROLE_MODO' => 'ROLE_MODO', 'ROLE_MASTER' => 'ROLE_MASTER', 'ROLE_USER' => 'ROLE_USER'];
|
||||
$choices = ['ROLE_ADMIN' => 'ROLE_ADMIN', 'ROLE_MODO' => 'ROLE_MODO', 'ROLE_MASTER' => 'ROLE_MASTER', 'ROLE_MANAGER' => 'ROLE_MANAGER', 'ROLE_USER' => 'ROLE_USER'];
|
||||
$builder->add('roles',
|
||||
ChoiceType::class, [
|
||||
'label' => 'Rôle',
|
||||
@ -222,7 +268,13 @@ class UserType extends AbstractType
|
||||
'userid' => 'string',
|
||||
'appMasteridentity' => 'string',
|
||||
'appNiveau01label' => 'string',
|
||||
'appNiveau02use' => 'string',
|
||||
'appNiveau02label' => 'string',
|
||||
'appNiveau03use' => 'string',
|
||||
'appNiveau03label' => 'string',
|
||||
'appNiveau04use' => 'string',
|
||||
'appNiveau04label' => 'string',
|
||||
'appNiveauupdatable' => 'string',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
33
src/Repository/Niveau03Repository.php
Normal file
33
src/Repository/Niveau03Repository.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Niveau03;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
class Niveau03Repository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Niveau03::class);
|
||||
}
|
||||
|
||||
public function add(Niveau03 $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(Niveau03 $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->remove($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
}
|
33
src/Repository/Niveau04Repository.php
Normal file
33
src/Repository/Niveau04Repository.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Niveau04;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
class Niveau04Repository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Niveau04::class);
|
||||
}
|
||||
|
||||
public function add(Niveau04 $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(Niveau04 $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->remove($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,165 +2,168 @@
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
|
||||
class AppSession
|
||||
class AppSession
|
||||
{
|
||||
private $container;
|
||||
protected $em;
|
||||
protected $requeststack;
|
||||
protected $token;
|
||||
|
||||
public function __construct(ContainerInterface $container, EntityManagerInterface $em, RequestStack $requeststack, TokenStorageInterface $token)
|
||||
{
|
||||
private $container;
|
||||
protected $em;
|
||||
protected $requeststack;
|
||||
protected $token;
|
||||
$this->container = $container;
|
||||
$this->requeststack = $requeststack;
|
||||
$this->em = $em;
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public function __construct(ContainerInterface $container, EntityManagerInterface $em, RequestStack $requeststack, TokenStorageInterface $token)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->requeststack = $requeststack;
|
||||
$this->em = $em;
|
||||
$this->token = $token;
|
||||
public function onDomainParse(RequestEvent $event)
|
||||
{
|
||||
$session = $this->requeststack->getSession();
|
||||
|
||||
$configs = $this->em->getRepository("App\Entity\Config")->findAll();
|
||||
foreach ($configs as $config) {
|
||||
$session->set($config->getId(), strval($config->getValue()));
|
||||
}
|
||||
$session->set('headerimage', 'header/'.$session->get('headerimage'));
|
||||
|
||||
// Calcul couleur
|
||||
$session->set('colorbgbodylight-darker', $this->adjustBrightness($session->get('colorbgbodylight'), -10));
|
||||
$session->set('colorfttitlelight-darker', $this->adjustBrightness($session->get('colorfttitlelight'), -50));
|
||||
|
||||
$session->set('colorbgbodydark-darker', $this->adjustBrightness($session->get('colorbgbodydark'), -50));
|
||||
$session->set('colorbgbodydark-lighter', $this->adjustBrightness($session->get('colorbgbodydark'), +50));
|
||||
|
||||
$session->set('colorbgbodydark-rgb', $this->hexToRgb($session->get('colorbgbodydark')));
|
||||
$session->set('colorbgbodydark-darkrgb', $this->hexToRgb($session->get('colorbgbodydark-darker')));
|
||||
$session->set('colorbgbodydark-lightrgb', $this->hexToRgb($session->get('colorbgbodydark-lighter')));
|
||||
|
||||
// Current user
|
||||
$token = $this->token->getToken();
|
||||
if (!$token) {
|
||||
return;
|
||||
}
|
||||
$curentuser = $token->getUser();
|
||||
|
||||
// Préférence par défaut
|
||||
$session->set('fgheader', true);
|
||||
$session->set('fgaudit', false);
|
||||
|
||||
// Préférence
|
||||
if ('anon.' != $curentuser) {
|
||||
$preference = $curentuser->getPreference();
|
||||
if (is_array($preference)) {
|
||||
// Préférence header
|
||||
if (array_key_exists('fgheader', $preference)) {
|
||||
$fgheader = ('true' == $preference['fgheader'][0]);
|
||||
$session->set('fgheader', $fgheader);
|
||||
}
|
||||
|
||||
// Préférence audit
|
||||
if (array_key_exists('fgaudit', $preference)) {
|
||||
$fgaudit = ('true' == $preference['fgaudit'][0]);
|
||||
$session->set('fgaudit', $fgaudit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function onDomainParse(RequestEvent $event)
|
||||
{
|
||||
$session = $this->requeststack->getSession();
|
||||
|
||||
$configs = $this->em->getRepository("App\Entity\Config")->findAll();
|
||||
foreach ($configs as $config) {
|
||||
$session->set($config->getId(), strval($config->getValue()));
|
||||
}
|
||||
$session->set('headerimage', 'header/'.$session->get('headerimage'));
|
||||
|
||||
// Calcul couleur
|
||||
$session->set('colorbgbodylight-darker', $this->adjustBrightness($session->get('colorbgbodylight'), -10));
|
||||
$session->set('colorfttitlelight-darker', $this->adjustBrightness($session->get('colorfttitlelight'), -50));
|
||||
|
||||
$session->set('colorbgbodydark-darker', $this->adjustBrightness($session->get('colorbgbodydark'), -50));
|
||||
$session->set('colorbgbodydark-lighter', $this->adjustBrightness($session->get('colorbgbodydark'), +50));
|
||||
|
||||
$session->set('colorbgbodydark-rgb', $this->hexToRgb($session->get('colorbgbodydark')));
|
||||
$session->set('colorbgbodydark-darkrgb', $this->hexToRgb($session->get('colorbgbodydark-darker')));
|
||||
$session->set('colorbgbodydark-lightrgb', $this->hexToRgb($session->get('colorbgbodydark-lighter')));
|
||||
|
||||
// Current user
|
||||
$token = $this->token->getToken();
|
||||
if (!$token) {
|
||||
return;
|
||||
}
|
||||
$curentuser = $token->getUser();
|
||||
|
||||
// Préférence par défaut
|
||||
$session->set('fgheader', true);
|
||||
$session->set('fgaudit', false);
|
||||
|
||||
// Préférence
|
||||
if ('anon.' != $curentuser) {
|
||||
$preference = $curentuser->getPreference();
|
||||
if (is_array($preference)) {
|
||||
// Préférence header
|
||||
if (array_key_exists('fgheader', $preference)) {
|
||||
$fgheader = ('true' == $preference['fgheader'][0]);
|
||||
$session->set('fgheader', $fgheader);
|
||||
}
|
||||
|
||||
// Préférence audit
|
||||
if (array_key_exists('fgaudit', $preference)) {
|
||||
$fgaudit = ('true' == $preference['fgaudit'][0]);
|
||||
$session->set('fgaudit', $fgaudit);
|
||||
}
|
||||
}
|
||||
// Permissions
|
||||
$showannuaire = false;
|
||||
$submitgroup = false;
|
||||
if ('anon.' != $curentuser) {
|
||||
if ($curentuser->hasRole('ROLE_ADMIN') && null != $this->container->getParameter('appAnnuscopeadmin')) {
|
||||
$showannuaire = true;
|
||||
$session->set('scopeannu', $this->container->getParameter('appAnnuscopeadmin'));
|
||||
} elseif ($curentuser->hasRole('ROLE_MODO') && null != $this->container->getParameter('appAnnuscopemodo')) {
|
||||
$showannuaire = true;
|
||||
$session->set('scopeannu', $this->container->getParameter('appAnnuscopemodo'));
|
||||
} elseif ($curentuser->hasRole('ROLE_MASTER') && null != $this->container->getParameter('appAnnuscopemaster')) {
|
||||
$showannuaire = true;
|
||||
$session->set('scopeannu', $this->container->getParameter('appAnnuscopemaster'));
|
||||
} elseif ($curentuser->hasRole('ROLE_MANAGER') && null != $this->container->getParameter('appAnnuscopemanager')) {
|
||||
$showannuaire = true;
|
||||
$session->set('scopeannu', $this->container->getParameter('appAnnuscopemanager'));
|
||||
} elseif ($curentuser->hasRole('ROLE_USER') && null != $this->container->getParameter('appAnnuscopeuser')) {
|
||||
$showannuaire = true;
|
||||
$session->set('scopeannu', $this->container->getParameter('appAnnuscopeuser'));
|
||||
}
|
||||
|
||||
// Permissions
|
||||
$showannuaire = false;
|
||||
$submitgroup = false;
|
||||
if ('anon.' != $curentuser) {
|
||||
switch ($session->get('permannu')) {
|
||||
case 'ROLE_USER':
|
||||
$showannuaire = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER') || $curentuser->hasRole('ROLE_USER'));
|
||||
break;
|
||||
|
||||
case 'ROLE_MASTER':
|
||||
$showannuaire = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER'));
|
||||
break;
|
||||
|
||||
case 'ROLE_MODO':
|
||||
$showannuaire = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO'));
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($session->get('permgroup')) {
|
||||
case 'ROLE_USER':
|
||||
$submitgroup = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER') || $curentuser->hasRole('ROLE_USER'));
|
||||
break;
|
||||
|
||||
case 'ROLE_MASTER':
|
||||
$submitgroup = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER'));
|
||||
break;
|
||||
|
||||
case 'ROLE_MODO':
|
||||
$submitgroup = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO'));
|
||||
break;
|
||||
}
|
||||
if (in_array('ALL', $this->container->getParameter('appGroupsubmiter'))) {
|
||||
$submitgroup = true;
|
||||
} elseif ($curentuser->hasRole('ROLE_ADMIN') && in_array('ROLE_ADMIN', $this->container->getParameter('appGroupsubmiter'))) {
|
||||
$submitgroup = true;
|
||||
} elseif ($curentuser->hasRole('ROLE_MODO') && in_array('ROLE_MODO', $this->container->getParameter('appGroupsubmiter'))) {
|
||||
$submitgroup = true;
|
||||
} elseif ($curentuser->hasRole('ROLE_MASTER') && in_array('ROLE_MASTER', $this->container->getParameter('appGroupsubmiter'))) {
|
||||
$submitgroup = true;
|
||||
} elseif ($curentuser->hasRole('ROLE_MANAGER') && in_array('ROLE_MANAGER', $this->container->getParameter('appGroupsubmiter'))) {
|
||||
$submitgroup = true;
|
||||
} elseif ($curentuser->hasRole('ROLE_USER') && in_array('ROLE_USER', $this->container->getParameter('appGroupsubmiter'))) {
|
||||
$submitgroup = true;
|
||||
}
|
||||
$session->set('showannuaire', $showannuaire);
|
||||
$session->set('submitgroup', $submitgroup);
|
||||
}
|
||||
$session->set('showannuaire', $showannuaire);
|
||||
$session->set('submitgroup', $submitgroup);
|
||||
|
||||
// Visite
|
||||
if ('anon.' != $curentuser) {
|
||||
$now = new \DateTime();
|
||||
if (!$curentuser->getVisitedate()) {
|
||||
// Visite
|
||||
if ('anon.' != $curentuser) {
|
||||
$now = new \DateTime();
|
||||
if (!$curentuser->getVisitedate()) {
|
||||
$curentuser->setVisitedate($now);
|
||||
$curentuser->setVisitecpt($curentuser->getVisitecpt() + 1);
|
||||
$this->em->persist($curentuser);
|
||||
$this->em->flush();
|
||||
} else {
|
||||
$visitedate = clone $curentuser->getVisitedate();
|
||||
$visitedate->add(new \DateInterval('PT1H'));
|
||||
if ($visitedate < $now) {
|
||||
$curentuser->setVisitedate($now);
|
||||
$curentuser->setVisitecpt($curentuser->getVisitecpt() + 1);
|
||||
$this->em->persist($curentuser);
|
||||
$this->em->flush();
|
||||
} else {
|
||||
$visitedate = clone $curentuser->getVisitedate();
|
||||
$visitedate->add(new \DateInterval('PT1H'));
|
||||
if ($visitedate < $now) {
|
||||
$curentuser->setVisitedate($now);
|
||||
$curentuser->setVisitecpt($curentuser->getVisitecpt() + 1);
|
||||
$this->em->persist($curentuser);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function adjustBrightness($hex, $steps)
|
||||
{
|
||||
// Steps should be between -255 and 255. Negative = darker, positive = lighter
|
||||
$steps = max(-255, min(255, $steps));
|
||||
|
||||
// Normalize into a six character long hex string
|
||||
$hex = str_replace('#', '', $hex);
|
||||
if (3 == strlen($hex)) {
|
||||
$hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2);
|
||||
}
|
||||
|
||||
// Split into three parts: R, G and B
|
||||
$color_parts = str_split($hex, 2);
|
||||
$return = '';
|
||||
|
||||
foreach ($color_parts as $color) {
|
||||
$color = hexdec($color); // Convert to decimal
|
||||
$color = max(0, min(255, $color + $steps)); // Adjust color
|
||||
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
|
||||
}
|
||||
|
||||
return '#'.$return;
|
||||
}
|
||||
|
||||
public function hexToRgb($hex)
|
||||
{
|
||||
$hex = str_replace('#', '', $hex);
|
||||
$length = strlen($hex);
|
||||
$rgb['r'] = hexdec(6 == $length ? substr($hex, 0, 2) : (3 == $length ? str_repeat(substr($hex, 0, 1), 2) : 0));
|
||||
$rgb['g'] = hexdec(6 == $length ? substr($hex, 2, 2) : (3 == $length ? str_repeat(substr($hex, 1, 1), 2) : 0));
|
||||
$rgb['b'] = hexdec(6 == $length ? substr($hex, 4, 2) : (3 == $length ? str_repeat(substr($hex, 2, 1), 2) : 0));
|
||||
|
||||
return $rgb['r'].','.$rgb['g'].','.$rgb['b'];
|
||||
}
|
||||
}
|
||||
|
||||
private function adjustBrightness($hex, $steps)
|
||||
{
|
||||
// Steps should be between -255 and 255. Negative = darker, positive = lighter
|
||||
$steps = max(-255, min(255, $steps));
|
||||
|
||||
// Normalize into a six character long hex string
|
||||
$hex = str_replace('#', '', $hex);
|
||||
if (3 == strlen($hex)) {
|
||||
$hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2);
|
||||
}
|
||||
|
||||
// Split into three parts: R, G and B
|
||||
$color_parts = str_split($hex, 2);
|
||||
$return = '';
|
||||
|
||||
foreach ($color_parts as $color) {
|
||||
$color = hexdec($color); // Convert to decimal
|
||||
$color = max(0, min(255, $color + $steps)); // Adjust color
|
||||
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
|
||||
}
|
||||
|
||||
return '#'.$return;
|
||||
}
|
||||
|
||||
public function hexToRgb($hex)
|
||||
{
|
||||
$hex = str_replace('#', '', $hex);
|
||||
$length = strlen($hex);
|
||||
$rgb['r'] = hexdec(6 == $length ? substr($hex, 0, 2) : (3 == $length ? str_repeat(substr($hex, 0, 1), 2) : 0));
|
||||
$rgb['g'] = hexdec(6 == $length ? substr($hex, 2, 2) : (3 == $length ? str_repeat(substr($hex, 1, 1), 2) : 0));
|
||||
$rgb['b'] = hexdec(6 == $length ? substr($hex, 4, 2) : (3 == $length ? str_repeat(substr($hex, 2, 1), 2) : 0));
|
||||
|
||||
return $rgb['r'].','.$rgb['g'].','.$rgb['b'];
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ namespace App\Service;
|
||||
use App\Entity\Group;
|
||||
use App\Entity\Niveau01;
|
||||
use App\Entity\Niveau02;
|
||||
use App\Entity\Niveau03;
|
||||
use App\Entity\Niveau04;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserGroup;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
@ -23,6 +25,8 @@ class LdapService
|
||||
private $baseorganisation;
|
||||
private $baseniveau01;
|
||||
private $baseniveau02;
|
||||
private $baseniveau03;
|
||||
private $baseniveau04;
|
||||
private $basegroup;
|
||||
private $baseuser;
|
||||
private $username;
|
||||
@ -55,6 +59,8 @@ class LdapService
|
||||
$this->baseorganisation = $container->getParameter('ldapBaseorganisation');
|
||||
$this->baseniveau01 = $container->getParameter('ldapBaseniveau01');
|
||||
$this->baseniveau02 = $container->getParameter('ldapBaseniveau02');
|
||||
$this->baseniveau03 = $container->getParameter('ldapBaseniveau03');
|
||||
$this->baseniveau04 = $container->getParameter('ldapBaseniveau04');
|
||||
$this->basegroup = $container->getParameter('ldapBasegroup');
|
||||
$this->baseuser = $container->getParameter('ldapBaseuser');
|
||||
$this->username = $container->getParameter('ldapUsername');
|
||||
@ -75,7 +81,7 @@ class LdapService
|
||||
|
||||
public function isNine2Ldap()
|
||||
{
|
||||
return 'SQL' == $this->appMasteridentity && 'NINE2LDAP' == $this->synchro && $this->userwriter && $this->baseorganisation && $this->baseniveau01 && $this->baseniveau02 && $this->basegroup && $this->baseuser && $this->connect();
|
||||
return ('SQL' == $this->appMasteridentity) && 'NINE2LDAP' == $this->synchro && $this->userwriter && $this->baseorganisation && $this->baseniveau01 && $this->baseniveau02 && $this->baseniveau03 && $this->baseniveau04 && $this->basegroup && $this->baseuser && $this->connect();
|
||||
}
|
||||
|
||||
public function connect()
|
||||
@ -91,7 +97,6 @@ class LdapService
|
||||
return $this->connection;
|
||||
} else {
|
||||
$ldapConn = ldap_connect($this->host, $this->port);
|
||||
|
||||
if ($ldapConn) {
|
||||
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0);
|
||||
@ -146,6 +151,10 @@ class LdapService
|
||||
break;
|
||||
case 'baseniveau02': return $this->baseniveau02;
|
||||
break;
|
||||
case 'baseniveau03': return $this->baseniveau03;
|
||||
break;
|
||||
case 'baseniveau04': return $this->baseniveau04;
|
||||
break;
|
||||
case 'basedn': return $this->basedn;
|
||||
break;
|
||||
case 'filteruser': return $this->filteruser;
|
||||
@ -279,6 +288,16 @@ class LdapService
|
||||
$this->addOrganisation($this->baseniveau02);
|
||||
}
|
||||
|
||||
$ldapentrys = $this->searchdn($this->baseniveau03, $this->baseorganisation);
|
||||
if (empty($ldapentrys)) {
|
||||
$this->addOrganisation($this->baseniveau03);
|
||||
}
|
||||
|
||||
$ldapentrys = $this->searchdn($this->baseniveau04, $this->baseorganisation);
|
||||
if (empty($ldapentrys)) {
|
||||
$this->addOrganisation($this->baseniveau04);
|
||||
}
|
||||
|
||||
$ldapentrys = $this->searchdn($this->basegroup, $this->baseorganisation);
|
||||
if (empty($ldapentrys)) {
|
||||
$this->addOrganisation($this->basegroup);
|
||||
@ -482,6 +501,78 @@ class LdapService
|
||||
}
|
||||
}
|
||||
|
||||
// NIVEAU03
|
||||
// On recherche le Niveau03 actuellement asscocié à l'utilisateur
|
||||
$criteria = '(&(cn=*)(memberUid='.$user->getUsername().'))';
|
||||
$subbranch = $this->baseniveau03;
|
||||
$results = $this->search($criteria, ['cn'], $subbranch);
|
||||
foreach ($results as $result) {
|
||||
// Si Niveau03 différent de celui en cours on le détache de ce Niveau03
|
||||
if (null === $user->getNiveau03() || $result['cn'] != $user->getNiveau03()->getLabel() || $todel) {
|
||||
$dn = $this->getNiveau03DN($result['cn']);
|
||||
$entry['memberuid'] = $user->getUsername();
|
||||
$result = ldap_mod_del($connection, $dn, $entry);
|
||||
if (!$result) {
|
||||
$this->ldapError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On recherche le Niveau03 en cours
|
||||
if (!$todel) {
|
||||
if (null !== $user->getNiveau03()) {
|
||||
$criteria = '(cn='.$user->getNiveau03()->getLabel().')';
|
||||
$subbranch = $this->baseniveau03;
|
||||
$result = $this->search($criteria, ['memberuid'], $subbranch);
|
||||
|
||||
// S'il n'est pas membre du Niveau03 on le rattache
|
||||
if (empty($result) || !$this->in_array_r($user->getUsername(), $result[0])) {
|
||||
$dn = $this->getNiveau03DN($user->getNiveau03()->getLabel());
|
||||
$entry['memberuid'] = $user->getUsername();
|
||||
$result = ldap_mod_add($connection, $dn, $entry);
|
||||
if (!$result) {
|
||||
$this->ldapError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NIVEAU04
|
||||
// On recherche le Niveau04 actuellement asscocié à l'utilisateur
|
||||
$criteria = '(&(cn=*)(memberUid='.$user->getUsername().'))';
|
||||
$subbranch = $this->baseniveau04;
|
||||
$results = $this->search($criteria, ['cn'], $subbranch);
|
||||
foreach ($results as $result) {
|
||||
// Si Niveau04 différent de celui en cours on le détache de ce Niveau04
|
||||
if (null === $user->getNiveau04() || $result['cn'] != $user->getNiveau04()->getLabel() || $todel) {
|
||||
$dn = $this->getNiveau04DN($result['cn']);
|
||||
$entry['memberuid'] = $user->getUsername();
|
||||
$result = ldap_mod_del($connection, $dn, $entry);
|
||||
if (!$result) {
|
||||
$this->ldapError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On recherche le Niveau04 en cours
|
||||
if (!$todel) {
|
||||
if (null !== $user->getNiveau04()) {
|
||||
$criteria = '(cn='.$user->getNiveau04()->getLabel().')';
|
||||
$subbranch = $this->baseniveau04;
|
||||
$result = $this->search($criteria, ['memberuid'], $subbranch);
|
||||
|
||||
// S'il n'est pas membre du Niveau04 on le rattache
|
||||
if (empty($result) || !$this->in_array_r($user->getUsername(), $result[0])) {
|
||||
$dn = $this->getNiveau04DN($user->getNiveau04()->getLabel());
|
||||
$entry['memberuid'] = $user->getUsername();
|
||||
$result = ldap_mod_add($connection, $dn, $entry);
|
||||
if (!$result) {
|
||||
$this->ldapError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -816,6 +907,262 @@ class LdapService
|
||||
return 'cn='.$id.','.$this->baseniveau02;
|
||||
}
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// == Function Niveau03==============================================================================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
public function addNiveau03(Niveau03 $niveau03)
|
||||
{
|
||||
$connection = $this->connect();
|
||||
$dn = $this->getNiveau03DN($niveau03->getLabel());
|
||||
|
||||
$attrs = [];
|
||||
$attrs['objectclass'] = $this->getObjectClassesNiveau03();
|
||||
$this->fillAttributesNiveau03($niveau03, $attrs);
|
||||
|
||||
foreach ($attrs as $key => $value) {
|
||||
if (empty($value)) {
|
||||
unset($attrs[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$result = ldap_add($connection, $dn, $attrs);
|
||||
if (!$result) {
|
||||
$this->ldapError();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function ismodifyNiveau03(Niveau03 $niveau03, $entry)
|
||||
{
|
||||
$attrs = [];
|
||||
$this->fillAttributesNiveau03($niveau03, $attrs);
|
||||
|
||||
foreach ($attrs as $key => $value) {
|
||||
if (!array_key_exists($key, $entry) && !empty($value)) {
|
||||
return true;
|
||||
} elseif (array_key_exists($key, $entry) && $value != $entry[$key]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($entry as $key => $value) {
|
||||
if (!array_key_exists($key, $attrs) && !empty($value)) {
|
||||
return true;
|
||||
} elseif (array_key_exists($key, $attrs) && $value != $attrs[$key]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function modifyNiveau03(Niveau03 $niveau03, $oldid)
|
||||
{
|
||||
$dn = $this->basedn;
|
||||
$connection = $this->connect();
|
||||
|
||||
$attrs = [];
|
||||
$this->fillAttributesNiveau03($niveau03, $attrs);
|
||||
unset($attrs['cn']);
|
||||
|
||||
$dn = $this->getNiveau03DN($niveau03->getLabel());
|
||||
|
||||
foreach ($attrs as $key => $value) {
|
||||
if (empty($value)) {
|
||||
// Bien mettre un @ car si l'attribut est déjà vide cela crache une erreur car l'attribut n'existe déjà plus
|
||||
@ldap_mod_del($connection, $dn, [$key => []]);
|
||||
unset($attrs[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($oldid) && $oldid != $niveau03->getLabel()) {
|
||||
$olddn = $this->getNiveau03DN($oldid);
|
||||
$this->rename($olddn, 'cn='.$niveau03->getLabel(), $this->baseniveau03);
|
||||
}
|
||||
|
||||
$result = ldap_modify($connection, $dn, $attrs);
|
||||
if (!$result) {
|
||||
$this->ldapError();
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteNiveau03(Niveau03 $niveau03)
|
||||
{
|
||||
$dn = $this->getNiveau03DN($niveau03->getLabel());
|
||||
|
||||
return $this->deleteByDN($dn);
|
||||
}
|
||||
|
||||
private function getObjectClassesNiveau03()
|
||||
{
|
||||
$oc = [
|
||||
'top',
|
||||
'posixGroup',
|
||||
];
|
||||
|
||||
return $oc;
|
||||
}
|
||||
|
||||
public function listAttributesNiveau03()
|
||||
{
|
||||
return [
|
||||
'cn',
|
||||
'gidnumber',
|
||||
'memberuid',
|
||||
];
|
||||
}
|
||||
|
||||
public function fillAttributesNiveau03(Niveau03 $niveau03, array &$attrs)
|
||||
{
|
||||
$attrs['cn'] = $niveau03->getLabel();
|
||||
$attrs['gidnumber'] = $niveau03->getId();
|
||||
|
||||
$attrs['memberuid'] = [];
|
||||
foreach ($niveau03->getUsers() as $user) {
|
||||
array_push($attrs['memberuid'], $user->getUsername());
|
||||
}
|
||||
|
||||
sort($attrs['memberuid']);
|
||||
if (1 == count($attrs['memberuid'])) {
|
||||
$attrs['memberuid'] = $attrs['memberuid'][0];
|
||||
}
|
||||
}
|
||||
|
||||
public function getNiveau03DN($id)
|
||||
{
|
||||
return 'cn='.$id.','.$this->baseniveau03;
|
||||
}
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// == Function Niveau04==============================================================================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
public function addNiveau04(Niveau04 $niveau04)
|
||||
{
|
||||
$connection = $this->connect();
|
||||
$dn = $this->getNiveau04DN($niveau04->getLabel());
|
||||
|
||||
$attrs = [];
|
||||
$attrs['objectclass'] = $this->getObjectClassesNiveau04();
|
||||
$this->fillAttributesNiveau04($niveau04, $attrs);
|
||||
|
||||
foreach ($attrs as $key => $value) {
|
||||
if (empty($value)) {
|
||||
unset($attrs[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$result = ldap_add($connection, $dn, $attrs);
|
||||
if (!$result) {
|
||||
$this->ldapError();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function ismodifyNiveau04(Niveau04 $niveau04, $entry)
|
||||
{
|
||||
$attrs = [];
|
||||
$this->fillAttributesNiveau04($niveau04, $attrs);
|
||||
|
||||
foreach ($attrs as $key => $value) {
|
||||
if (!array_key_exists($key, $entry) && !empty($value)) {
|
||||
return true;
|
||||
} elseif (array_key_exists($key, $entry) && $value != $entry[$key]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($entry as $key => $value) {
|
||||
if (!array_key_exists($key, $attrs) && !empty($value)) {
|
||||
return true;
|
||||
} elseif (array_key_exists($key, $attrs) && $value != $attrs[$key]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function modifyNiveau04(Niveau04 $niveau04, $oldid)
|
||||
{
|
||||
$dn = $this->basedn;
|
||||
$connection = $this->connect();
|
||||
|
||||
$attrs = [];
|
||||
$this->fillAttributesNiveau04($niveau04, $attrs);
|
||||
unset($attrs['cn']);
|
||||
|
||||
$dn = $this->getNiveau04DN($niveau04->getLabel());
|
||||
|
||||
foreach ($attrs as $key => $value) {
|
||||
if (empty($value)) {
|
||||
// Bien mettre un @ car si l'attribut est déjà vide cela crache une erreur car l'attribut n'existe déjà plus
|
||||
@ldap_mod_del($connection, $dn, [$key => []]);
|
||||
unset($attrs[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($oldid) && $oldid != $niveau04->getLabel()) {
|
||||
$olddn = $this->getNiveau04DN($oldid);
|
||||
$this->rename($olddn, 'cn='.$niveau04->getLabel(), $this->baseniveau04);
|
||||
}
|
||||
|
||||
$result = ldap_modify($connection, $dn, $attrs);
|
||||
if (!$result) {
|
||||
$this->ldapError();
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteNiveau04(Niveau04 $niveau04)
|
||||
{
|
||||
$dn = $this->getNiveau04DN($niveau04->getLabel());
|
||||
|
||||
return $this->deleteByDN($dn);
|
||||
}
|
||||
|
||||
private function getObjectClassesNiveau04()
|
||||
{
|
||||
$oc = [
|
||||
'top',
|
||||
'posixGroup',
|
||||
];
|
||||
|
||||
return $oc;
|
||||
}
|
||||
|
||||
public function listAttributesNiveau04()
|
||||
{
|
||||
return [
|
||||
'cn',
|
||||
'gidnumber',
|
||||
'memberuid',
|
||||
];
|
||||
}
|
||||
|
||||
public function fillAttributesNiveau04(Niveau04 $niveau04, array &$attrs)
|
||||
{
|
||||
$attrs['cn'] = $niveau04->getLabel();
|
||||
$attrs['gidnumber'] = $niveau04->getId();
|
||||
|
||||
$attrs['memberuid'] = [];
|
||||
foreach ($niveau04->getUsers() as $user) {
|
||||
array_push($attrs['memberuid'], $user->getUsername());
|
||||
}
|
||||
|
||||
sort($attrs['memberuid']);
|
||||
if (1 == count($attrs['memberuid'])) {
|
||||
$attrs['memberuid'] = $attrs['memberuid'][0];
|
||||
}
|
||||
}
|
||||
|
||||
public function getNiveau04DN($id)
|
||||
{
|
||||
return 'cn='.$id.','.$this->baseniveau04;
|
||||
}
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// == Function Group=================================================================================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
|
Reference in New Issue
Block a user