rest users & groups

This commit is contained in:
afornerot 2020-07-03 10:30:41 +02:00
parent 151be1a66e
commit f4325bfb4f
2 changed files with 72 additions and 4 deletions

View File

@ -66,7 +66,7 @@ class RestController extends Controller
// Construction de la réponse // Construction de la réponse
$output["user"]["firstname"] = $user->getFirstname(); $output["user"]["firstname"] = $user->getFirstname();
$output["user"]["lasttname"] = $user->getLastname(); $output["user"]["lastname"] = $user->getLastname();
$output["user"]["email"] = $user->getEmail(); $output["user"]["email"] = $user->getEmail();
$output["user"]["avatar"] = $weburl."uploads/avatar/".$user->getAvatar(); $output["user"]["avatar"] = $weburl."uploads/avatar/".$user->getAvatar();
$output["user"]["niveau01"] = $user->getNiveau01()->getLabel(); $output["user"]["niveau01"] = $user->getNiveau01()->getLabel();
@ -127,10 +127,70 @@ class RestController extends Controller
} }
} }
// Retour
return new Response(json_encode($output), 200);
}
public function usersAction($key, Request $request)
{
// Vérification de la clé
$realkey = $this->getParameter("apikeyninegate");
if($key!=$realkey) {
$output["error"]="error key";
return new Response(json_encode($output), 400);
}
$weburl="https://".$this->getParameter("weburl")."/".$this->getParameter("alias")."/";
$em = $this->getDoctrine()->getManager();
$output = [];
$users=$em->getRepository('CadolesCoreBundle:User')->findAll();
foreach($users as $user) {
// Construction de la réponse
$output[$user->getId()]["id"] = $user->getId();
$output[$user->getId()]["username"] = $user->getUsername();
$output[$user->getId()]["firstname"] = $user->getFirstname();
$output[$user->getId()]["lastname"] = $user->getLastname();
$output[$user->getId()]["email"] = $user->getEmail();
$output[$user->getId()]["avatar"] = $weburl."uploads/avatar/".$user->getAvatar();
}
// Retour // Retour
return new Response(json_encode($output), 200); return new Response(json_encode($output), 200);
} }
public function groupsAction($key, Request $request)
{
// Vérification de la clé
$realkey = $this->getParameter("apikeyninegate");
if($key!=$realkey) {
$output["error"]="error key";
return new Response(json_encode($output), 400);
}
$em = $this->getDoctrine()->getManager();
$output = [];
$groups=$em->getRepository('CadolesCoreBundle:Group')->findAll();
foreach($groups as $group) {
// Construction de la réponse
$output[$group->getId()]["id"] = $group->getId();
$output[$group->getId()]["name"] = $group->getLabel();
$output[$group->getId()]["users"] = [];
$usergroups=$group->getUsers();
foreach($usergroups as $usergroup) {
$user=$usergroup->getUser();
$output[$group->getId()]["users"][$user->getId()]["id"]=$user->getId();
$output[$group->getId()]["users"][$user->getId()]["username"]=$user->getUsername();
}
}
// Retour
return new Response(json_encode($output), 200);
}
} }

View File

@ -495,3 +495,11 @@ cadoles_core_config_statistic:
cadoles_core_rest_user: cadoles_core_rest_user:
path: /rest/user/{key}/{login} path: /rest/user/{key}/{login}
defaults: { _controller: CadolesCoreBundle:Rest:user } defaults: { _controller: CadolesCoreBundle:Rest:user }
cadoles_core_rest_users:
path: /rest/users/{key}
defaults: { _controller: CadolesCoreBundle:Rest:users }
cadoles_core_rest_groups:
path: /rest/groups/{key}
defaults: { _controller: CadolesCoreBundle:Rest:groups }