103 lines
2.9 KiB
PHP
Executable File
103 lines
2.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace viewer\view\machine;
|
|
use \viewer\core\Viewer;
|
|
use \api\core\Request;
|
|
use \error\core\Error;
|
|
use \error\core\Err;
|
|
|
|
class view{
|
|
|
|
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' ),
|
|
'group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' ),
|
|
'motor' => file_get_contents( __PUBLIC__.'/src/static/container/motor.svg' )
|
|
],
|
|
|
|
'p_theme' => $_SESSION['WAREHOUSE']['theme']
|
|
];
|
|
|
|
/* [3] Store functions
|
|
=========================================================*/
|
|
$twig->addFunction(new \Twig_Function('f_machines', function(){
|
|
$request = new Request('machineDefault/getAll'); // On utilise la methode 'getAll' du module 'machineDefault'
|
|
$answer = $request->dispatch(); // On recupere la reponse
|
|
|
|
// si erreur, on affiche rien par défaut
|
|
if( $answer->error->get() != Err::Success )
|
|
return [];
|
|
|
|
return $answer->get('machines');
|
|
}));
|
|
|
|
$twig->addFunction(new \Twig_Function('f_getstate', function($id_machine){
|
|
/* (1) Write / Execute request */
|
|
$req = new Request('machineDefault/getState', ['id_machine' => $id_machine]);
|
|
$res = $req->dispatch();
|
|
|
|
/* (2) Manage error */
|
|
if( $res->error->get() != Err::Success )
|
|
return 'detached';
|
|
|
|
return $res->get('state');
|
|
}));
|
|
|
|
$twig->addFunction(new \Twig_Function('f_clusters', function($id_machine){
|
|
$request = new Request('machineDefault/getClusters', [
|
|
'id_machine' => (int) $id_machine
|
|
]);
|
|
|
|
$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_motheure', function($id_machine){
|
|
/* (1) Get its machine_clusters
|
|
---------------------------------------------------------*/
|
|
/* (1) Create request */
|
|
$motheureReq = new Request('motheure/getCount', ['id_machine' => $id_machine]);
|
|
|
|
/* (2) Execute */
|
|
$motheureRes = $motheureReq->dispatch();
|
|
|
|
/* (3) Manage error */
|
|
if( $motheureRes->error->get() != Err::Success )
|
|
return null;
|
|
|
|
|
|
return $motheureRes->get('count');
|
|
|
|
}));
|
|
|
|
|
|
/* [4] Build the whole stuff
|
|
=========================================================*/
|
|
return $twig->render('machine/view.twig', [
|
|
'p_icon' => $variables['p_icon'],
|
|
'p_theme' => $variables['p_theme']
|
|
]);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|