2016-07-14 08:16:11 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
namespace viewer\view\group;
|
|
|
|
use \viewer\core\Viewer;
|
2017-01-30 17:39:21 +00:00
|
|
|
use \api\core\Request;
|
|
|
|
use \error\core\Err;
|
2016-10-18 17:09:47 +00:00
|
|
|
use \error\core\Error;
|
2016-10-18 14:03:03 +00:00
|
|
|
use \api\core\Authentification;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-15 16:27:02 +00:00
|
|
|
class members_choice{
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
public static function render($params){
|
|
|
|
/* [1] On vérifie le type de groupe (user/machine)
|
2016-07-14 08:16:11 +00:00
|
|
|
=========================================================*/
|
|
|
|
/* (1) On vérifie les paramètres */
|
2016-07-20 16:16:36 +00:00
|
|
|
if( !isset($params['id_cluster']) || !is_numeric($params['id_cluster']) || !isset($params['class']) || !is_numeric($params['class']) )
|
2016-10-18 14:03:03 +00:00
|
|
|
return Viewer::$htmlError;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (2) On récupère le groupe */
|
2017-01-30 17:39:21 +00:00
|
|
|
$checktypeRequest = new Request('clusterDefault/getById', [
|
2016-07-20 16:16:36 +00:00
|
|
|
'id_cluster' => $params['id_cluster'],
|
|
|
|
'class' => $params['class']
|
2016-07-14 08:16:11 +00:00
|
|
|
]);
|
|
|
|
$checktypeResponse = $checktypeRequest->dispatch();
|
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (3) Si on ne le trouve pas, on retourne une erreur */
|
2017-01-30 17:39:21 +00:00
|
|
|
if( $checktypeResponse->error->get() != Err::Success )
|
2016-10-18 14:03:03 +00:00
|
|
|
return Viewer::$htmlError;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (4) On récupère les données du groupe */
|
2016-07-14 08:16:11 +00:00
|
|
|
$currentCluster = $checktypeResponse->get('cluster');
|
|
|
|
|
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* [2] Init Twig
|
2016-07-14 08:16:11 +00:00
|
|
|
=========================================================*/
|
2017-01-08 15:30:40 +00:00
|
|
|
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
|
|
|
|
$twig = new \Twig_Environment($loader, []);
|
|
|
|
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* [3] Store variables
|
|
|
|
=========================================================*/
|
|
|
|
$variables = [
|
|
|
|
'p_id_cluster' => $params['id_cluster'],
|
|
|
|
'p_class' => $params['class'],
|
|
|
|
'p_name' => $currentCluster['name'],
|
|
|
|
'p_theme' => $_SESSION['WAREHOUSE']['theme']
|
|
|
|
];
|
|
|
|
|
|
|
|
/* [4] Store functions
|
2016-07-14 08:16:11 +00:00
|
|
|
=========================================================*/
|
2017-01-08 15:30:40 +00:00
|
|
|
$twig->addFunction(new \Twig_Function('f_members', function($id_cluster, $class){
|
|
|
|
/* [1] On récupère les membres
|
|
|
|
=========================================================*/
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
/* (1) On exécute la requête */
|
2017-01-30 17:39:21 +00:00
|
|
|
$getmembersRequest = new Request('clusterDefault/getMembers', [
|
2017-01-08 15:30:40 +00:00
|
|
|
'id_cluster' => $id_cluster,
|
|
|
|
'class' => $class
|
|
|
|
]);
|
|
|
|
$getmembersResponse = $getmembersRequest->dispatch();
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (2) Si erreur, on retourne rien par défaut */
|
2017-01-30 17:39:21 +00:00
|
|
|
if( $getmembersResponse->error->get() != Err::Success )
|
2017-01-08 15:30:40 +00:00
|
|
|
return [];
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (3) On récupère la liste des UID uniquement */
|
|
|
|
$members_ids = [];
|
|
|
|
foreach($getmembersResponse->get('members') as $member)
|
|
|
|
$members_ids[] = ($class==0) ? $member['id_user'] : $member['id_machine'];
|
|
|
|
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* [2] On récupère les utilisateurs non membres
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) On récupère les utilisateurs */
|
|
|
|
if( $class == 0 ){
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (2) On exécute la requête */
|
2017-01-30 17:39:21 +00:00
|
|
|
$getusersRequest = new Request('userDefault/getAll');
|
2017-01-08 15:30:40 +00:00
|
|
|
// On recupere la reponse
|
|
|
|
$getusersResponse = $getusersRequest->dispatch();
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (3) si erreur, on affiche l'explicitation */
|
2017-01-30 17:39:21 +00:00
|
|
|
if( $getusersResponse->error->get() != Err::Success )
|
2017-01-08 15:30:40 +00:00
|
|
|
return [];
|
2016-07-21 13:35:00 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (4) On récupère la liste des utilisateurs */
|
|
|
|
$users = $getusersResponse->get('users');
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (5) On ajoute s'ils sont dans le groupe ou non */
|
|
|
|
foreach($users as $u=>$user)
|
|
|
|
$users[$u]['already'] = in_array($user['id_user'], $members_ids);
|
|
|
|
return $users;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* [3] On récupère les machines non membres
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) On récupère les machines */
|
|
|
|
}else{
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (2) On exécute la requête */
|
2017-01-30 17:39:21 +00:00
|
|
|
$getmachinesRequest = new Request('machineDefault/getAll');
|
2017-01-08 15:30:40 +00:00
|
|
|
// On recupere la reponse
|
|
|
|
$getmachinesResponse = $getmachinesRequest->dispatch();
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (3) si erreur, on affiche l'explicitation */
|
2017-01-30 17:39:21 +00:00
|
|
|
if( $getmachinesResponse->error->get() != Err::Success )
|
2017-01-08 15:30:40 +00:00
|
|
|
return [];
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (4) On récupère la liste des machines */
|
|
|
|
$machines = $getmachinesResponse->get('machines');
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* (5) On ajoute s'ils sont dans le groupe ou non */
|
|
|
|
foreach($machines as $u=>$machine)
|
|
|
|
$machines[$u]['already'] = in_array($machine['id_machine'], $members_ids);
|
|
|
|
|
|
|
|
return $machines;
|
|
|
|
}
|
2016-07-21 13:35:00 +00:00
|
|
|
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
}));
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* [5] Build the whole stuff
|
|
|
|
=========================================================*/
|
2017-01-15 16:27:02 +00:00
|
|
|
return $twig->render('group/members_choice.twig', [
|
2017-01-08 15:30:40 +00:00
|
|
|
'p_class' => $variables['p_class'],
|
|
|
|
'p_name' => $variables['p_name'],
|
|
|
|
'p_id_cluster' => $variables['p_id_cluster'],
|
|
|
|
'p_theme' => $variables['p_theme']
|
|
|
|
]);
|
2016-07-14 08:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|