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 "
|
2016-07-20 16:41:24 +00:00
|
|
|
|
<a style='text-align:center; color: #000;' href='/groups/members/'>Changer de groupe</a><p></p>
|
2016-07-14 08:16:11 +00:00
|
|
|
|
<article class='check-table'>
|
2016-07-20 16:41:24 +00:00
|
|
|
|
<input type='hidden' id='members-member-idcluster' value='@id_cluster'>
|
|
|
|
|
<input type='hidden' id='members-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 */
|
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-07-14 08:16:11 +00:00
|
|
|
|
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', [
|
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();
|
|
|
|
|
|
|
|
|
|
/* (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', [
|
2016-07-20 16:16:36 +00:00
|
|
|
|
'id_cluster' => $params['id_cluster'],
|
|
|
|
|
'class' => $params['class']
|
2016-07-14 08:16:11 +00:00
|
|
|
|
]);
|
|
|
|
|
$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)
|
2016-07-20 16:16:36 +00:00
|
|
|
|
$members_id[] = ($params['class']==0) ? $member['id_user'] : $member['id_machine'];
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] SI GROUPE D'UTILISATEURS -> On récupère les utilisateurs
|
|
|
|
|
=========================================================*/
|
2016-07-20 16:16:36 +00:00
|
|
|
|
if( $params['class'] == 0 ){
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
/* (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 */
|
2016-07-20 16:16:36 +00:00
|
|
|
|
foreach($MACHINELIST as $m=>$machine)
|
|
|
|
|
$MACHINELIST[$m]['already_in'] = in_array($machine['id_machine'], $members_id) ? 'checked' : '';
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
/* (2) On génère la vue */
|
|
|
|
|
$members_view = View::replaceMultiple(
|
|
|
|
|
self::template('machinelist'),
|
|
|
|
|
$MACHINELIST
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-15 12:48:18 +00:00
|
|
|
|
return View::replaceSingle(
|
|
|
|
|
self::template(), [
|
2016-07-20 16:16:36 +00:00
|
|
|
|
'id_cluster' => $params['id_cluster'],
|
|
|
|
|
'class' => $params['class'],
|
2016-07-15 14:56:09 +00:00
|
|
|
|
'name' => $currentCluster['name'],
|
2016-07-20 16:16:36 +00:00
|
|
|
|
'clustertype' => ($params['class']==0) ? 'utilisateurs' : 'machines',
|
2016-07-15 14:56:09 +00:00
|
|
|
|
'members' => $members_view
|
2016-07-15 12:48:18 +00:00
|
|
|
|
]
|
|
|
|
|
);
|
2016-07-14 08:16:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|