SMMP/build/viewer/view/machine/machine_view.php

114 lines
3.2 KiB
PHP
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace viewer\view\machine;
use \viewer\core\Viewer;
use \api\core\ModuleRequest;
use \api\core\Authentification;
use \error\core\Error;
class machine_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' )
],
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [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 [];
return $answer->get('machines');
}));
$twig->addFunction(new \Twig_Function('f_clusters', function($id_machine){
$clustersReq = new ModuleRequest('machineDefault/getClusters', [
'id_machine' => (int) $id_machine
]);
$clustersRes = $clustersReq->dispatch();
// si erreur, on affiche rien par défaut
if( $clustersRes->error != Error::Success )
return [];
return $clustersRes->get('clusters');
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('machine/machine_view.twig', [
'p_icon' => $variables['p_icon'],
'p_theme' => $variables['p_theme']
]);
}
public static function view($params){
$view = '';
/* [1] On récupère la liste des 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 == Error::Success ) $clusters = $clustersRes->get('clusters');
else $clusters = [];
$MACHINELIST[$u]['grouplist'] = Viewer::replaceMultiple(
self::template('cluster'),
$clusters,
[ 'id_machine' => $machine['id_machine'] ]
);
}
$view_machine = Viewer::replaceMultiple(
self::template('machine'),
$MACHINELIST, [
'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' ),
]);
return Viewer::replaceSingle(self::template(), [ 'machinelist' => $view_machine ]);
}
}
?>