SMMP/manager/view/group/membersChoice.php

201 lines
5.8 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 "
<a style='text-align:center; color: #000;' href='/groups/members/'>Changer de 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'>
<div>
<span><strong>@name</strong></span>
<span><strong>@clustertype</strong></span>
</div>
@members
</article>";
break;
}
}
public static function view($params){
/* [0] Initialisation
=========================================================*/
/* (1) On vérifie les paramètres */
if( !isset($params['id_cluster']) || !is_numeric($params['id_cluster']) || !isset($params['class']) || !is_numeric($params['class']) )
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'],
'class' => $params['class']
]);
$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'],
'class' => $params['class']
]);
$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[] = ($params['class']==0) ? $member['id_user'] : $member['id_machine'];
/* [3] SI GROUPE D'UTILISATEURS -> On récupère les utilisateurs
=========================================================*/
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 )
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 $m=>$machine)
$MACHINELIST[$m]['already_in'] = in_array($machine['id_machine'], $members_id) ? 'checked' : '';
/* (2) On génère la vue */
$members_view = View::replaceMultiple(
self::template('machinelist'),
$MACHINELIST
);
}
return View::replaceSingle(
self::template(), [
'id_cluster' => $params['id_cluster'],
'class' => $params['class'],
'name' => $currentCluster['name'],
'clustertype' => ($params['class']==0) ? 'utilisateurs' : 'machines',
'members' => $members_view
]
);
}
}
?>