SMMP/manager/view/machine/view.php

106 lines
2.7 KiB
PHP
Raw Normal View History

2016-07-12 10:06:46 +00:00
<?php
namespace manager\view\machine;
use \manager\View;
use \manager\ModuleRequest;
use \manager\Authentification;
use \manager\ManagerError;
class view{
public static function template($type=null){
switch($type){
case 'cluster': return "
<span>
@name
<span class='rem-group' data-group='@id_cluster' data-machine='@id_machine'></span>
</span>";
break;
case 'machine': return "
<article class='inline-box' id='@id_machine'>
<span class='title' style='color: ".$_SESSION['WAREHOUSE']['theme']."'>@name <span>#@name</span></span>
<span class='link_remove' data-machine='@id_machine'>@icon_remove</span>
<span class='link_edit' data-machine='@id_machine'>@icon_edit</span>
<span class='groups'>
@icon_group
@grouplist
<span class='add-group' data-machine='@id_machine'>+</span>
</span>
</article>";
break;
default: return "
<input type='text' class='searchbar' placeholder='Recherche'>
@machinelist";
break;
}
}
public static function view($params){
$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');
foreach($MACHINELIST as $u=>$machine){
$clustersReq = new ModuleRequest('machineDefault/getClusters', [ 'id_machine' => $machine['id_machine'] ]);
$clustersRes = $clustersReq->dispatch();
/* (2) Gestion si erreur */
if( $clustersRes->error == ManagerError::Success ) $clusters = $clustersRes->get('clusters');
else $clusters = [];
$MACHINELIST[$u]['grouplist'] = View::replaceMultiple(
self::template('cluster'),
$clusters,
[ 'id_machine' => $machine['id_machine'] ]
);
}
$view_machine = View::replaceMultiple(
self::template('machine'),
$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_group' => file_get_contents( __ROOT__.'/src/static/container/group.svg' ),
]);
return View::replaceSingle(self::template(), [ 'machinelist' => $view_machine ]);
}
}
?>