2022-07-21 16:15:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
use Doctrine\Persistence\ManagerRegistry;
|
2022-07-21 16:15:47 +02:00
|
|
|
use FOS\RestBundle\Controller\AbstractFOSRestController;
|
|
|
|
use FOS\RestBundle\Controller\Annotations as FOSRest;
|
|
|
|
use OpenApi\Annotations as OA;
|
2022-09-23 16:14:15 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
class RestController extends AbstractFOSRestController
|
|
|
|
{
|
2022-09-23 16:14:15 +02:00
|
|
|
private $output = [];
|
2022-07-21 16:15:47 +02:00
|
|
|
private $cpt;
|
|
|
|
|
|
|
|
/**
|
2022-09-23 16:14:15 +02:00
|
|
|
* getAllUsers.
|
2022-07-21 16:15:47 +02:00
|
|
|
*
|
2022-09-23 16:14:15 +02:00
|
|
|
* @FOSRest\Get("/rest/getAllUsers")
|
2022-07-21 16:15:47 +02:00
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get all users"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
2022-09-23 16:14:15 +02:00
|
|
|
public function getAllUsers(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
2022-09-23 16:14:15 +02:00
|
|
|
$users = $em->getRepository("App\Entity\User")->findAll();
|
|
|
|
foreach ($users as $user) {
|
|
|
|
array_push($output, $this->userFormat($user));
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$view = $this->view($output, 200);
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
/**
|
2022-09-23 16:14:15 +02:00
|
|
|
* getOneUser.
|
2022-07-21 16:15:47 +02:00
|
|
|
*
|
2022-09-23 16:14:15 +02:00
|
|
|
* @FOSRest\Get("/rest/getOneUser")
|
2022-07-21 16:15:47 +02:00
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get one user by login"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="login",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="Login",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
2022-09-23 16:14:15 +02:00
|
|
|
public function getOneUser(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
2022-09-23 16:14:15 +02:00
|
|
|
$user = $em->getRepository("App\Entity\User")->findOneBy(['username' => $request->headers->get('login')]);
|
|
|
|
if (!$user) {
|
|
|
|
$view = $this->view('Utilisateur inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = $this->userFormat($user);
|
2022-07-21 16:15:47 +02:00
|
|
|
$view = $this->view($output, 200);
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
/**
|
2022-09-23 16:14:15 +02:00
|
|
|
* getAllNiveau01s.
|
2022-07-21 16:15:47 +02:00
|
|
|
*
|
2022-09-23 16:14:15 +02:00
|
|
|
* @FOSRest\Get("/rest/getAllNiveau01s")
|
2022-07-21 16:15:47 +02:00
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get all niveau01"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
2022-09-23 16:14:15 +02:00
|
|
|
public function getAllNiveau01s(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
2022-09-23 16:14:15 +02:00
|
|
|
$niveau01s = $em->getRepository("App\Entity\Niveau01")->findAll();
|
|
|
|
foreach ($niveau01s as $niveau01) {
|
|
|
|
array_push($output, $this->niveau01Format($niveau01, true));
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$view = $this->view($output, 200);
|
2022-09-23 16:14:15 +02:00
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-23 16:14:15 +02:00
|
|
|
* getOneNiveau01.
|
2022-07-21 16:15:47 +02:00
|
|
|
*
|
2022-09-23 16:14:15 +02:00
|
|
|
* @FOSRest\Get("/rest/getOneNiveau01")
|
2022-07-21 16:15:47 +02:00
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get one niveau01 by label"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="label",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="Label",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
2022-09-23 16:14:15 +02:00
|
|
|
public function getOneNiveau01(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
2022-09-23 16:14:15 +02:00
|
|
|
$niveau01 = $em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $request->headers->get('label')]);
|
|
|
|
if (!$niveau01) {
|
|
|
|
$view = $this->view('Niveau01 inconnu', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = $this->niveau01Format($niveau01, true);
|
2022-07-21 16:15:47 +02:00
|
|
|
$view = $this->view($output, 200);
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
|
|
|
/**
|
2022-09-23 16:14:15 +02:00
|
|
|
* getAllNiveau02s.
|
2022-07-21 16:15:47 +02:00
|
|
|
*
|
2022-09-23 16:14:15 +02:00
|
|
|
* @FOSRest\Get("/rest/getAllNiveau02s")
|
2022-07-21 16:15:47 +02:00
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get all niveau02"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
2022-09-23 16:14:15 +02:00
|
|
|
public function getAllNiveau02s(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
2022-09-23 16:14:15 +02:00
|
|
|
$niveau02s = $em->getRepository("App\Entity\Niveau02")->findAll();
|
|
|
|
foreach ($niveau02s as $niveau02) {
|
|
|
|
array_push($output, $this->niveau02Format($niveau02, true));
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$view = $this->view($output, 200);
|
2022-09-23 16:14:15 +02:00
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-23 16:14:15 +02:00
|
|
|
* getOneNiveau02.
|
2022-07-21 16:15:47 +02:00
|
|
|
*
|
2022-09-23 16:14:15 +02:00
|
|
|
* @FOSRest\Get("/rest/getOneNiveau02")
|
2022-07-21 16:15:47 +02:00
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get one niveau02 by label"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="label",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="Label",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
2022-09-23 16:14:15 +02:00
|
|
|
public function getOneNiveau02(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
2022-09-23 16:14:15 +02:00
|
|
|
$niveau02 = $em->getRepository("App\Entity\Niveau02")->findOneBy(['label' => $request->headers->get('label')]);
|
|
|
|
if (!$niveau02) {
|
|
|
|
$view = $this->view('Niveau02 inconnu', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = $this->niveau02Format($niveau02, true);
|
2022-07-21 16:15:47 +02:00
|
|
|
$view = $this->view($output, 200);
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-27 11:52:49 +02:00
|
|
|
/**
|
|
|
|
* getAllNiveau03s.
|
|
|
|
*
|
|
|
|
* @FOSRest\Get("/rest/getAllNiveau03s")
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get all niveau03"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function getAllNiveau03s(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
$niveau03s = $em->getRepository("App\Entity\Niveau03")->findAll();
|
|
|
|
foreach ($niveau03s as $niveau03) {
|
|
|
|
array_push($output, $this->niveau03Format($niveau03, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
$view = $this->view($output, 200);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getOneNiveau03.
|
|
|
|
*
|
|
|
|
* @FOSRest\Get("/rest/getOneNiveau03")
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get one niveau03 by label"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="label",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="Label",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function getOneNiveau03(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
$niveau03 = $em->getRepository("App\Entity\Niveau03")->findOneBy(['label' => $request->headers->get('label')]);
|
|
|
|
if (!$niveau03) {
|
|
|
|
$view = $this->view('Niveau03 inconnu', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = $this->niveau03Format($niveau03, true);
|
|
|
|
$view = $this->view($output, 200);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getAllNiveau04s.
|
|
|
|
*
|
|
|
|
* @FOSRest\Get("/rest/getAllNiveau04s")
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get all niveau04"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function getAllNiveau04s(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
$niveau04s = $em->getRepository("App\Entity\Niveau04")->findAll();
|
|
|
|
foreach ($niveau04s as $niveau04) {
|
|
|
|
array_push($output, $this->niveau04Format($niveau04, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
$view = $this->view($output, 200);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getOneNiveau04.
|
|
|
|
*
|
|
|
|
* @FOSRest\Get("/rest/getOneNiveau04")
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get one niveau04 by label"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="label",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="Label",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function getOneNiveau04(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
$niveau04 = $em->getRepository("App\Entity\Niveau04")->findOneBy(['label' => $request->headers->get('label')]);
|
|
|
|
if (!$niveau04) {
|
|
|
|
$view = $this->view('Niveau04 inconnu', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = $this->niveau04Format($niveau04, true);
|
|
|
|
$view = $this->view($output, 200);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
/**
|
2022-09-23 16:14:15 +02:00
|
|
|
* getAllGroups.
|
2022-07-21 16:15:47 +02:00
|
|
|
*
|
2022-09-23 16:14:15 +02:00
|
|
|
* @FOSRest\Get("/rest/getAllGroups")
|
2022-07-21 16:15:47 +02:00
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get all group"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
2022-09-23 16:14:15 +02:00
|
|
|
public function getAllGroups(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
2022-09-23 16:14:15 +02:00
|
|
|
$groups = $em->getRepository("App\Entity\Group")->findAll();
|
|
|
|
foreach ($groups as $group) {
|
|
|
|
if ($group->getId() < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
array_push($output, $this->groupFormat($group, true));
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$view = $this->view($output, 200);
|
2022-09-23 16:14:15 +02:00
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-23 16:14:15 +02:00
|
|
|
* getOneGroup.
|
2022-07-21 16:15:47 +02:00
|
|
|
*
|
2022-09-23 16:14:15 +02:00
|
|
|
* @FOSRest\Get("/rest/getOneGroup")
|
2022-07-21 16:15:47 +02:00
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="get one group by label"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="key",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="APIKey",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="label",
|
|
|
|
* in="header",
|
|
|
|
* required=true,
|
|
|
|
* description="Label",
|
|
|
|
* @OA\Schema(type="string")
|
|
|
|
* )
|
|
|
|
*/
|
2022-09-23 16:14:15 +02:00
|
|
|
public function getOneGroup(Request $request, ManagerRegistry $em)
|
|
|
|
{
|
2022-07-21 16:15:47 +02:00
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
// Récupération des parametres
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!$this->iskey($request->headers->get('key'))) {
|
|
|
|
$view = $this->view('API Key inconnue', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
2022-09-23 16:14:15 +02:00
|
|
|
$group = $em->getRepository("App\Entity\Group")->findOneBy(['label' => $request->headers->get('label')]);
|
|
|
|
if (!$group) {
|
|
|
|
$view = $this->view('Group inconnu', 403);
|
|
|
|
|
|
|
|
return $this->handleView($view);
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
$output = $this->groupFormat($group, true);
|
2022-07-21 16:15:47 +02:00
|
|
|
$view = $this->view($output, 200);
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
return $this->handleView($view);
|
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
private function iskey($key)
|
|
|
|
{
|
|
|
|
return $key == $this->getParameter('appSecret');
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
private function userFormat($user)
|
|
|
|
{
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
$output['userid'] = $user->getId();
|
|
|
|
$output['userlogin'] = $user->getUsername();
|
|
|
|
$output['userlastname'] = $user->getLastname();
|
|
|
|
$output['userfirstname'] = $user->getFirstname();
|
|
|
|
$output['useremail'] = $user->getEmail();
|
|
|
|
$output['userjob'] = $user->getJob();
|
|
|
|
$output['userposition'] = $user->getPosition();
|
|
|
|
$output['userpostaladress'] = $user->getPostaladress();
|
|
|
|
$output['usertelephonenumber'] = $user->getTelephonenumber();
|
|
|
|
$output['useravatar'] = 'https://'.str_replace('//', '/', $this->getParameter('appWeburl').$this->getParameter('appAlias').$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$user->getAvatar()], true));
|
|
|
|
$output['userniveau01'] = $this->niveau01Format($user->getNiveau01());
|
|
|
|
$output['userniveau02'] = $this->niveau02Format($user->getNiveau02());
|
2022-09-27 11:52:49 +02:00
|
|
|
$output['userniveau03'] = $this->niveau03Format($user->getNiveau03());
|
|
|
|
$output['userniveau04'] = $this->niveau03Format($user->getNiveau04());
|
2022-09-23 16:14:15 +02:00
|
|
|
$output['usergroups'] = [];
|
|
|
|
foreach ($user->getGroups() as $usergroup) {
|
|
|
|
$groupFormat = $this->groupFormat($usergroup->getGroup());
|
|
|
|
if ($groupFormat) {
|
|
|
|
array_push($output['usergroups'], $groupFormat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (empty($output['usergroups'])) {
|
|
|
|
$output['usergroups'] = null;
|
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 $output;
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
private function niveau01Format($niveau01, $withmembers = false)
|
|
|
|
{
|
|
|
|
if (!$niveau01) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$output = [];
|
|
|
|
$output['niveau01id'] = $niveau01->getId();
|
|
|
|
$output['niveau01label'] = $niveau01->getLabel();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
if ($withmembers) {
|
|
|
|
$output['niveau01users'] = [];
|
|
|
|
foreach ($niveau01->getUsers() as $user) {
|
|
|
|
array_push($output['niveau01users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]);
|
|
|
|
}
|
|
|
|
if (empty($output['niveau01users'])) {
|
|
|
|
$output['niveau01users'] = null;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
private function niveau02Format($niveau02, $withmembers = false)
|
|
|
|
{
|
|
|
|
if (!$niveau02) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$output = [];
|
|
|
|
$output['niveau02id'] = $niveau02->getId();
|
|
|
|
$output['niveau02label'] = $niveau02->getLabel();
|
|
|
|
|
|
|
|
if ($withmembers) {
|
|
|
|
$output['niveau02niveau01'] = $this->niveau01Format($niveau02->getNiveau01());
|
|
|
|
$output['niveau02users'] = [];
|
|
|
|
foreach ($niveau02->getUsers() as $user) {
|
|
|
|
array_push($output['niveau02users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]);
|
|
|
|
}
|
|
|
|
if (empty($output['niveau02users'])) {
|
|
|
|
$output['niveau02users'] = null;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2022-09-27 11:52:49 +02:00
|
|
|
private function niveau03Format($niveau03, $withmembers = false)
|
|
|
|
{
|
|
|
|
if (!$niveau03) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$output = [];
|
|
|
|
$output['niveau03id'] = $niveau03->getId();
|
|
|
|
$output['niveau03label'] = $niveau03->getLabel();
|
|
|
|
|
|
|
|
if ($withmembers) {
|
|
|
|
$output['niveau03niveau01'] = $this->niveau01Format($niveau03->getNiveau02()->getNiveau01());
|
|
|
|
$output['niveau03niveau02'] = $this->niveau02Format($niveau03->getNiveau02());
|
|
|
|
$output['niveau03users'] = [];
|
|
|
|
foreach ($niveau03->getUsers() as $user) {
|
|
|
|
array_push($output['niveau03users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]);
|
|
|
|
}
|
|
|
|
if (empty($output['niveau03users'])) {
|
|
|
|
$output['niveau03users'] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function niveau04Format($niveau04, $withmembers = false)
|
|
|
|
{
|
|
|
|
if (!$niveau04) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$output = [];
|
|
|
|
$output['niveau04id'] = $niveau04->getId();
|
|
|
|
$output['niveau04label'] = $niveau04->getLabel();
|
|
|
|
|
|
|
|
if ($withmembers) {
|
|
|
|
$output['niveau04niveau01'] = $this->niveau01Format($niveau04->getNiveau03()->getNiveau02()->getNiveau01());
|
|
|
|
$output['niveau04niveau02'] = $this->niveau02Format($niveau04->getNiveau03()->getNiveau02());
|
|
|
|
$output['niveau04niveau03'] = $this->niveau02Format($niveau04->getNiveau03());
|
|
|
|
$output['niveau04users'] = [];
|
|
|
|
foreach ($niveau04->getUsers() as $user) {
|
|
|
|
array_push($output['niveau04users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]);
|
|
|
|
}
|
|
|
|
if (empty($output['niveau04users'])) {
|
|
|
|
$output['niveau04users'] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
private function groupFormat($group, $withmembers = false)
|
|
|
|
{
|
|
|
|
if (!$group || $group->getId() < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$output = [];
|
|
|
|
$output['groupid'] = $group->getId();
|
|
|
|
$output['grouplabel'] = $group->getLabel();
|
2022-07-21 16:15:47 +02:00
|
|
|
|
2022-09-23 16:14:15 +02:00
|
|
|
if ($withmembers) {
|
|
|
|
$output['groupusers'] = [];
|
|
|
|
foreach ($group->getUsers() as $usergroup) {
|
|
|
|
array_push($output['groupusers'], ['userid' => $usergroup->getUser()->getId(), 'userlogin' => $usergroup->getUser()->getUsername()]);
|
|
|
|
}
|
|
|
|
if (empty($output['groupusers'])) {
|
|
|
|
$output['groupusers'] = null;
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|