SMMP/manager/views/group/group_membersChoice.php

221 lines
6.2 KiB
PHP
Raw Normal View History

<?php
namespace manager\views\group;
2016-08-06 09:32:50 +00:00
use \manager\ViewManager;
use \manager\ModuleRequest;
use \manager\ManagerError;
use \manager\Authentification;
use \manager\repo\cluster as clusterRepo;
2016-08-06 09:32:50 +00:00
class group_membersChoice{
public static function template($type=null){
switch($type){
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;
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 "
<a style='text-align:center; color: #666;' href='/groups/members/'>Modifier un autre groupe</a><p></p>
<article class='check-table'>
<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>
@header
<span><strong>Membre de <u>@name</u></strong></span>
2016-07-15 14:56:09 +00:00
</div>
@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-08-06 09:32:50 +00:00
return ViewManager::$htmlError;
/* (2) On initialise les vues */
$view = '';
$members_view = '';
$header = '';
/* [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']
]);
$checktypeResponse = $checktypeRequest->dispatch();
/* (2) Si on ne le trouve pas, on retourne une erreur */
if( $checktypeResponse->error != ManagerError::Success )
2016-08-06 09:32:50 +00:00
return ViewManager::$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']
]);
$getmembersResponse = $getmembersRequest->dispatch();
/* (2) Si erreur, on retourne l'erreur */
if( $getmembersResponse->error != ManagerError::Success )
2016-08-06 09:32:50 +00:00
return ViewManager::$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'];
/* [3] SI GROUPE D'UTILISATEURS -> On récupère les utilisateurs
=========================================================*/
2016-07-20 16:16:36 +00:00
if( $params['class'] == 0 ){
/* (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 )
2016-08-06 09:32:50 +00:00
return ViewManager::$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 */
$header = self::template('userheader');
2016-08-06 09:32:50 +00:00
$members_view = ViewManager::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 )
2016-08-06 09:32:50 +00:00
return ViewManager::$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' : '';
/* (2) On génère la vue */
$header = self::template('machineheader');
2016-08-06 09:32:50 +00:00
$members_view = ViewManager::replaceMultiple(
self::template('machinelist'),
$MACHINELIST
);
}
2016-08-06 09:32:50 +00:00
return ViewManager::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',
'members' => $members_view,
'header' => $header
]
);
}
}
?>