2016-07-14 08:16:11 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace manager\view\group;
|
|
|
|
|
use \manager\View;
|
|
|
|
|
use \manager\ModuleRequest;
|
|
|
|
|
use \manager\ManagerError;
|
|
|
|
|
use \manager\Authentification;
|
|
|
|
|
use \manager\repo\cluster as clusterRepo;
|
|
|
|
|
|
|
|
|
|
class membersChoice{
|
|
|
|
|
|
|
|
|
|
public static function template($type=null){
|
|
|
|
|
|
|
|
|
|
switch($type){
|
|
|
|
|
case 'userlist': return "
|
|
|
|
|
<div>
|
|
|
|
|
<span>@username</span>
|
|
|
|
|
<span>@firstname @lastname</span>
|
|
|
|
|
<span>@code</span>
|
|
|
|
|
<span>
|
|
|
|
|
|
|
|
|
|
<input type='checkbox' value='@id_user' data-name='members' id='checkbox_@id_user' @already_in>
|
|
|
|
|
<label for='checkbox_@id_user'></label>
|
|
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
</div>";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'machinelist': return "
|
|
|
|
|
<div>
|
|
|
|
|
<span>@name</span>
|
|
|
|
|
<span>
|
|
|
|
|
|
|
|
|
|
<input type='checkbox' value='@id_machine' data-name='members' id='checkbox_@id_machine' @already_in>
|
|
|
|
|
<label for='checkbox_@id_machine'></label>
|
|
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
</div>";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: return "
|
|
|
|
|
<article class='check-table'>
|
2016-07-15 12:48:18 +00:00
|
|
|
|
<input type='hidden' id='filter-member-idcluster' value='@id_cluster'>
|
|
|
|
|
<input type='hidden' id='filter-member-class' value='@class'>
|
2016-07-15 14:56:09 +00:00
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<span><strong>@name</strong></span>
|
|
|
|
|
<span><strong>@clustertype</strong></span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2016-07-14 08:16:11 +00:00
|
|
|
|
@members
|
|
|
|
|
</article>";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function view($params){
|
|
|
|
|
/* [0] Initialisation
|
|
|
|
|
=========================================================*/
|
|
|
|
|
/* (1) On vérifie les paramètres */
|
|
|
|
|
if( !isset($params['id_cluster']) && !is_number($params['id_cluster']) )
|
|
|
|
|
return View::$htmlError;
|
|
|
|
|
|
|
|
|
|
/* (2) On initialise les vues */
|
|
|
|
|
$view = '';
|
|
|
|
|
$members_view = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] On vérifie le type de groupe (user/machine)
|
|
|
|
|
=========================================================*/
|
|
|
|
|
/* (1) On récupère le groupe */
|
|
|
|
|
$checktypeRequest = new ModuleRequest('clusterDefault/getById', [
|
|
|
|
|
'id_cluster' => $params['id_cluster']
|
|
|
|
|
]);
|
|
|
|
|
$checktypeResponse = $checktypeRequest->dispatch();
|
|
|
|
|
|
|
|
|
|
/* (2) Si on ne le trouve pas, on retourne une erreur */
|
|
|
|
|
if( $checktypeResponse->error != ManagerError::Success )
|
|
|
|
|
return View::$htmlError;
|
|
|
|
|
|
|
|
|
|
/* (3) On récupère les données du groupe */
|
|
|
|
|
$currentCluster = $checktypeResponse->get('cluster');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On récupère les membres du groupe
|
|
|
|
|
=========================================================*/
|
|
|
|
|
/* (1) On exécute la requête */
|
|
|
|
|
$getmembersRequest = new ModuleRequest('clusterDefault/getMembers', [
|
|
|
|
|
'id_cluster' => $params['id_cluster']
|
|
|
|
|
]);
|
|
|
|
|
$getmembersResponse = $getmembersRequest->dispatch();
|
|
|
|
|
|
|
|
|
|
/* (2) Si erreur, on retourne l'erreur */
|
|
|
|
|
if( $getmembersResponse->error != ManagerError::Success )
|
|
|
|
|
return View::$htmlError;
|
|
|
|
|
|
|
|
|
|
/* (3) On récupère la liste des UID uniquement */
|
|
|
|
|
$members_id = [];
|
|
|
|
|
foreach($getmembersResponse->get('members') as $member)
|
|
|
|
|
$members_id[] = $member['id_member'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] SI GROUPE D'UTILISATEURS -> On récupère les utilisateurs
|
|
|
|
|
=========================================================*/
|
|
|
|
|
if( $currentCluster['class'] == clusterRepo::USER_CLASS ){
|
|
|
|
|
|
|
|
|
|
/* (1) On récupère les utilisateurs
|
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
|
/* (1) On exécute la requête */
|
|
|
|
|
$getusersRequest = new ModuleRequest('userDefault/getAll'); // On utilise la methode 'getAll' du module 'userDefault'
|
|
|
|
|
$getusersResponse = $getusersRequest->dispatch(); // On recupere la reponse
|
|
|
|
|
|
|
|
|
|
/* (2) si erreur, on affiche l'explicitation */
|
|
|
|
|
if( $getusersResponse->error != ManagerError::Success )
|
|
|
|
|
return View::$htmlError;
|
|
|
|
|
|
|
|
|
|
/* (3) On récupère la liste des utilisateurs */
|
|
|
|
|
$USERLIST = $getusersResponse->get('users');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On gère l'affichage des utilisateurs
|
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
|
/* (1) On gère l'état 'membre' ou non */
|
|
|
|
|
foreach($USERLIST as $u=>$user)
|
|
|
|
|
$USERLIST[$u]['already_in'] = in_array($user['id_user'], $members_id) ? 'checked' : '';
|
|
|
|
|
|
|
|
|
|
/* (2) On génère la vue */
|
|
|
|
|
$members_view = View::replaceMultiple(
|
|
|
|
|
self::template('userlist'),
|
|
|
|
|
$USERLIST
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] SI GROUPE DE MACHINES -> On récupère les machines
|
|
|
|
|
=========================================================*/
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
/* (1) On récupère les machines
|
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
|
/* (1) On exécute la requête */
|
|
|
|
|
$getmachinesRequest = new ModuleRequest('machineDefault/getAll'); // On utilise la methode 'getAll' du module 'machineDefault'
|
|
|
|
|
$getmachinesResponse = $getmachinesRequest->dispatch(); // On recupere la reponse
|
|
|
|
|
|
|
|
|
|
/* (2) si erreur, on affiche l'explicitation */
|
|
|
|
|
if( $getmachinesResponse->error != ManagerError::Success )
|
|
|
|
|
return View::$htmlError;
|
|
|
|
|
|
|
|
|
|
/* (3) On récupère la liste des machines */
|
|
|
|
|
$MACHINELIST = $getmachinesResponse->get('machines');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On gère l'affichage des machines
|
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
|
/* (1) On gère l'état 'membre' ou non */
|
|
|
|
|
foreach($MACHINELIST as $u=>$user)
|
|
|
|
|
$MACHINELIST[$u]['already_in'] = in_array($user['id_machine'], $members_id) ? 'checked' : '';
|
|
|
|
|
|
|
|
|
|
/* (2) On génère la vue */
|
|
|
|
|
$members_view = View::replaceMultiple(
|
|
|
|
|
self::template('machinelist'),
|
|
|
|
|
$MACHINELIST
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 12:48:18 +00:00
|
|
|
|
$class = ($currentCluster['class'] == clusterRepo::USER_CLASS) ? 0 : 1;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-15 12:48:18 +00:00
|
|
|
|
return View::replaceSingle(
|
|
|
|
|
self::template(), [
|
2016-07-15 14:56:09 +00:00
|
|
|
|
'id_cluster' => $currentCluster['id_cluster'],
|
|
|
|
|
'class' => $class,
|
|
|
|
|
'name' => $currentCluster['name'],
|
|
|
|
|
'clustertype' => ($class==0) ? 'utilisateurs' : 'machines',
|
|
|
|
|
'members' => $members_view
|
2016-07-15 12:48:18 +00:00
|
|
|
|
]
|
|
|
|
|
);
|
2016-07-14 08:16:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|