75 lines
2.1 KiB
PHP
Executable File
75 lines
2.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace viewer\view\group;
|
|
use \api\core\Request;
|
|
use \api\core\Authentification;
|
|
use \error\core\Err;
|
|
use \error\core\Error;
|
|
|
|
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' ),
|
|
'type' => file_get_contents( __PUBLIC__.'/src/static/menu-side/type.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_clusters', function($class){
|
|
/* (1) On récupère les groupes */
|
|
$getClustersReq = new Request('clusterDefault/getAll', ['class' => $class]);
|
|
$getClusters = $getClustersReq->dispatch();
|
|
|
|
/* (2) si erreur, on retourne rien par défaut */
|
|
if( $getClusters->error->get() != Err::Success )
|
|
return [];
|
|
|
|
/* (3) On enregistre le résultat */
|
|
return $getClusters->get('clusters');
|
|
}));
|
|
|
|
$twig->addFunction(new \Twig_Function('f_members', function($id_cluster, $class){
|
|
$membersReq = new Request('clusterDefault/getMembers', [
|
|
'id_cluster' => (int) $id_cluster,
|
|
'class' => $class
|
|
]);
|
|
|
|
$membersRes = $membersReq->dispatch();
|
|
//
|
|
// si erreur, on affiche rien par défaut
|
|
if( $membersRes->error->get() != Err::Success )
|
|
return [];
|
|
|
|
return $membersRes->get('members');
|
|
}));
|
|
|
|
|
|
/* [4] Build the whole stuff
|
|
=========================================================*/
|
|
return $twig->render('group/view.twig', [
|
|
'p_icon' => $variables['p_icon'],
|
|
'p_theme' => $variables['p_theme']
|
|
]);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|