2022-07-21 16:15:47 +02:00
|
|
|
<?php
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
namespace App\Controller;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
use App\Entity\Group as Entity;
|
|
|
|
use App\Entity\UserGroup;
|
|
|
|
use App\Form\GroupType as Form;
|
2022-09-23 16:14:15 +02:00
|
|
|
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;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
class GroupController extends AbstractController
|
|
|
|
{
|
2022-09-23 16:14:15 +02:00
|
|
|
private $data = 'group';
|
|
|
|
private $entity = "App\Entity\Group";
|
|
|
|
private $twig = 'Group/';
|
|
|
|
private $route = 'app_admin_group';
|
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
public function list($access): Response
|
2022-09-23 16:14:15 +02:00
|
|
|
{
|
|
|
|
return $this->render($this->twig.'list.html.twig', [
|
|
|
|
'useheader' => true,
|
|
|
|
'usemenu' => false,
|
2022-10-02 14:50:48 +02:00
|
|
|
'usesidebar' => ('all' != $access),
|
2022-09-23 16:14:15 +02:00
|
|
|
'access' => $access,
|
2022-07-21 16:15:47 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
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();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Nombre total d'enregistrement
|
|
|
|
$qb = $em->getManager()->createQueryBuilder();
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
2022-10-02 14:50:48 +02:00
|
|
|
if ('all' == $access) {
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->from('App:UserGroup', 'usergroup')
|
|
|
|
->andWhere('entity.isworkgroup=:flag')
|
|
|
|
->andWhere('entity.id=usergroup.group')
|
|
|
|
->andWhere('usergroup.user=:user')
|
|
|
|
->setParameter('flag', true)
|
|
|
|
->setParameter('user', $user);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
$total = $qb->getQuery()->getSingleScalarResult();
|
|
|
|
|
|
|
|
// Nombre d'enregistrement filtré
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$search || '' == $search['value']) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$totalf = $total;
|
2022-09-23 16:14:15 +02:00
|
|
|
} else {
|
|
|
|
$qb = $em->getManager()->createQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('COUNT(entity)')
|
|
|
|
->from($this->entity, 'entity')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where('entity.label LIKE :value')
|
2022-09-23 16:14:15 +02:00
|
|
|
->leftJoin('App:User', 'user', 'WITH', 'entity.owner = user.id AND user.username LIKE :value')
|
|
|
|
->setParameter('value', '%'.$search['value'].'%')
|
2022-07-21 16:15:47 +02:00
|
|
|
->getQuery()
|
|
|
|
->getSingleScalarResult();
|
2022-10-02 14:50:48 +02:00
|
|
|
if ('all' == $access) {
|
2022-09-23 16:14:15 +02:00
|
|
|
$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();
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Construction du tableau de retour
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = [
|
2022-07-21 16:15:47 +02:00
|
|
|
'draw' => $draw,
|
|
|
|
'recordsFiltered' => $totalf,
|
|
|
|
'recordsTotal' => $total,
|
2022-09-23 16:14:15 +02:00
|
|
|
'data' => [],
|
|
|
|
];
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Parcours des Enregistrement
|
|
|
|
$qb = $em->getManager()->createQueryBuilder();
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->select('entity')
|
|
|
|
->from($this->entity, 'entity');
|
2022-10-02 14:50:48 +02:00
|
|
|
if ('all' == $access) {
|
2022-09-23 16:14:15 +02:00
|
|
|
$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 ($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;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
foreach ($datas as $data) {
|
2022-07-21 16:15:47 +02:00
|
|
|
// Action
|
2022-09-23 16:14:15 +02:00
|
|
|
$action = '';
|
|
|
|
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;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
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>";
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
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;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-10-02 14:50:48 +02:00
|
|
|
case 'all':
|
2022-09-23 16:14:15 +02:00
|
|
|
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>";
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
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>";
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// On ne peut se désinscrire que si le groupe est ouvert et qu'il n'est pas lié à un groupe ldap ou sso
|
2022-09-23 16:14:15 +02:00
|
|
|
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;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$userinfo = '';
|
|
|
|
if ($data->getOwner()) {
|
2022-10-02 14:50:48 +02:00
|
|
|
$userinfo .= '<div class="d-flex align-items-center">';
|
|
|
|
$userinfo .= "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getOwner()->getAvatar()])."' class='avatar me-2'>";
|
|
|
|
$userinfo .= '<div>'.$data->getOwner()->getFullname().'</div>';
|
|
|
|
$userinfo .= '</div>';
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$visitecpt = 0;
|
|
|
|
$visitelast = null;
|
|
|
|
foreach ($data->getUsers() as $usergroup) {
|
|
|
|
$visitecpt += intval($usergroup->getVisitecpt());
|
|
|
|
$visitelast = ($usergroup->getVisitedate() > $visitelast ? $usergroup->getVisitedate() : $visitelast);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$tmp = [];
|
|
|
|
array_push($tmp, $action);
|
|
|
|
array_push($tmp, $data->getLabel());
|
|
|
|
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);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retour
|
|
|
|
return new JsonResponse($output);
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2023-01-10 11:13:28 +01:00
|
|
|
public function selectlist($access, Request $request, ManagerRegistry $em): Response
|
|
|
|
{
|
|
|
|
$output = [];
|
|
|
|
$page_limit = $request->query->get('page_limit');
|
|
|
|
$q = $request->query->get('q');
|
|
|
|
|
|
|
|
$qb = $em->getManager()->createQueryBuilder();
|
|
|
|
$qb->select('table')->from($this->entity, 'table')
|
|
|
|
->where('table.label LIKE :value')
|
|
|
|
->setParameter('value', '%'.$q.'%')
|
|
|
|
->orderBy('table.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;
|
|
|
|
|
|
|
|
return new JsonResponse($ret_string);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function submit($access, Request $request, ManagerRegistry $em): Response
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Initialisation de l'enregistrement
|
|
|
|
$data = new Entity();
|
|
|
|
$data->setApikey(Uuid::uuid4());
|
2022-10-02 14:50:48 +02:00
|
|
|
if ('all' == $access) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$data->setOwner($this->getUser());
|
|
|
|
$data->setIsworkgroup(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Controler les permissions
|
2022-09-27 11:52:49 +02:00
|
|
|
if (!$this->cansubmit($access, $request)) {
|
|
|
|
throw $this->createAccessDeniedException('Permission denied');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Création du formulaire
|
2022-09-23 16:14:15 +02:00
|
|
|
$form = $this->createForm(Form::class, $data, [
|
|
|
|
'mode' => 'submit',
|
|
|
|
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
|
|
|
'access' => $access,
|
|
|
|
]);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Récupération des data du formulaire
|
|
|
|
$form->handleRequest($request);
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Sur validation
|
2022-09-23 16:14:15 +02:00
|
|
|
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
|
|
|
$data = $form->getData();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Les groupes opé ne sont pas ouvert
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$data->isIsworkgroup()) {
|
|
|
|
$data->setIsopen(false);
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Sauvegarde
|
|
|
|
$em->getManager()->persist($data);
|
|
|
|
$em->getManager()->flush();
|
|
|
|
|
|
|
|
// Retour à la liste
|
2022-09-23 16:14:15 +02:00
|
|
|
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Affichage du formulaire
|
|
|
|
return $this->render($this->twig.'edit.html.twig', [
|
2022-09-23 16:14:15 +02:00
|
|
|
'useheader' => true,
|
|
|
|
'usemenu' => false,
|
2022-10-02 14:50:48 +02:00
|
|
|
'usesidebar' => ('all' != $access),
|
2022-09-23 16:14:15 +02:00
|
|
|
'mode' => 'submit',
|
|
|
|
'access' => $access,
|
|
|
|
'form' => $form->createView(),
|
|
|
|
$this->data => $data,
|
2022-10-02 14:50:48 +02:00
|
|
|
'maxsize' => ('all' == $access ? 1200 : null),
|
2022-07-21 16:15:47 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function update($id, $access, Request $request, ManagerRegistry $em): Response
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Initialisation de l'enregistrement
|
2022-09-23 16:14:15 +02:00
|
|
|
$data = $em->getRepository($this->entity)->find($id);
|
|
|
|
if (!$data or $id < 0) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Controler les permissions
|
2022-09-23 16:14:15 +02:00
|
|
|
$this->canupdate($access, $data, $em);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Création du formulaire
|
2022-09-23 16:14:15 +02:00
|
|
|
$form = $this->createForm(Form::class, $data, [
|
|
|
|
'mode' => 'update',
|
|
|
|
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
|
|
|
'access' => $access,
|
|
|
|
]);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Récupération des data du formulaire
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
// Sur validation
|
2022-09-23 16:14:15 +02:00
|
|
|
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
|
|
|
$data = $form->getData();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Les groupes opé ne sont pas ouvert
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$data->isIsworkgroup()) {
|
|
|
|
$data->setIsopen(false);
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
$em->getManager()->flush();
|
|
|
|
|
|
|
|
// Retour à la liste
|
2022-09-23 16:14:15 +02:00
|
|
|
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Affichage du formulaire
|
|
|
|
return $this->render($this->twig.'edit.html.twig', [
|
2022-09-23 16:14:15 +02:00
|
|
|
'useheader' => true,
|
|
|
|
'usemenu' => false,
|
2022-10-02 14:50:48 +02:00
|
|
|
'usesidebar' => ('all' != $access),
|
2022-07-21 16:15:47 +02:00
|
|
|
$this->data => $data,
|
2022-09-23 16:14:15 +02:00
|
|
|
'mode' => 'update',
|
|
|
|
'access' => $access,
|
|
|
|
'form' => $form->createView(),
|
2022-10-02 14:50:48 +02:00
|
|
|
'maxsize' => ('all' == $access ? 1200 : null),
|
2022-07-21 16:15:47 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function delete($id, $access, Request $request, ManagerRegistry $em): Response
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Récupération de l'enregistrement courant
|
2022-09-23 16:14:15 +02:00
|
|
|
$data = $em->getRepository($this->entity)->find($id);
|
|
|
|
if (!$data) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Controler les permissions
|
2022-09-23 16:14:15 +02:00
|
|
|
$this->canupdate($access, $data, $em);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Tentative de suppression
|
2022-09-23 16:14:15 +02:00
|
|
|
try {
|
2022-07-21 16:15:47 +02:00
|
|
|
$em->getManager()->remove($data);
|
|
|
|
$em->getManager()->flush();
|
2022-09-23 16:14:15 +02:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
|
|
|
|
|
|
|
|
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function users($id, $access, Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
// Récupération de l'enregistrement courant
|
2022-09-23 16:14:15 +02:00
|
|
|
$data = $em->getRepository($this->entity)->find($id);
|
|
|
|
if (!$data) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Controler les permissions
|
2022-09-23 16:14:15 +02:00
|
|
|
$this->canseemember($access, $data, $em);
|
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Affichage du formulaire
|
|
|
|
return $this->render($this->twig.'users.html.twig', [
|
2022-09-23 16:14:15 +02:00
|
|
|
'useheader' => true,
|
|
|
|
'usemenu' => false,
|
2022-10-02 14:50:48 +02:00
|
|
|
'usesidebar' => ('all' != $access),
|
2022-09-23 16:14:15 +02:00
|
|
|
'access' => $access,
|
|
|
|
$this->data => $data,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function usersnotin($id, $access, Request $request, ManagerRegistry $em)
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Récupération de l'enregistrement courant
|
2022-09-23 16:14:15 +02:00
|
|
|
$group = $em->getRepository($this->entity)->find($id);
|
|
|
|
if (!$group) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Controler les permissions
|
2022-09-23 16:14:15 +02:00
|
|
|
$this->canseemember($access, $group, $em);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
$sub = $em->getManager()->createQueryBuilder();
|
2022-09-23 16:14:15 +02:00
|
|
|
$sub->select('usergroup');
|
|
|
|
$sub->from('App:UserGroup', 'usergroup');
|
2022-07-21 16:15:47 +02:00
|
|
|
$sub->andWhere('usergroup.user = user.id');
|
2022-09-23 16:14:15 +02:00
|
|
|
$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;
|
2022-09-27 11:52:49 +02:00
|
|
|
$niveau03 = null;
|
|
|
|
$niveau04 = null;
|
2022-09-23 15:34:07 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Nombre total d'enregistrement
|
|
|
|
$qb = $em->getManager()->createQueryBuilder();
|
2022-09-23 16:14:15 +02:00
|
|
|
switch ($access) {
|
|
|
|
case 'admin':
|
2022-07-21 16:15:47 +02:00
|
|
|
$qb->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
2022-10-02 14:50:48 +02:00
|
|
|
->andWhere('user.isactive=:isactive')
|
|
|
|
->setParameter('groupid', $id)
|
|
|
|
->setParameter('isactive', true);
|
2022-09-23 16:14:15 +02:00
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
case 'modo':
|
|
|
|
$usermodo = $this->getUser()->getId();
|
2022-07-21 16:15:47 +02:00
|
|
|
$qb->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
|
|
|
->from('App:UserModo', 'usermodo')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
2022-09-23 16:14:15 +02:00
|
|
|
->andWhere('usermodo.niveau01 = user.niveau01')
|
|
|
|
->andWhere('usermodo.user = :userid')
|
2022-10-02 14:50:48 +02:00
|
|
|
->andWhere('user.isactive=:isactive')
|
2022-09-23 16:14:15 +02:00
|
|
|
->setParameter('userid', $usermodo)
|
2022-10-02 14:50:48 +02:00
|
|
|
->setParameter('groupid', $id)
|
|
|
|
->setParameter('isactive', true);
|
2022-09-23 16:14:15 +02:00
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-10-02 14:50:48 +02:00
|
|
|
case 'all':
|
2022-09-23 16:14:15 +02:00
|
|
|
$niveau01 = $this->getUser()->getNiveau01();
|
|
|
|
$niveau02 = $this->getUser()->getNiveau02();
|
2022-09-27 11:52:49 +02:00
|
|
|
$niveau03 = $this->getUser()->getNiveau03();
|
|
|
|
$niveau04 = $this->getUser()->getNiveau04();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
$qb->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
2022-10-02 14:50:48 +02:00
|
|
|
->andWhere('user.isactive=:isactive')
|
|
|
|
->setParameter('groupid', $id)
|
|
|
|
->setParameter('isactive', true);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
switch ($request->getSession()->get('scopeannu')) {
|
2022-09-27 11:52:49 +02:00
|
|
|
case 1:
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-27 11:52:49 +02:00
|
|
|
case 2:
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
|
|
|
|
break;
|
2022-09-27 11:52:49 +02:00
|
|
|
|
|
|
|
case 3:
|
|
|
|
$qb->andWhere('user.niveau03 = :niveau03')->setParameter('niveau02', $niveau03);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
$qb->andWhere('user.niveau04 = :niveau04')->setParameter('niveau04', $niveau04);
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
$total = $qb->getQuery()->getSingleScalarResult();
|
|
|
|
$totalf = null;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Nombre d'enregistrement filtré
|
2022-09-23 16:14:15 +02:00
|
|
|
if ('' == $search['value']) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$totalf = $total;
|
2022-09-23 16:14:15 +02:00
|
|
|
} else {
|
|
|
|
switch ($access) {
|
|
|
|
case 'admin':
|
|
|
|
$totalf = $em->getManager()->createQueryBuilder()
|
2022-07-21 16:15:47 +02:00
|
|
|
->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where('user.username LIKE :value OR user.email LIKE :value')
|
|
|
|
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
2022-10-02 14:50:48 +02:00
|
|
|
->andWhere('user.isactive=:isactive')
|
2022-09-23 16:14:15 +02:00
|
|
|
->setParameter('value', '%'.$search['value'].'%')
|
|
|
|
->setParameter('groupid', $id)
|
2022-10-02 14:50:48 +02:00
|
|
|
->setParameter('isactive', true)
|
2022-07-21 16:15:47 +02:00
|
|
|
->getQuery()
|
|
|
|
->getSingleScalarResult();
|
2022-09-23 16:14:15 +02:00
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
case 'modo':
|
2022-07-21 16:15:47 +02:00
|
|
|
$totalf = $em->getManager()->createQueryBuilder()
|
|
|
|
->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
|
|
|
->from('App:UserModo', 'usermodo')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where('user.username LIKE :value OR user.email LIKE :value')
|
|
|
|
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
2022-09-23 16:14:15 +02:00
|
|
|
->andWhere('usermodo.niveau01 = user.niveau01')
|
|
|
|
->andWhere('usermodo.user = :userid')
|
2022-10-02 14:50:48 +02:00
|
|
|
->andWhere('user.isactive=:isactive')
|
2022-09-23 16:14:15 +02:00
|
|
|
->setParameter('userid', $usermodo)
|
|
|
|
->setParameter('value', '%'.$search['value'].'%')
|
|
|
|
->setParameter('groupid', $id)
|
2022-10-02 14:50:48 +02:00
|
|
|
->setParameter('isactive', true)
|
2022-07-21 16:15:47 +02:00
|
|
|
->getQuery()
|
|
|
|
->getSingleScalarResult();
|
2022-09-23 16:14:15 +02:00
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-10-02 14:50:48 +02:00
|
|
|
case 'all':
|
2022-07-21 16:15:47 +02:00
|
|
|
$qb = $em->getManager()->createQueryBuilder()
|
|
|
|
->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where('user.username LIKE :value OR user.email LIKE :value')
|
|
|
|
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
2022-10-02 14:50:48 +02:00
|
|
|
->andWhere('user.isactive=:isactive')
|
2022-09-23 16:14:15 +02:00
|
|
|
->setParameter('value', '%'.$search['value'].'%')
|
2022-10-02 14:50:48 +02:00
|
|
|
->setParameter('groupid', $id)
|
|
|
|
->setParameter('isactive', true);
|
2022-09-23 16:14:15 +02:00
|
|
|
|
|
|
|
switch ($request->getSession()->get('scopeannu')) {
|
2022-09-27 11:52:49 +02:00
|
|
|
case 1:
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
|
2022-07-21 16:15:47 +02:00
|
|
|
break;
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-09-27 11:52:49 +02:00
|
|
|
case 2:
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
|
2022-07-21 16:15:47 +02:00
|
|
|
break;
|
2022-09-27 11:52:49 +02:00
|
|
|
|
|
|
|
case 3:
|
|
|
|
$qb->andWhere('user.niveau03 = :niveau03')->setParameter('niveau02', $niveau03);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
$qb->andWhere('user.niveau04 = :niveau04')->setParameter('niveau04', $niveau04);
|
|
|
|
break;
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$totalf = $qb->getQuery()->getSingleScalarResult();
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construction du tableau de retour
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = [
|
2022-07-21 16:15:47 +02:00
|
|
|
'draw' => $draw,
|
|
|
|
'recordsFiltered' => $totalf,
|
|
|
|
'recordsTotal' => $total,
|
2022-09-23 16:14:15 +02:00
|
|
|
'data' => [],
|
|
|
|
];
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Parcours des Enregistrement
|
|
|
|
$qb = $em->getManager()->createQueryBuilder();
|
2022-10-02 14:50:48 +02:00
|
|
|
$qb->select('user')->from('App:User', 'user')->Where('user.isactive=:isactive')->setParameter('isactive', true);
|
2022-09-23 16:14:15 +02:00
|
|
|
|
|
|
|
switch ($access) {
|
|
|
|
case 'admin':
|
2022-10-02 14:50:48 +02:00
|
|
|
$qb->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
|
2022-09-23 16:14:15 +02:00
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
case 'modo':
|
|
|
|
$qb->from('App:UserModo', 'usermodo')
|
2022-10-02 14:50:48 +02:00
|
|
|
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
2022-09-23 16:14:15 +02:00
|
|
|
->andWhere('usermodo.niveau01 = user.niveau01')
|
|
|
|
->andWhere('usermodo.user = :userid')
|
|
|
|
->setParameter('userid', $usermodo);
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-10-02 14:50:48 +02:00
|
|
|
case 'all':
|
|
|
|
$qb->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
|
2022-09-23 16:14:15 +02:00
|
|
|
switch ($request->getSession()->get('scopeannu')) {
|
2022-09-27 11:52:49 +02:00
|
|
|
case 1:
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
|
|
|
|
break;
|
|
|
|
|
2022-09-27 11:52:49 +02:00
|
|
|
case 2:
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
|
|
|
|
break;
|
2022-09-27 11:52:49 +02:00
|
|
|
|
|
|
|
case 3:
|
|
|
|
$qb->andWhere('user.niveau03 = :niveau03')->setParameter('niveau02', $niveau03);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
$qb->andWhere('user.niveau04 = :niveau04')->setParameter('niveau04', $niveau04);
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
if ('' != $search['value']) {
|
|
|
|
$qb->andWhere('user.username LIKE :value OR user.email LIKE :value')
|
|
|
|
->setParameter('value', '%'.$search['value'].'%');
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->setParameter('groupid', $id);
|
|
|
|
switch ($ordercolumn) {
|
|
|
|
case 2:
|
|
|
|
$qb->orderBy('user.username', $orderdir);
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
case 3:
|
|
|
|
$qb->orderBy('user.email', $orderdir);
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
|
|
|
$canupdatemember = $this->canupdatemember($access, $group, $em, false);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
foreach ($datas as $data) {
|
2022-07-21 16:15:47 +02:00
|
|
|
// Action
|
2022-09-23 16:14:15 +02:00
|
|
|
$action = '';
|
|
|
|
if ($canupdatemember) {
|
|
|
|
$action .= "<a style='cursor:pointer' onClick='addUsers(".$data->getId().")'><i class='fa fa-plus fa-fw'></i></a>";
|
|
|
|
}
|
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Avatar
|
2022-09-23 16:14:15 +02:00
|
|
|
$avatar = "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getAvatar()])."' class='avatar'>";
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
array_push($output['data'], ['DT_RowId' => 'user'.$data->getId(), $action, $avatar, $data->getUsername(), $data->getEmail(), '', '']);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retour
|
|
|
|
return new JsonResponse($output);
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function usersin($id, $access, Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
// Récupération de l'enregistrement courant
|
2022-09-23 16:14:15 +02:00
|
|
|
$group = $em->getRepository($this->entity)->find($id);
|
|
|
|
if (!$group) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Controler les permissions
|
2022-09-23 16:14:15 +02:00
|
|
|
$this->canseemember($access, $group, $em);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
$sub = $em->getManager()->createQueryBuilder();
|
2022-09-23 16:14:15 +02:00
|
|
|
$sub->select('usergroup');
|
|
|
|
$sub->from('App:UserGroup', 'usergroup');
|
2022-07-21 16:15:47 +02:00
|
|
|
$sub->andWhere('usergroup.user = user.id');
|
2022-09-23 16:14:15 +02:00
|
|
|
$sub->andWhere('usergroup.group = :groupid');
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$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;
|
2022-09-23 15:34:07 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
// Nombre total d'enregistrement
|
|
|
|
$qb = $em->getManager()->createQueryBuilder();
|
2022-10-02 14:50:48 +02:00
|
|
|
if ('admin' == $access || 'all' == $access) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$qb->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where($qb->expr()->exists($sub->getDQL()))
|
2022-09-23 16:14:15 +02:00
|
|
|
->setParameter('groupid', $id);
|
|
|
|
} else {
|
|
|
|
$usermodo = $this->getUser()->getId();
|
2022-07-21 16:15:47 +02:00
|
|
|
$qb->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
|
|
|
->from('App:UserModo', 'usermodo')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where($qb->expr()->exists($sub->getDQL()))
|
2022-09-23 16:14:15 +02:00
|
|
|
->andWhere('usermodo.niveau01 = user.niveau01')
|
|
|
|
->andWhere('usermodo.user = :userid')
|
|
|
|
->setParameter('userid', $usermodo)
|
|
|
|
->setParameter('groupid', $id);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
$total = $qb->getQuery()->getSingleScalarResult();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Nombre d'enregistrement filtré
|
2022-09-23 16:14:15 +02:00
|
|
|
if ('' == $search['value']) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$totalf = $total;
|
2022-09-23 16:14:15 +02:00
|
|
|
} else {
|
2022-10-02 14:50:48 +02:00
|
|
|
if ('admin' == $access || 'all' == $access) {
|
2022-09-23 16:14:15 +02:00
|
|
|
$totalf = $em->getManager()->createQueryBuilder()
|
2022-07-21 16:15:47 +02:00
|
|
|
->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where('user.username LIKE :value OR user.email LIKE :value')
|
|
|
|
->andWhere($qb->expr()->exists($sub->getDQL()))
|
2022-09-23 16:14:15 +02:00
|
|
|
->setParameter('value', '%'.$search['value'].'%')
|
|
|
|
->setParameter('groupid', $id)
|
2022-07-21 16:15:47 +02:00
|
|
|
->getQuery()
|
|
|
|
->getSingleScalarResult();
|
2022-09-23 16:14:15 +02:00
|
|
|
} else {
|
|
|
|
$totalf = $em->getManager()->createQueryBuilder()
|
2022-07-21 16:15:47 +02:00
|
|
|
->select('COUNT(user)')
|
2022-09-23 16:14:15 +02:00
|
|
|
->from('App:User', 'user')
|
|
|
|
->from('App:UserModo', 'usermodo')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where('user.username LIKE :value OR user.email LIKE :value')
|
|
|
|
->andWhere($qb->expr()->exists($sub->getDQL()))
|
2022-09-23 16:14:15 +02:00
|
|
|
->andWhere('usermodo.niveau01 = user.niveau01')
|
|
|
|
->andWhere('usermodo.user = :userid')
|
|
|
|
->setParameter('userid', $usermodo)
|
|
|
|
->setParameter('value', '%'.$search['value'].'%')
|
|
|
|
->setParameter('groupid', $id)
|
2022-07-21 16:15:47 +02:00
|
|
|
->getQuery()
|
|
|
|
->getSingleScalarResult();
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Construction du tableau de retour
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = [
|
2022-07-21 16:15:47 +02:00
|
|
|
'draw' => $draw,
|
|
|
|
'recordsFiltered' => $totalf,
|
|
|
|
'recordsTotal' => $total,
|
2022-09-23 16:14:15 +02:00
|
|
|
'data' => [],
|
|
|
|
];
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Parcours des Enregistrement
|
|
|
|
$qb = $em->getManager()->createQueryBuilder();
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->select('user')->from('App:User', 'user');
|
|
|
|
|
2022-10-02 14:50:48 +02:00
|
|
|
if ('admin' == $access || 'all' == $access) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$qb->where($qb->expr()->exists($sub->getDQL()));
|
2022-09-23 16:14:15 +02:00
|
|
|
} else {
|
|
|
|
$qb->from('App:UserModo', 'usermodo')
|
2022-07-21 16:15:47 +02:00
|
|
|
->where($qb->expr()->exists($sub->getDQL()))
|
2022-09-23 16:14:15 +02:00
|
|
|
->andWhere('usermodo.niveau01 = user.niveau01')
|
|
|
|
->andWhere('usermodo.user = :userid')
|
|
|
|
->setParameter('userid', $usermodo);
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
if ('' != $search['value']) {
|
|
|
|
$qb->andWhere('user.username LIKE :value OR user.email LIKE :value')
|
|
|
|
->setParameter('value', '%'.$search['value'].'%');
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
$qb->setParameter('groupid', $id);
|
|
|
|
switch ($ordercolumn) {
|
|
|
|
case 2:
|
|
|
|
$qb->orderBy('user.username', $orderdir);
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
case 3:
|
|
|
|
$qb->orderBy('user.email', $orderdir);
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
|
|
|
|
|
|
|
foreach ($datas as $data) {
|
2022-07-21 16:15:47 +02:00
|
|
|
// Propriétaire
|
2022-09-23 16:14:15 +02:00
|
|
|
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $data->getId(), 'group' => $id]);
|
|
|
|
$fgproprio = ($usergroup->getUser() == $group->getOwner());
|
|
|
|
$fgme = ($usergroup->getUser() == $this->getUser() && 'admin' != $access);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Action
|
2022-09-23 16:14:15 +02:00
|
|
|
$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>";
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Avatar
|
2022-09-23 16:14:15 +02:00
|
|
|
$avatar = "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getAvatar()])."' class='avatar'>";
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// Flag manager
|
2022-09-23 16:14:15 +02:00
|
|
|
$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>';
|
|
|
|
} else {
|
|
|
|
$rolegroup = (0 == $usergroup->getRolegroup() ? 'Utilisateur' : (50 == $usergroup->getRolegroup() ? 'Collaborateur' : 'Gestionnaire'));
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-10-02 14:50:48 +02:00
|
|
|
$tmp = ['DT_RowId' => 'user'.$data->getId(), $action, $avatar, $data->getUsername().(!$data->isIsactive() ? '<br><small><i>Inactif</i></small>' : ''), $data->getEmail(), $rolegroup];
|
2022-09-23 16:14:15 +02:00
|
|
|
array_push($output['data'], $tmp);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retour
|
|
|
|
return new JsonResponse($output);
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function useradd($groupid, $userid, $access, Request $request, ManagerRegistry $em)
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Récupération de l'enregistrement courant
|
2022-09-23 16:14:15 +02:00
|
|
|
$group = $em->getRepository($this->entity)->find($groupid);
|
|
|
|
if (!$group) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$user = $em->getRepository("App\Entity\User")->find($userid);
|
|
|
|
if (!$user) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = [];
|
|
|
|
$this->canupdatemember($access, $group, $em, true);
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
|
|
|
if ($usergroup) {
|
|
|
|
return new JsonResponse($output);
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$usergroup = new UserGroup();
|
2022-07-21 16:15:47 +02:00
|
|
|
$usergroup->setUser($user);
|
|
|
|
$usergroup->setGroup($group);
|
|
|
|
$usergroup->setApikey(Uuid::uuid4());
|
|
|
|
$usergroup->setRolegroup(0);
|
|
|
|
$em->getManager()->persist($usergroup);
|
|
|
|
$em->getManager()->flush();
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
// Retour
|
2022-07-21 16:15:47 +02:00
|
|
|
return new JsonResponse($output);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function userdel($groupid, $userid, $access, Request $request, ManagerRegistry $em)
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Récupération de l'enregistrement courant
|
2022-09-23 16:14:15 +02:00
|
|
|
$group = $em->getRepository($this->entity)->find($groupid);
|
|
|
|
if (!$group) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$user = $em->getRepository("App\Entity\User")->find($userid);
|
|
|
|
if (!$user) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = [];
|
|
|
|
$this->canupdatemember($access, $group, $em, true);
|
|
|
|
if ($user == $group->getOwner()) {
|
|
|
|
throw $this->createAccessDeniedException('Permission denied');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
|
|
|
if ($usergroup) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$em->getManager()->remove($usergroup);
|
|
|
|
$em->getManager()->flush();
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
// Retour
|
2022-07-21 16:15:47 +02:00
|
|
|
return new JsonResponse($output);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function userchangerole($groupid, $userid, $roleid, $access, Request $request, ManagerRegistry $em)
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Récupération de l'enregistrement courant
|
2022-09-23 16:14:15 +02:00
|
|
|
$group = $em->getRepository($this->entity)->find($groupid);
|
|
|
|
if (!$group) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$user = $em->getRepository("App\Entity\User")->find($userid);
|
|
|
|
if (!$user) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = [];
|
|
|
|
$this->canupdatemember($access, $group, $em, true);
|
|
|
|
if ($user == $group->getOwner()) {
|
|
|
|
throw $this->createAccessDeniedException('Permission denied');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
|
|
|
if ($usergroup) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$usergroup->setRolegroup($roleid);
|
|
|
|
$em->getManager()->persist($usergroup);
|
|
|
|
$em->getManager()->flush();
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
// Retour
|
2022-07-21 16:15:47 +02:00
|
|
|
return new JsonResponse($output);
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
public function userout($id, $access, Request $request, ManagerRegistry $em)
|
2022-07-21 16:15:47 +02:00
|
|
|
{
|
|
|
|
// Récupération de l'enregistrement courant
|
2022-09-23 16:14:15 +02:00
|
|
|
$group = $em->getRepository($this->entity)->find($id);
|
|
|
|
if (!$group) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
// On ne peut se désinscrire que si le groupe est ouvert et qu'il n'est pas lié à un groupe ldap ou sso
|
2022-09-23 16:14:15 +02:00
|
|
|
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) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$em->getManager()->remove($usergroup);
|
|
|
|
$em->getManager()->flush();
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-27 11:52:49 +02:00
|
|
|
private function cansubmit($access, $request)
|
2022-09-23 16:14:15 +02:00
|
|
|
{
|
|
|
|
switch ($access) {
|
|
|
|
case 'admin': return true;
|
|
|
|
break;
|
2022-09-27 11:52:49 +02:00
|
|
|
case 'modo': return false;
|
|
|
|
break;
|
2022-10-02 14:50:48 +02:00
|
|
|
case 'all': return $request->getSession()->get('submitgroup');
|
2022-09-23 16:14:15 +02:00
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
throw $this->createAccessDeniedException('Permission denied');
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
private function canupdate($access, $entity, $em, $fgblock = true)
|
|
|
|
{
|
|
|
|
$toreturn = false;
|
|
|
|
switch ($access) {
|
|
|
|
case 'admin': $toreturn = ($entity->getId() > 0);
|
|
|
|
break;
|
2022-10-02 14:50:48 +02:00
|
|
|
case 'all':
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$entity->isIsworkgroup() || $entity->getOwner() != $this->getUser()) {
|
|
|
|
$toreturn = false;
|
|
|
|
} else {
|
|
|
|
$toreturn = true;
|
|
|
|
}
|
|
|
|
break;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
if ($fgblock && !$toreturn) {
|
|
|
|
throw $this->createAccessDeniedException('Permission denied');
|
|
|
|
}
|
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
return $toreturn;
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
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;
|
2022-10-02 14:50:48 +02:00
|
|
|
case 'all':
|
2022-09-23 16:14:15 +02:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
return $toreturn;
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
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;
|
2022-10-02 14:50:48 +02:00
|
|
|
case 'all':
|
2022-09-23 16:14:15 +02:00
|
|
|
$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');
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
return $toreturn;
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
|
|
|
}
|