103 lines
2.7 KiB
PHP
103 lines
2.7 KiB
PHP
|
<?php
|
|||
|
|
|||
|
namespace manager\view\group;
|
|||
|
use \manager\View;
|
|||
|
use \manager\ModuleRequest;
|
|||
|
use \manager\Authentification;
|
|||
|
use \manager\ManagerError;
|
|||
|
|
|||
|
class machineChoice{
|
|||
|
|
|||
|
public static function template($type=null){
|
|||
|
|
|||
|
switch($type){
|
|||
|
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'>
|
|||
|
@machinelist
|
|||
|
</article>";
|
|||
|
break;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static function view($params){
|
|||
|
// On vérifie les paramètres
|
|||
|
if( !isset($params['id_cluster']) && !is_number($params['id_cluster']) )
|
|||
|
return "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
|
|||
|
|
|||
|
|
|||
|
$view = '';
|
|||
|
|
|||
|
/* [1] On récupère la liste des machines
|
|||
|
=========================================================*/
|
|||
|
$request = new ModuleRequest('machineDefault/getAll'); // On utilise la methode 'getAll' du module 'machineDefault'
|
|||
|
$answer = $request->dispatch(); // On recupere la reponse
|
|||
|
|
|||
|
// si erreur, on affiche l'explicitation
|
|||
|
if( $answer->error != ManagerError::Success )
|
|||
|
return "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
|
|||
|
|
|||
|
$MACHINELIST = $answer->get('machines');
|
|||
|
|
|||
|
/* [2] On récupère la liste des membres
|
|||
|
=========================================================*/
|
|||
|
$get_members = new ModuleRequest('clusterDefault/getMembers', [
|
|||
|
'id_cluster' => $params['id_cluster']
|
|||
|
]);
|
|||
|
$members_response = $get_members->dispatch();
|
|||
|
|
|||
|
// On récupère la liste des UID uniquement
|
|||
|
$members_id = [];
|
|||
|
foreach($members_response->get('members') as $member)
|
|||
|
$members_id[] = $member['id_member'];
|
|||
|
|
|||
|
|
|||
|
|
|||
|
foreach($MACHINELIST as $m=>$machine)
|
|||
|
$MACHINELIST[$m]['already_in'] = in_array($machine['id_machine'], $members_id) ? 'checked' : '';
|
|||
|
|
|||
|
|
|||
|
$view_user = View::replaceMultiple(
|
|||
|
self::template('machinelist'),
|
|||
|
$MACHINELIST, [
|
|||
|
'icon_remove' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' ),
|
|||
|
'icon_edit' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' ),
|
|||
|
'icon_card' => file_get_contents( __ROOT__.'/src/static/container/card.svg' ),
|
|||
|
'icon_mail' => file_get_contents( __ROOT__.'/src/static/container/mail.svg' ),
|
|||
|
'icon_group' => file_get_contents( __ROOT__.'/src/static/container/group.svg' ),
|
|||
|
]);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
return View::replaceSingle(self::template(), [ 'machinelist' => $view_user ]);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
?>
|