73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace viewer\view\extension;
|
||
|
use \viewer\core\Viewer;
|
||
|
use \api\core\Request;
|
||
|
use \api\core\Authentification;
|
||
|
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' => [
|
||
|
'group' => file_get_contents( __PUBLIC__.'/src/static/container/extension.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_modules', function($id_cluster){
|
||
|
$extReq = new Request('clusterDefault/getModules', [
|
||
|
'id_cluster' => (int) $id_cluster
|
||
|
]);
|
||
|
|
||
|
$extRes = $extReq->dispatch();
|
||
|
// si erreur, on affiche rien par défaut
|
||
|
if( $extRes->error->get() != Err::Success )
|
||
|
return [];
|
||
|
|
||
|
return $extRes->get('modules');
|
||
|
}));
|
||
|
|
||
|
|
||
|
/* [4] Build the whole stuff
|
||
|
=========================================================*/
|
||
|
return $twig->render('extension/view.twig', [
|
||
|
'p_icon' => $variables['p_icon'],
|
||
|
'p_theme' => $variables['p_theme']
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
?>
|