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;
|
|
|
|
|
use \api\core\ModuleRequest;
|
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
|
|
|
|
use \manager\repo\cluster as clusterRepo;
|
|
|
|
|
|
2016-08-06 09:32:50 +00:00
|
|
|
|
class group_membersChoice{
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
public static function template($type=null){
|
|
|
|
|
|
|
|
|
|
switch($type){
|
2016-07-21 13:35:00 +00:00
|
|
|
|
|
|
|
|
|
case 'userheader': return "
|
|
|
|
|
<span><strong>Identifiant</strong></span>
|
|
|
|
|
<span><strong>Nom</strong></span>
|
|
|
|
|
<span><strong>Code RFID</strong></span>
|
|
|
|
|
";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'machineheader': return "
|
|
|
|
|
<span><strong>Nom</strong></span>
|
|
|
|
|
";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
2016-07-14 08:16:11 +00:00
|
|
|
|
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:45:43 +00:00
|
|
|
|
<a style='text-align:center; color: #666;' href='/groups/members/'>Modifier un autre 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>
|
2016-07-21 13:35:00 +00:00
|
|
|
|
@header
|
|
|
|
|
<span><strong>Membre de <u>@name</u></strong></span>
|
2016-07-15 14:56:09 +00:00
|
|
|
|
</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-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::$htmlError;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
/* (2) On initialise les vues */
|
|
|
|
|
$view = '';
|
|
|
|
|
$members_view = '';
|
2016-07-21 13:35:00 +00:00
|
|
|
|
$header = '';
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [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 */
|
2016-10-18 17:09:47 +00:00
|
|
|
|
if( $checktypeResponse->error != Error::Success )
|
2016-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::$htmlError;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
/* (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 */
|
2016-10-18 17:09:47 +00:00
|
|
|
|
if( $getmembersResponse->error != Error::Success )
|
2016-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::$htmlError;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
/* (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 */
|
2016-10-18 17:09:47 +00:00
|
|
|
|
if( $getusersResponse->error != Error::Success )
|
2016-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::$htmlError;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
/* (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 */
|
2016-07-21 13:35:00 +00:00
|
|
|
|
$header = self::template('userheader');
|
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$members_view = Viewer::replaceMultiple(
|
2016-07-14 08:16:11 +00:00
|
|
|
|
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 */
|
2016-10-18 17:09:47 +00:00
|
|
|
|
if( $getmachinesResponse->error != Error::Success )
|
2016-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::$htmlError;
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
|
|
/* (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 */
|
2016-07-21 13:35:00 +00:00
|
|
|
|
$header = self::template('machineheader');
|
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$members_view = Viewer::replaceMultiple(
|
2016-07-14 08:16:11 +00:00
|
|
|
|
self::template('machinelist'),
|
|
|
|
|
$MACHINELIST
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::replaceSingle(
|
2016-07-15 12:48:18 +00:00
|
|
|
|
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-21 13:35:00 +00:00
|
|
|
|
'members' => $members_view,
|
|
|
|
|
'header' => $header
|
2016-07-15 12:48:18 +00:00
|
|
|
|
]
|
|
|
|
|
);
|
2016-07-14 08:16:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|