2016-07-18 14:49:00 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
namespace viewer\view\machine;
|
|
|
|
use \viewer\core\Viewer;
|
2017-01-30 17:39:21 +00:00
|
|
|
use \api\core\Request;
|
2016-10-18 14:03:03 +00:00
|
|
|
use \api\core\Authentification;
|
2016-10-18 17:09:47 +00:00
|
|
|
use \error\core\Error;
|
2017-01-30 17:39:21 +00:00
|
|
|
use \error\core\Err;
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-01-11 16:31:59 +00:00
|
|
|
class groups{
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
public static function render(){
|
|
|
|
/* [1] Init Twig
|
|
|
|
=========================================================*/
|
|
|
|
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
|
|
|
|
$twig = new \Twig_Environment($loader, []);
|
2017-09-23 17:40:37 +00:00
|
|
|
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
/* [2] Store variables
|
2016-07-18 14:49:00 +00:00
|
|
|
=========================================================*/
|
2017-01-06 16:09:01 +00:00
|
|
|
$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' ),
|
2017-09-23 17:40:37 +00:00
|
|
|
'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' )
|
2017-01-06 16:09:01 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
'p_theme' => $_SESSION['WAREHOUSE']['theme']
|
|
|
|
];
|
|
|
|
|
|
|
|
/* [3] Store functions
|
|
|
|
=========================================================*/
|
|
|
|
$twig->addFunction(new \Twig_Function('f_clusters', function(){
|
2017-01-30 17:39:21 +00:00
|
|
|
$request = new Request('clusterDefault/getAll', [
|
2017-01-06 16:09:01 +00:00
|
|
|
'class' => 1
|
|
|
|
]);
|
2017-09-23 17:40:37 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
$answer = $request->dispatch();
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
// si erreur, on affiche rien par défaut
|
2017-01-30 17:39:21 +00:00
|
|
|
if( $answer->error->get() != Err::Success )
|
2017-01-06 16:09:01 +00:00
|
|
|
return [];
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
return $answer->get('clusters');
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
}));
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
$twig->addFunction(new \Twig_Function('f_machines', function($id_cluster){
|
2017-01-30 17:39:21 +00:00
|
|
|
$usersReq = new Request('clusterDefault/getMembers', [
|
2017-01-06 16:09:01 +00:00
|
|
|
'id_cluster' => (int) $id_cluster,
|
2016-07-18 14:49:00 +00:00
|
|
|
'class' => 1
|
|
|
|
]);
|
2017-09-23 17:40:37 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
$usersRes = $usersReq->dispatch();
|
|
|
|
// si erreur, on affiche rien par défaut
|
2017-01-30 17:39:21 +00:00
|
|
|
if( $usersRes->error->get() != Err::Success )
|
2017-01-06 16:09:01 +00:00
|
|
|
return [];
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
return $usersRes->get('members');
|
|
|
|
}));
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-09-23 17:40:37 +00:00
|
|
|
$twig->addFunction(new \Twig_Function('f_options', function($id_cluster){
|
2017-09-25 13:29:15 +00:00
|
|
|
$modReq = new Request('clusterDefault/getEtree', [
|
|
|
|
'id_machine_cluster' => (int) $id_cluster
|
2017-09-23 17:40:37 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$modRes = $modReq->dispatch();
|
2017-09-25 13:29:15 +00:00
|
|
|
|
2017-09-23 17:40:37 +00:00
|
|
|
// si erreur, on affiche rien par défaut
|
|
|
|
if( $modRes->error->get() != Err::Success )
|
|
|
|
return [];
|
|
|
|
|
2017-09-25 13:29:15 +00:00
|
|
|
return $modRes->get('etree');
|
2017-09-23 17:40:37 +00:00
|
|
|
}));
|
|
|
|
|
2016-07-18 14:49:00 +00:00
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
/* [4] Build the whole stuff
|
|
|
|
=========================================================*/
|
2017-01-11 16:31:59 +00:00
|
|
|
return $twig->render('machine/groups.twig', [
|
2017-01-06 16:09:01 +00:00
|
|
|
'p_icon' => $variables['p_icon'],
|
|
|
|
'p_theme' => $variables['p_theme']
|
2016-07-18 14:49:00 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|