92 lines
2.5 KiB
PHP
Executable File
92 lines
2.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace viewer\view\machine;
|
|
use \viewer\core\Viewer;
|
|
use \api\core\Request;
|
|
use \api\core\Authentification;
|
|
use \error\core\Error;
|
|
use \error\core\Err;
|
|
|
|
class groups{
|
|
|
|
public static function render(){
|
|
/* [1] Init Twig
|
|
=========================================================*/
|
|
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
|
|
$twig = new \Twig_Environment($loader, []);
|
|
|
|
|
|
/* [2] Store variables
|
|
=========================================================*/
|
|
$variables = [
|
|
'p_icon' => [
|
|
'remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
|
|
'edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' ),
|
|
'device' => file_get_contents( __PUBLIC__.'/src/static/menu-side/device.svg' ),
|
|
'group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' ),
|
|
'option' => file_get_contents( __PUBLIC__.'/src/static/container/option.svg' )
|
|
],
|
|
|
|
'p_theme' => $_SESSION['WAREHOUSE']['theme']
|
|
];
|
|
|
|
/* [3] Store functions
|
|
=========================================================*/
|
|
$twig->addFunction(new \Twig_Function('f_clusters', function(){
|
|
$request = new Request('clusterDefault/getAll', [
|
|
'class' => 1
|
|
]);
|
|
|
|
$answer = $request->dispatch();
|
|
|
|
// si erreur, on affiche rien par défaut
|
|
if( $answer->error->get() != Err::Success )
|
|
return [];
|
|
|
|
return $answer->get('clusters');
|
|
|
|
}));
|
|
|
|
$twig->addFunction(new \Twig_Function('f_machines', function($id_cluster){
|
|
$usersReq = new Request('clusterDefault/getMembers', [
|
|
'id_cluster' => (int) $id_cluster,
|
|
'class' => 1
|
|
]);
|
|
|
|
$usersRes = $usersReq->dispatch();
|
|
// si erreur, on affiche rien par défaut
|
|
if( $usersRes->error->get() != Err::Success )
|
|
return [];
|
|
|
|
return $usersRes->get('members');
|
|
}));
|
|
|
|
$twig->addFunction(new \Twig_Function('f_options', function($id_cluster){
|
|
$modReq = new Request('clusterDefault/getEtree', [
|
|
'id_machine_cluster' => (int) $id_cluster
|
|
]);
|
|
|
|
$modRes = $modReq->dispatch();
|
|
|
|
// si erreur, on affiche rien par défaut
|
|
if( $modRes->error->get() != Err::Success )
|
|
return [];
|
|
|
|
return $modRes->get('etree');
|
|
}));
|
|
|
|
|
|
/* [4] Build the whole stuff
|
|
=========================================================*/
|
|
return $twig->render('machine/groups.twig', [
|
|
'p_icon' => $variables['p_icon'],
|
|
'p_theme' => $variables['p_theme']
|
|
]);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|