fix(continuous-integration): correction php-cs-fixer
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good

This commit is contained in:
2022-09-23 16:14:15 +02:00
parent 5f3cc51f5c
commit b78f54b76c
70 changed files with 5943 additions and 5549 deletions

View File

@ -1,695 +1,720 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Doctrine\Persistence\ManagerRegistry;
use Ramsey\Uuid\Uuid;
use App\Entity\Group as Entity;
use App\Entity\UserGroup;
use App\Form\GroupType 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 GroupController extends AbstractController
{
private $data="group";
private $entity="App\Entity\Group";
private $twig="Group/";
private $route="app_admin_group";
private $data = 'group';
private $entity = "App\Entity\Group";
private $twig = 'Group/';
private $route = 'app_admin_group';
public function list($access): Response
{
return $this->render($this->twig.'list.html.twig',[
"useheader"=>true,
"usemenu"=>false,
"usesidebar"=>($access!="user"),
"access"=>$access,
{
return $this->render($this->twig.'list.html.twig', [
'useheader' => true,
'usemenu' => false,
'usesidebar' => ('user' != $access),
'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'];
$user=$this->getUser();
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'];
$user = $this->getUser();
// Nombre total d'enregistrement
$qb = $em->getManager()->createQueryBuilder();
$qb->select('COUNT(entity)')->from($this->entity,'entity')->getQuery()->getSingleScalarResult();
if($access=="user") {
$qb ->from("App:UserGroup","usergroup")
->andWhere(("entity.isworkgroup=:flag"))
->andWhere("entity.id=usergroup.group")
->andWhere("usergroup.user=:user")
->setParameter("flag", true)
->setParameter("user", $user);
$qb->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
if ('user' == $access) {
$qb->from('App:UserGroup', 'usergroup')
->andWhere('entity.isworkgroup=:flag')
->andWhere('entity.id=usergroup.group')
->andWhere('usergroup.user=:user')
->setParameter('flag', true)
->setParameter('user', $user);
}
$total = $qb->getQuery()->getSingleScalarResult();
// Nombre d'enregistrement filtré
if(!$search||$search["value"]=="")
if (!$search || '' == $search['value']) {
$totalf = $total;
else {
$qb= $em->getManager()->createQueryBuilder();
$qb ->select('COUNT(entity)')
->from($this->entity,'entity')
} else {
$qb = $em->getManager()->createQueryBuilder();
$qb->select('COUNT(entity)')
->from($this->entity, 'entity')
->where('entity.label LIKE :value')
->leftJoin('App:User', 'user','WITH','entity.owner = user.id AND user.username LIKE :value')
->setParameter("value", "%".$search["value"]."%")
->leftJoin('App:User', 'user', 'WITH', 'entity.owner = user.id AND user.username LIKE :value')
->setParameter('value', '%'.$search['value'].'%')
->getQuery()
->getSingleScalarResult();
if($access=="user") {
$qb ->from("App:UserGroup","usergroup")
->andWhere(("entity.isworkgroup=:flag"))
->andWhere("entity.id=usergroup.group")
->andWhere("usergroup.user=:user")
->setParameter("flag", true)
->setParameter("user", $user);
}
$totalf= $qb->getQuery()->getSingleScalarResult();
if ('user' == $access) {
$qb->from('App:UserGroup', 'usergroup')
->andWhere('entity.isworkgroup=:flag')
->andWhere('entity.id=usergroup.group')
->andWhere('usergroup.user=:user')
->setParameter('flag', true)
->setParameter('user', $user);
}
$totalf = $qb->getQuery()->getSingleScalarResult();
}
// Construction du tableau de retour
$output = array(
$output = [
'draw' => $draw,
'recordsFiltered' => $totalf,
'recordsTotal' => $total,
'data' => array(),
);
'data' => [],
];
// Parcours des Enregistrement
$qb = $em->getManager()->createQueryBuilder();
$qb ->select('entity')
->from($this->entity,'entity');
if($access=="user") {
$qb ->from("App:UserGroup","usergroup")
->andWhere(("entity.isworkgroup=:flag"))
->andWhere("entity.id=usergroup.group")
->andWhere("usergroup.user=:user")
->setParameter("flag", true)
->setParameter("user", $user);
$qb->select('entity')
->from($this->entity, 'entity');
if ('user' == $access) {
$qb->from('App:UserGroup', 'usergroup')
->andWhere('entity.isworkgroup=:flag')
->andWhere('entity.id=usergroup.group')
->andWhere('usergroup.user=:user')
->setParameter('flag', true)
->setParameter('user', $user);
}
if($search&&$search["value"]!="") {
$qb ->andWhere('entity.label LIKE :value')
->setParameter("value", "%".$search["value"]."%");
if ($search && '' != $search['value']) {
$qb->andWhere('entity.label LIKE :value')
->setParameter('value', '%'.$search['value'].'%');
}
if($ordercolumn) {
switch($ordercolumn) {
case 1 :
$qb->orderBy('entity.label',$orderdir);
break;
case 2 :
$qb->orderBy('entity.isworkgroup',$orderdir);
break;
case 3 :
$qb->orderBy('entity.isopen',$orderdir);
break;
case 4 :
$qb->orderBy('entity.owner',$orderdir);
break;
if ($ordercolumn) {
switch ($ordercolumn) {
case 1:
$qb->orderBy('entity.label', $orderdir);
break;
case 2:
$qb->orderBy('entity.isworkgroup', $orderdir);
break;
case 3:
$qb->orderBy('entity.isopen', $orderdir);
break;
case 4:
$qb->orderBy('entity.owner', $orderdir);
break;
}
}
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
foreach($datas as $data) {
foreach ($datas as $data) {
// Action
$action = "";
switch($access) {
case "admin":
if($this->canupdate($access,$data,$em,false))
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_update', ['id'=>$data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
$action = '';
switch ($access) {
case 'admin':
if ($this->canupdate($access, $data, $em, false)) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
}
if($this->canseemember($access,$data,$em,false))
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_users', ['id'=>$data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
break;
if ($this->canseemember($access, $data, $em, false)) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_users', ['id' => $data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
}
break;
case "modo":
if($this->canupdate($access,$data,$em,false))
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_update', ['id'=>$data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
case 'modo':
if ($this->canupdate($access, $data, $em, false)) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
}
if($this->canseemember($access,$data,$em,false))
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_users', ['id'=>$data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
break;
if ($this->canseemember($access, $data, $em, false)) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_users', ['id' => $data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
}
break;
case "user":
if($this->canupdate($access,$data,$em,false))
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_update', ['id'=>$data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
if($this->canseemember($access,$data,$em,false))
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_users', ['id'=>$data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
case 'user':
if ($this->canupdate($access, $data, $em, false)) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
}
if ($this->canseemember($access, $data, $em, false)) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_users', ['id' => $data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
}
// On ne peut se désinscrire que si le groupe est ouvert et qu'il n'est pas lié à un groupe ldap ou sso
if($data->getOwner()!=$this->getUser()&&($data->isIsOpen()||$this->canupdatemember($access,$data,$em,false)))
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_userout', ['id'=>$data->getId()])."'><i class='fa fa-sign-out-alt fa-fw fa-2x'></i></a>";
break;
if ($data->getOwner() != $this->getUser() && ($data->isIsOpen() || $this->canupdatemember($access, $data, $em, false))) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_userout', ['id' => $data->getId()])."'><i class='fa fa-sign-out-alt fa-fw fa-2x'></i></a>";
}
break;
}
$userinfo="";
if($data->getOwner()) {
$userinfo.="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getOwner()->getAvatar()])."' class='avatar'>";
$userinfo.="<br>".$data->getOwner()->getUsername();
$userinfo = '';
if ($data->getOwner()) {
$userinfo .= "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getOwner()->getAvatar()])."' class='avatar'>";
$userinfo .= '<br>'.$data->getOwner()->getUsername();
}
$visitecpt=0;
$visitelast=null;
foreach($data->getUsers() as $usergroup) {
$visitecpt+=intval($usergroup->getVisitecpt());
$visitelast=($usergroup->getVisitedate()>$visitelast?$usergroup->getVisitedate():$visitelast);
$visitecpt = 0;
$visitelast = null;
foreach ($data->getUsers() as $usergroup) {
$visitecpt += intval($usergroup->getVisitecpt());
$visitelast = ($usergroup->getVisitedate() > $visitelast ? $usergroup->getVisitedate() : $visitelast);
}
$tmp=array();
array_push($tmp,$action);
array_push($tmp,$data->getLabel());
array_push($tmp,($data->isIsworkgroup()?"oui":"non"));
array_push($tmp,($data->isIsopen()?"oui":"non"));
array_push($tmp,$userinfo);
array_push($tmp,($visitelast?$visitelast->format("d/m/Y H:i")."<br>":"")."nb = ".$visitecpt);
array_push($output["data"],$tmp);
$tmp = [];
array_push($tmp, $action);
array_push($tmp, $data->getLabel());
array_push($tmp, $data->isIsworkgroup() ? 'oui' : 'non');
array_push($tmp, $data->isIsopen() ? 'oui' : 'non');
array_push($tmp, $userinfo);
array_push($tmp, ($visitelast ? $visitelast->format('d/m/Y H:i').'<br>' : '').'nb = '.$visitecpt);
array_push($output['data'], $tmp);
}
// Retour
return new JsonResponse($output);
}
}
public function submit($access,Request $request,ManagerRegistry $em): Response
public function submit($access, Request $request, ManagerRegistry $em): Response
{
// Initialisation de l'enregistrement
$data = new Entity();
$data->setApikey(Uuid::uuid4());
if($access=="user") {
if ('user' == $access) {
$data->setOwner($this->getUser());
$data->setIsworkgroup(true);
}
// Controler les permissions
$this->cansubmit($access,$em);
$this->cansubmit($access, $em);
// Création du formulaire
$form = $this->createForm(Form::class,$data,array(
"mode"=>"submit",
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
"access"=>$access,
));
$form = $this->createForm(Form::class, $data, [
'mode' => 'submit',
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'access' => $access,
]);
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
// Les groupes opé ne sont pas ouvert
if(!$data->isIsworkgroup()) $data->setIsopen(false);
if (!$data->isIsworkgroup()) {
$data->setIsopen(false);
}
// Sauvegarde
$em->getManager()->persist($data);
$em->getManager()->flush();
// Retour à la liste
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
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"=>($access!="user"),
"mode"=>"submit",
"access"=>$access,
"form"=>$form->createView(),
$this->data=>$data,
"maxsize"=>($access=="user"?1200:null),
'useheader' => true,
'usemenu' => false,
'usesidebar' => ('user' != $access),
'mode' => 'submit',
'access' => $access,
'form' => $form->createView(),
$this->data => $data,
'maxsize' => ('user' == $access ? 1200 : null),
]);
}
public function update($id,$access,Request $request,ManagerRegistry $em): Response
public function update($id, $access, Request $request, ManagerRegistry $em): Response
{
// Initialisation de l'enregistrement
$data=$em->getRepository($this->entity)->find($id);
if (!$data or $id<0) throw $this->createNotFoundException('Unable to find entity.');
$data = $em->getRepository($this->entity)->find($id);
if (!$data or $id < 0) {
throw $this->createNotFoundException('Unable to find entity.');
}
// Controler les permissions
$this->canupdate($access,$data,$em);
$this->canupdate($access, $data, $em);
// Création du formulaire
$form = $this->createForm(Form::class,$data,array(
"mode"=>"update",
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
"access"=>$access,
));
$form = $this->createForm(Form::class, $data, [
'mode' => 'update',
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
'access' => $access,
]);
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
// Les groupes opé ne sont pas ouvert
if(!$data->isIsworkgroup()) $data->setIsopen(false);
if (!$data->isIsworkgroup()) {
$data->setIsopen(false);
}
$em->getManager()->flush();
// Retour à la liste
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
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" => ($access!="user"),
'useheader' => true,
'usemenu' => false,
'usesidebar' => ('user' != $access),
$this->data => $data,
"mode" => "update",
"access"=>$access,
"form" => $form->createView(),
"maxsize"=>($access=="user"?1200:null),
'mode' => 'update',
'access' => $access,
'form' => $form->createView(),
'maxsize' => ('user' == $access ? 1200 : null),
]);
}
public function delete($id,$access,Request $request,ManagerRegistry $em): Response
public function delete($id, $access, Request $request, ManagerRegistry $em): Response
{
// Récupération de l'enregistrement courant
$data=$em->getRepository($this->entity)->find($id);
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
$data = $em->getRepository($this->entity)->find($id);
if (!$data) {
throw $this->createNotFoundException('Unable to find entity.');
}
// Controler les permissions
$this->canupdate($access,$data,$em);
$this->canupdate($access, $data, $em);
// Tentative de suppression
try{
try {
$em->getManager()->remove($data);
$em->getManager()->flush();
}
catch (\Exception $e) {
$request->getSession()->getFlashBag()->add("error", $e->getMessage());
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route)."_update",["id"=>$id]);
}
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
}
} catch (\Exception $e) {
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]);
}
public function users($id,$access,Request $request,ManagerRegistry $em)
{
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
}
public function users($id, $access, Request $request, ManagerRegistry $em)
{
// Récupération de l'enregistrement courant
$data=$em->getRepository($this->entity)->find($id);
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
$data = $em->getRepository($this->entity)->find($id);
if (!$data) {
throw $this->createNotFoundException('Unable to find entity.');
}
// Controler les permissions
$this->canseemember($access,$data,$em);
$this->canseemember($access, $data, $em);
// Affichage du formulaire
return $this->render($this->twig.'users.html.twig', [
'useheader' => true,
'usemenu' => false,
'usesidebar' => ($access!="user"),
'access' => $access,
$this->data => $data,
]);
}
'useheader' => true,
'usemenu' => false,
'usesidebar' => ('user' != $access),
'access' => $access,
$this->data => $data,
]);
}
public function usersnotin($id,$access,Request $request,ManagerRegistry $em)
public function usersnotin($id, $access, Request $request, ManagerRegistry $em)
{
// Récupération de l'enregistrement courant
$group=$em->getRepository($this->entity)->find($id);
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
$group = $em->getRepository($this->entity)->find($id);
if (!$group) {
throw $this->createNotFoundException('Unable to find entity.');
}
// Controler les permissions
$this->canseemember($access,$group,$em);
$this->canseemember($access, $group, $em);
$sub = $em->getManager()->createQueryBuilder();
$sub->select("usergroup");
$sub->from("App:UserGroup","usergroup");
$sub->select('usergroup');
$sub->from('App:UserGroup', 'usergroup');
$sub->andWhere('usergroup.user = user.id');
$sub->andWhere('usergroup.group = :groupid');
$sub->andWhere('usergroup.group = :groupid');
$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'];
$usermodo=null;
$niveau01=null;
$niveau02=null;
$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'];
$usermodo = null;
$niveau01 = null;
$niveau02 = null;
// Nombre total d'enregistrement
$qb = $em->getManager()->createQueryBuilder();
switch($access) {
case "admin":
switch ($access) {
case 'admin':
$qb->select('COUNT(user)')
->from('App:User','user')
->from('App:User', 'user')
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->setParameter("groupid",$id);
break;
case "modo":
$usermodo=$this->getUser()->getId();
$qb->select('COUNT(user)')
->from('App:User','user')
->from('App:UserModo','usermodo')
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->andWhere("usermodo.niveau01 = user.niveau01")
->andWhere("usermodo.user = :userid")
->setParameter("userid", $usermodo)
->setParameter("groupid",$id);
break;
case "user":
$niveau01=$this->getUser()->getNiveau01();
$niveau02=$this->getUser()->getNiveau02();
$qb->select('COUNT(user)')
->from('App:User','user')
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->setParameter("groupid",$id);
switch($request->getSession()->get("scopeannu")) {
case "SAME_NIVEAU01":
$qb->andWhere("user.niveau01 = :niveau01")->setParameter("niveau01",$niveau01);
break;
case "SAME_NIVEAU02":
$qb->andWhere("user.niveau02 = :niveau02")->setParameter("niveau02",$niveau02);
break;
}
break;
}
$total=$qb->getQuery()->getSingleScalarResult();
$totalf=null;
// Nombre d'enregistrement filtré
if($search["value"]=="")
$totalf = $total;
else {
switch($access) {
case "admin":
$totalf= $em->getManager()->createQueryBuilder()
->select('COUNT(user)')
->from('App:User','user')
->where('user.username LIKE :value OR user.email LIKE :value')
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->setParameter("value", "%".$search["value"]."%")
->setParameter("groupid",$id)
->getQuery()
->getSingleScalarResult();
->setParameter('groupid', $id);
break;
case "modo":
case 'modo':
$usermodo = $this->getUser()->getId();
$qb->select('COUNT(user)')
->from('App:User', 'user')
->from('App:UserModo', 'usermodo')
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->andWhere('usermodo.niveau01 = user.niveau01')
->andWhere('usermodo.user = :userid')
->setParameter('userid', $usermodo)
->setParameter('groupid', $id);
break;
case 'user':
$niveau01 = $this->getUser()->getNiveau01();
$niveau02 = $this->getUser()->getNiveau02();
$qb->select('COUNT(user)')
->from('App:User', 'user')
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->setParameter('groupid', $id);
switch ($request->getSession()->get('scopeannu')) {
case 'SAME_NIVEAU01':
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
break;
case 'SAME_NIVEAU02':
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
break;
}
break;
}
$total = $qb->getQuery()->getSingleScalarResult();
$totalf = null;
// Nombre d'enregistrement filtré
if ('' == $search['value']) {
$totalf = $total;
} else {
switch ($access) {
case 'admin':
$totalf = $em->getManager()->createQueryBuilder()
->select('COUNT(user)')
->from('App:User','user')
->from('App:UserModo','usermodo')
->from('App:User', 'user')
->where('user.username LIKE :value OR user.email LIKE :value')
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->andWhere("usermodo.niveau01 = user.niveau01")
->andWhere("usermodo.user = :userid")
->setParameter("userid", $usermodo)
->setParameter("value", "%".$search["value"]."%")
->setParameter("groupid",$id)
->setParameter('value', '%'.$search['value'].'%')
->setParameter('groupid', $id)
->getQuery()
->getSingleScalarResult();
break;
break;
case "user":
case 'modo':
$totalf = $em->getManager()->createQueryBuilder()
->select('COUNT(user)')
->from('App:User', 'user')
->from('App:UserModo', 'usermodo')
->where('user.username LIKE :value OR user.email LIKE :value')
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->andWhere('usermodo.niveau01 = user.niveau01')
->andWhere('usermodo.user = :userid')
->setParameter('userid', $usermodo)
->setParameter('value', '%'.$search['value'].'%')
->setParameter('groupid', $id)
->getQuery()
->getSingleScalarResult();
break;
case 'user':
$qb = $em->getManager()->createQueryBuilder()
->select('COUNT(user)')
->from('App:User','user')
->from('App:User', 'user')
->where('user.username LIKE :value OR user.email LIKE :value')
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->setParameter("value", "%".$search["value"]."%")
->setParameter("groupid",$id);
switch($request->getSession()->get("scopeannu")) {
case "SAME_NIVEAU01":
$qb->andWhere("user.niveau01 = :niveau01")->setParameter("niveau01",$niveau01);
break;
case "SAME_NIVEAU02":
$qb->andWhere("user.niveau02 = :niveau02")->setParameter("niveau02",$niveau02);
break;
}
->setParameter('value', '%'.$search['value'].'%')
->setParameter('groupid', $id);
$totalf=$qb->getQuery()->getSingleScalarResult();
break;
switch ($request->getSession()->get('scopeannu')) {
case 'SAME_NIVEAU01':
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
break;
case 'SAME_NIVEAU02':
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
break;
}
$totalf = $qb->getQuery()->getSingleScalarResult();
break;
}
}
// Construction du tableau de retour
$output = array(
$output = [
'draw' => $draw,
'recordsFiltered' => $totalf,
'recordsTotal' => $total,
'data' => array(),
);
'data' => [],
];
// Parcours des Enregistrement
$qb = $em->getManager()->createQueryBuilder();
$qb->select('user')->from("App:User",'user');
switch($access) {
case "admin":
$qb->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
break;
$qb->select('user')->from('App:User', 'user');
case "modo":
$qb->from('App:UserModo','usermodo')
switch ($access) {
case 'admin':
$qb->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
break;
case 'modo':
$qb->from('App:UserModo', 'usermodo')
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->andWhere("usermodo.niveau01 = user.niveau01")
->andWhere("usermodo.user = :userid")
->setParameter("userid", $usermodo);
break;
->andWhere('usermodo.niveau01 = user.niveau01')
->andWhere('usermodo.user = :userid')
->setParameter('userid', $usermodo);
break;
case "user":
case 'user':
$qb->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
switch($request->getSession()->get("scopeannu")) {
case "SAME_NIVEAU01":
$qb->andWhere("user.niveau01 = :niveau01")->setParameter("niveau01",$niveau01);
break;
switch ($request->getSession()->get('scopeannu')) {
case 'SAME_NIVEAU01':
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
break;
case "SAME_NIVEAU02":
$qb->andWhere("user.niveau02 = :niveau02")->setParameter("niveau02",$niveau02);
break;
case 'SAME_NIVEAU02':
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
break;
}
break;
break;
}
if($search["value"]!="") {
$qb ->andWhere('user.username LIKE :value OR user.email LIKE :value')
->setParameter("value", "%".$search["value"]."%");
if ('' != $search['value']) {
$qb->andWhere('user.username LIKE :value OR user.email LIKE :value')
->setParameter('value', '%'.$search['value'].'%');
}
$qb->setParameter("groupid",$id);
switch($ordercolumn) {
case 2 :
$qb->orderBy('user.username',$orderdir);
break;
$qb->setParameter('groupid', $id);
switch ($ordercolumn) {
case 2:
$qb->orderBy('user.username', $orderdir);
break;
case 3 :
$qb->orderBy('user.email',$orderdir);
break;
case 3:
$qb->orderBy('user.email', $orderdir);
break;
}
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
$canupdatemember=$this->canupdatemember($access,$group,$em,false);
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
$canupdatemember = $this->canupdatemember($access, $group, $em, false);
foreach($datas as $data) {
foreach ($datas as $data) {
// Action
$action = "";
if($canupdatemember)
$action.="<a style='cursor:pointer' onClick='addUsers(".$data->getId().")'><i class='fa fa-plus fa-fw'></i></a>";
// Avatar
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>";
$action = '';
if ($canupdatemember) {
$action .= "<a style='cursor:pointer' onClick='addUsers(".$data->getId().")'><i class='fa fa-plus fa-fw'></i></a>";
}
array_push($output["data"],array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),"",""));
// Avatar
$avatar = "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getAvatar()])."' class='avatar'>";
array_push($output['data'], ['DT_RowId' => 'user'.$data->getId(), $action, $avatar, $data->getUsername(), $data->getEmail(), '', '']);
}
// Retour
return new JsonResponse($output);
}
}
public function usersin($id,$access,Request $request,ManagerRegistry $em)
{
public function usersin($id, $access, Request $request, ManagerRegistry $em)
{
// Récupération de l'enregistrement courant
$group=$em->getRepository($this->entity)->find($id);
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
$group = $em->getRepository($this->entity)->find($id);
if (!$group) {
throw $this->createNotFoundException('Unable to find entity.');
}
// Controler les permissions
$this->canseemember($access,$group,$em);
$this->canseemember($access, $group, $em);
$sub = $em->getManager()->createQueryBuilder();
$sub->select("usergroup");
$sub->from("App:UserGroup","usergroup");
$sub->select('usergroup');
$sub->from('App:UserGroup', 'usergroup');
$sub->andWhere('usergroup.user = user.id');
$sub->andWhere('usergroup.group = :groupid');
$sub->andWhere('usergroup.group = :groupid');
$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'];
$usermodo=null;
$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'];
$usermodo = null;
// Nombre total d'enregistrement
$qb = $em->getManager()->createQueryBuilder();
if($access=="admin"||$access=="user")
if ('admin' == $access || 'user' == $access) {
$qb->select('COUNT(user)')
->from('App:User','user')
->from('App:User', 'user')
->where($qb->expr()->exists($sub->getDQL()))
->setParameter("groupid",$id);
else {
$usermodo=$this->getUser()->getId();
->setParameter('groupid', $id);
} else {
$usermodo = $this->getUser()->getId();
$qb->select('COUNT(user)')
->from('App:User','user')
->from('App:UserModo','usermodo')
->from('App:User', 'user')
->from('App:UserModo', 'usermodo')
->where($qb->expr()->exists($sub->getDQL()))
->andWhere("usermodo.niveau01 = user.niveau01")
->andWhere("usermodo.user = :userid")
->setParameter("userid", $usermodo)
->setParameter("groupid",$id);
->andWhere('usermodo.niveau01 = user.niveau01')
->andWhere('usermodo.user = :userid')
->setParameter('userid', $usermodo)
->setParameter('groupid', $id);
}
$total=$qb->getQuery()->getSingleScalarResult();
$total = $qb->getQuery()->getSingleScalarResult();
// Nombre d'enregistrement filtré
if($search["value"]=="")
if ('' == $search['value']) {
$totalf = $total;
else {
if($access=="admin"||$access=="user")
$totalf= $em->getManager()->createQueryBuilder()
} else {
if ('admin' == $access || 'user' == $access) {
$totalf = $em->getManager()->createQueryBuilder()
->select('COUNT(user)')
->from('App:User','user')
->from('App:User', 'user')
->where('user.username LIKE :value OR user.email LIKE :value')
->andWhere($qb->expr()->exists($sub->getDQL()))
->setParameter("value", "%".$search["value"]."%")
->setParameter("groupid",$id)
->setParameter('value', '%'.$search['value'].'%')
->setParameter('groupid', $id)
->getQuery()
->getSingleScalarResult();
else
$totalf= $em->getManager()->createQueryBuilder()
} else {
$totalf = $em->getManager()->createQueryBuilder()
->select('COUNT(user)')
->from('App:User','user')
->from('App:UserModo','usermodo')
->from('App:User', 'user')
->from('App:UserModo', 'usermodo')
->where('user.username LIKE :value OR user.email LIKE :value')
->andWhere($qb->expr()->exists($sub->getDQL()))
->andWhere("usermodo.niveau01 = user.niveau01")
->andWhere("usermodo.user = :userid")
->setParameter("userid", $usermodo)
->setParameter("value", "%".$search["value"]."%")
->setParameter("groupid",$id)
->andWhere('usermodo.niveau01 = user.niveau01')
->andWhere('usermodo.user = :userid')
->setParameter('userid', $usermodo)
->setParameter('value', '%'.$search['value'].'%')
->setParameter('groupid', $id)
->getQuery()
->getSingleScalarResult();
}
}
// Construction du tableau de retour
$output = array(
$output = [
'draw' => $draw,
'recordsFiltered' => $totalf,
'recordsTotal' => $total,
'data' => array(),
);
'data' => [],
];
// Parcours des Enregistrement
$qb = $em->getManager()->createQueryBuilder();
$qb->select('user')->from("App:User",'user');
if($access=="admin"||$access=="user")
$qb->select('user')->from('App:User', 'user');
if ('admin' == $access || 'user' == $access) {
$qb->where($qb->expr()->exists($sub->getDQL()));
else
$qb->from('App:UserModo','usermodo')
} else {
$qb->from('App:UserModo', 'usermodo')
->where($qb->expr()->exists($sub->getDQL()))
->andWhere("usermodo.niveau01 = user.niveau01")
->andWhere("usermodo.user = :userid")
->setParameter("userid", $usermodo);
if($search["value"]!="") {
$qb ->andWhere('user.username LIKE :value OR user.email LIKE :value')
->setParameter("value", "%".$search["value"]."%");
}
$qb->setParameter("groupid",$id);
switch($ordercolumn) {
case 2 :
$qb->orderBy('user.username',$orderdir);
break;
case 3 :
$qb->orderBy('user.email',$orderdir);
break;
->andWhere('usermodo.niveau01 = user.niveau01')
->andWhere('usermodo.user = :userid')
->setParameter('userid', $usermodo);
}
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
foreach($datas as $data) {
if ('' != $search['value']) {
$qb->andWhere('user.username LIKE :value OR user.email LIKE :value')
->setParameter('value', '%'.$search['value'].'%');
}
$qb->setParameter('groupid', $id);
switch ($ordercolumn) {
case 2:
$qb->orderBy('user.username', $orderdir);
break;
case 3:
$qb->orderBy('user.email', $orderdir);
break;
}
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
foreach ($datas as $data) {
// Propriétaire
$usergroup=$em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$data->getId(),"group"=>$id]);
$fgproprio=($usergroup->getUser()==$group->getOwner());
$fgme=($usergroup->getUser()==$this->getUser()&&$access!="admin");
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $data->getId(), 'group' => $id]);
$fgproprio = ($usergroup->getUser() == $group->getOwner());
$fgme = ($usergroup->getUser() == $this->getUser() && 'admin' != $access);
// Action
$action = "";
if($this->canupdatemember($access,$group,$em,false)&&!$fgproprio&&!$fgme)
$action.="<a style='cursor:pointer' onClick='delUsers(".$data->getId().")'><i class='fa fa-minus fa-fw'></i></a>";
$action = '';
if ($this->canupdatemember($access, $group, $em, false) && !$fgproprio && !$fgme) {
$action .= "<a style='cursor:pointer' onClick='delUsers(".$data->getId().")'><i class='fa fa-minus fa-fw'></i></a>";
}
// Avatar
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>";
$avatar = "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getAvatar()])."' class='avatar'>";
// Flag manager
$rolegroup="";
if($fgproprio) $rolegroup="Propriétaire du groupe";
elseif($this->canupdatemember($access,$group,$em,false)&&!$fgme) {
$selectuser=($usergroup->getRolegroup()==0?"selected='selected'":"");
$selectwritter=($usergroup->getRolegroup()==50?"selected='selected'":"");
$selectmanager=($usergroup->getRolegroup()==90?"selected='selected'":"");
$rolegroup = '';
if ($fgproprio) {
$rolegroup = 'Propriétaire du groupe';
} elseif ($this->canupdatemember($access, $group, $em, false) && !$fgme) {
$selectuser = (0 == $usergroup->getRolegroup() ? "selected='selected'" : '');
$selectwritter = (50 == $usergroup->getRolegroup() ? "selected='selected'" : '');
$selectmanager = (90 == $usergroup->getRolegroup() ? "selected='selected'" : '');
$rolegroup='<select id="roleuser-'.$data->getId().'" name="user[visible]" onChange="changeRole('.$data->getId().');"><option value="0" '.$selectuser.'>Utilisateur</option><option value="50" '.$selectwritter.'>Collaborateur</option><option value="90" '.$selectmanager.'>Gestionnaire</option></select>';
$rolegroup = '<select id="roleuser-'.$data->getId().'" name="user[visible]" onChange="changeRole('.$data->getId().');"><option value="0" '.$selectuser.'>Utilisateur</option><option value="50" '.$selectwritter.'>Collaborateur</option><option value="90" '.$selectmanager.'>Gestionnaire</option></select>';
} else {
$rolegroup = (0 == $usergroup->getRolegroup() ? 'Utilisateur' : (50 == $usergroup->getRolegroup() ? 'Collaborateur' : 'Gestionnaire'));
}
else $rolegroup=($usergroup->getRolegroup()==0?"Utilisateur":($usergroup->getRolegroup()==50?"Collaborateur":"Gestionnaire"));
$tmp=array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),$rolegroup);
array_push($output["data"],$tmp);
$tmp = ['DT_RowId' => 'user'.$data->getId(), $action, $avatar, $data->getUsername(), $data->getEmail(), $rolegroup];
array_push($output['data'], $tmp);
}
// Retour
return new JsonResponse($output);
}
}
public function useradd($groupid,$userid,$access,Request $request,ManagerRegistry $em)
public function useradd($groupid, $userid, $access, Request $request, ManagerRegistry $em)
{
// Récupération de l'enregistrement courant
$group=$em->getRepository($this->entity)->find($groupid);
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
$group = $em->getRepository($this->entity)->find($groupid);
if (!$group) {
throw $this->createNotFoundException('Unable to find entity.');
}
$user=$em->getRepository("App\Entity\User")->find($userid);
if (!$user) throw $this->createNotFoundException('Unable to find entity.');
$user = $em->getRepository("App\Entity\User")->find($userid);
if (!$user) {
throw $this->createNotFoundException('Unable to find entity.');
}
$output=array();
$this->canupdatemember($access,$group,$em,true);
$output = [];
$this->canupdatemember($access, $group, $em, true);
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(array("user"=>$user,"group"=>$group));
if($usergroup) return new JsonResponse($output);
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
if ($usergroup) {
return new JsonResponse($output);
}
$usergroup=new UserGroup();
$usergroup = new UserGroup();
$usergroup->setUser($user);
$usergroup->setGroup($group);
$usergroup->setApikey(Uuid::uuid4());
@ -697,127 +722,168 @@ class GroupController extends AbstractController
$em->getManager()->persist($usergroup);
$em->getManager()->flush();
// Retour
// Retour
return new JsonResponse($output);
}
public function userdel($groupid,$userid,$access,Request $request,ManagerRegistry $em)
public function userdel($groupid, $userid, $access, Request $request, ManagerRegistry $em)
{
// Récupération de l'enregistrement courant
$group=$em->getRepository($this->entity)->find($groupid);
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
$group = $em->getRepository($this->entity)->find($groupid);
if (!$group) {
throw $this->createNotFoundException('Unable to find entity.');
}
$user=$em->getRepository("App\Entity\User")->find($userid);
if (!$user) throw $this->createNotFoundException('Unable to find entity.');
$user = $em->getRepository("App\Entity\User")->find($userid);
if (!$user) {
throw $this->createNotFoundException('Unable to find entity.');
}
$output=array();
$this->canupdatemember($access,$group,$em,true);
if($user==$group->getOwner()) throw $this->createAccessDeniedException('Permission denied');
$output = [];
$this->canupdatemember($access, $group, $em, true);
if ($user == $group->getOwner()) {
throw $this->createAccessDeniedException('Permission denied');
}
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(array("user"=>$user,"group"=>$group));
if($usergroup) {
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
if ($usergroup) {
$em->getManager()->remove($usergroup);
$em->getManager()->flush();
}
// Retour
// Retour
return new JsonResponse($output);
}
public function userchangerole($groupid,$userid,$roleid,$access,Request $request,ManagerRegistry $em)
public function userchangerole($groupid, $userid, $roleid, $access, Request $request, ManagerRegistry $em)
{
// Récupération de l'enregistrement courant
$group=$em->getRepository($this->entity)->find($groupid);
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
$group = $em->getRepository($this->entity)->find($groupid);
if (!$group) {
throw $this->createNotFoundException('Unable to find entity.');
}
$user=$em->getRepository("App\Entity\User")->find($userid);
if (!$user) throw $this->createNotFoundException('Unable to find entity.');
$user = $em->getRepository("App\Entity\User")->find($userid);
if (!$user) {
throw $this->createNotFoundException('Unable to find entity.');
}
$output=array();
$this->canupdatemember($access,$group,$em,true);
if($user==$group->getOwner()) throw $this->createAccessDeniedException('Permission denied');
$output = [];
$this->canupdatemember($access, $group, $em, true);
if ($user == $group->getOwner()) {
throw $this->createAccessDeniedException('Permission denied');
}
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(array("user"=>$user,"group"=>$group));
if($usergroup) {
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
if ($usergroup) {
$usergroup->setRolegroup($roleid);
$em->getManager()->persist($usergroup);
$em->getManager()->flush();
}
// Retour
// Retour
return new JsonResponse($output);
}
public function userout($id,$access,Request $request,ManagerRegistry $em)
public function userout($id, $access, Request $request, ManagerRegistry $em)
{
// Récupération de l'enregistrement courant
$group=$em->getRepository($this->entity)->find($id);
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
// On ne peut se désinscrire que si le groupe est ouvert et qu'il n'est pas lié à un groupe ldap ou sso
if($group->getOwner()!=$this->getUser()&&($group->isIsOpen()||$this->canupdatemember($access,$group,$em,false))) {
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(array("user"=>$this->getUser(),"group"=>$group));
if($usergroup) {
$em->getManager()->remove($usergroup);
$em->getManager()->flush();
}
$group = $em->getRepository($this->entity)->find($id);
if (!$group) {
throw $this->createNotFoundException('Unable to find entity.');
}
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
// On ne peut se désinscrire que si le groupe est ouvert et qu'il n'est pas lié à un groupe ldap ou sso
if ($group->getOwner() != $this->getUser() && ($group->isIsOpen() || $this->canupdatemember($access, $group, $em, false))) {
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $this->getUser(), 'group' => $group]);
if ($usergroup) {
$em->getManager()->remove($usergroup);
$em->getManager()->flush();
}
}
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
}
private function cansubmit($access,$em) {
switch($access) {
case "admin" : return true; break;
case "user" : return true; break;
private function cansubmit($access, $em)
{
switch ($access) {
case 'admin': return true;
break;
case 'user': return true;
break;
}
throw $this->createAccessDeniedException('Permission denied');
}
private function canupdate($access,$entity,$em,$fgblock=true) {
$toreturn=false;
switch($access) {
case "admin" : $toreturn=($entity->getId()>0); break;
case "user":
if(!$entity->isIsworkgroup()||$entity->getOwner()!=$this->getUser()) $toreturn=false;
else $toreturn=true;
break;
private function canupdate($access, $entity, $em, $fgblock = true)
{
$toreturn = false;
switch ($access) {
case 'admin': $toreturn = ($entity->getId() > 0);
break;
case 'user':
if (!$entity->isIsworkgroup() || $entity->getOwner() != $this->getUser()) {
$toreturn = false;
} else {
$toreturn = true;
}
break;
}
if($fgblock&&!$toreturn) throw $this->createAccessDeniedException('Permission denied');
if ($fgblock && !$toreturn) {
throw $this->createAccessDeniedException('Permission denied');
}
return $toreturn;
}
private function canseemember($access,$entity,$em,$fgblock=true) {
$toreturn=false;
switch($access) {
case "admin" : $toreturn=($entity->getId()>0); break;
case "modo" : $toreturn=($entity->getId()>0); break;
case "user":
$usergroup=$em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$this->getUser(),"group"=>$entity]);
if(!$usergroup||!$entity->isIsworkgroup()||$entity->getId()<0) $toreturn=false;
else $toreturn=true;
break;
private function canseemember($access, $entity, $em, $fgblock = true)
{
$toreturn = false;
switch ($access) {
case 'admin': $toreturn = ($entity->getId() > 0);
break;
case 'modo': $toreturn = ($entity->getId() > 0);
break;
case 'user':
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $this->getUser(), 'group' => $entity]);
if (!$usergroup || !$entity->isIsworkgroup() || $entity->getId() < 0) {
$toreturn = false;
} else {
$toreturn = true;
}
break;
}
if($fgblock&&!$toreturn) throw $this->createAccessDeniedException('Permission denied');
if ($fgblock && !$toreturn) {
throw $this->createAccessDeniedException('Permission denied');
}
return $toreturn;
}
private function canupdatemember($access,$entity,$em,$fgblock=true) {
$toreturn=false;
switch($access) {
case "admin" : $toreturn=($entity->getId()>0&&!$entity->getLdapfilter()); break;
case "modo" : $toreturn=($entity->getId()>0); break;
case "user":
$usergroup=$em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$this->getUser(),"group"=>$entity]);
if(!$usergroup||!$entity->isIsworkgroup()||$entity->getId()<0) $toreturn=false;
elseif($usergroup->getRolegroup()<90) $toreturn=false;
else $toreturn=true;
break;
private function canupdatemember($access, $entity, $em, $fgblock = true)
{
$toreturn = false;
switch ($access) {
case 'admin': $toreturn = ($entity->getId() > 0 && !$entity->getLdapfilter());
break;
case 'modo': $toreturn = ($entity->getId() > 0);
break;
case 'user':
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $this->getUser(), 'group' => $entity]);
if (!$usergroup || !$entity->isIsworkgroup() || $entity->getId() < 0) {
$toreturn = false;
} elseif ($usergroup->getRolegroup() < 90) {
$toreturn = false;
} else {
$toreturn = true;
}
break;
}
if($fgblock&&!$toreturn) throw $this->createAccessDeniedException('Permission denied');
if ($fgblock && !$toreturn) {
throw $this->createAccessDeniedException('Permission denied');
}
return $toreturn;
}
}
}
}