2016-07-12 10:06:46 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
|
namespace viewer\view\machine;
|
|
|
|
|
use \viewer\core\Viewer;
|
|
|
|
|
use \api\core\ModuleRequest;
|
|
|
|
|
use \api\core\Authentification;
|
2016-10-18 17:09:47 +00:00
|
|
|
|
use \error\core\Error;
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2016-08-06 09:32:50 +00:00
|
|
|
|
class machine_view{
|
2016-07-12 10:06:46 +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, []);
|
|
|
|
|
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
|
/* [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' )
|
|
|
|
|
],
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
|
'p_theme' => $_SESSION['WAREHOUSE']['theme']
|
|
|
|
|
];
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
|
/* [3] Store functions
|
|
|
|
|
=========================================================*/
|
|
|
|
|
$twig->addFunction(new \Twig_Function('f_machines', function(){
|
|
|
|
|
$request = new ModuleRequest('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 != Error::Success )
|
|
|
|
|
return [];
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
|
return $answer->get('machines');
|
|
|
|
|
}));
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
|
$twig->addFunction(new \Twig_Function('f_clusters', function($id_machine){
|
|
|
|
|
$clustersReq = new ModuleRequest('machineDefault/getClusters', [
|
|
|
|
|
'id_machine' => (int) $id_machine
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$clustersRes = $clustersReq->dispatch();
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
|
// si erreur, on affiche rien par défaut
|
|
|
|
|
if( $clustersRes->error != Error::Success )
|
|
|
|
|
return [];
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
|
return $clustersRes->get('clusters');
|
|
|
|
|
}));
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
|
|
|
|
|
2017-01-06 16:09:01 +00:00
|
|
|
|
/* [4] Build the whole stuff
|
|
|
|
|
=========================================================*/
|
|
|
|
|
return $twig->render('machine/machine_view.twig', [
|
|
|
|
|
'p_icon' => $variables['p_icon'],
|
|
|
|
|
'p_theme' => $variables['p_theme']
|
|
|
|
|
]);
|
2016-07-12 10:06:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function view($params){
|
|
|
|
|
$view = '';
|
|
|
|
|
|
|
|
|
|
/* [1] On récupère la liste des machines
|
|
|
|
|
=========================================================*/
|
2017-01-06 16:09:01 +00:00
|
|
|
|
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
|
|
|
|
foreach($MACHINELIST as $u=>$machine){
|
|
|
|
|
$clustersReq = new ModuleRequest('machineDefault/getClusters', [ 'id_machine' => $machine['id_machine'] ]);
|
|
|
|
|
$clustersRes = $clustersReq->dispatch();
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion si erreur */
|
2016-10-18 17:09:47 +00:00
|
|
|
|
if( $clustersRes->error == Error::Success ) $clusters = $clustersRes->get('clusters');
|
2016-07-12 10:06:46 +00:00
|
|
|
|
else $clusters = [];
|
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$MACHINELIST[$u]['grouplist'] = Viewer::replaceMultiple(
|
2016-07-12 10:06:46 +00:00
|
|
|
|
self::template('cluster'),
|
|
|
|
|
$clusters,
|
|
|
|
|
[ 'id_machine' => $machine['id_machine'] ]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$view_machine = Viewer::replaceMultiple(
|
2016-07-12 10:06:46 +00:00
|
|
|
|
self::template('machine'),
|
|
|
|
|
$MACHINELIST, [
|
2016-10-18 14:03:03 +00:00
|
|
|
|
'icon_remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
|
|
|
|
|
'icon_edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' ),
|
|
|
|
|
'icon_group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' ),
|
2016-07-12 10:06:46 +00:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::replaceSingle(self::template(), [ 'machinelist' => $view_machine ]);
|
2016-07-12 10:06:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|