105 lines
2.8 KiB
PHP
105 lines
2.8 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace viewer\view\group;
|
||
|
use \viewer\core\Viewer;
|
||
|
use \api\core\ModuleRequest;
|
||
|
use \api\core\Authentification;
|
||
|
use \error\core\Error;
|
||
|
|
||
|
class permission{
|
||
|
|
||
|
public static function render(){
|
||
|
debug();
|
||
|
/* [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' ),
|
||
|
'device' => file_get_contents( __PUBLIC__.'/src/static/menu-side/device.svg' ),
|
||
|
'permission' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/permission.svg')
|
||
|
],
|
||
|
|
||
|
'p_theme' => $_SESSION['WAREHOUSE']['theme']
|
||
|
];
|
||
|
|
||
|
/* [3] Store functions
|
||
|
=========================================================*/
|
||
|
$twig->addFunction(new \Twig_Function('f_clusters', function(){
|
||
|
$request = new ModuleRequest('clusterDefault/getAll', [
|
||
|
'class' => 1
|
||
|
]);
|
||
|
|
||
|
$answer = $request->dispatch();
|
||
|
|
||
|
// si erreur, on affiche rien par défaut
|
||
|
if( $answer->error != Error::Success )
|
||
|
return [];
|
||
|
|
||
|
return $answer->get('clusters');
|
||
|
|
||
|
}));
|
||
|
|
||
|
$twig->addFunction(new \Twig_Function('f_nbmachines', function($id_cluster){
|
||
|
$machineReq = new ModuleRequest('clusterDefault/getMembers', [
|
||
|
'id_cluster' => (int) $id_cluster,
|
||
|
'class' => 1
|
||
|
]);
|
||
|
|
||
|
$machineRes = $machineReq->dispatch();
|
||
|
|
||
|
// si erreur, on affiche rien par défaut
|
||
|
if( $machineRes->error != Error::Success )
|
||
|
return [];
|
||
|
|
||
|
return count($machineRes->get('members'));
|
||
|
}));
|
||
|
|
||
|
$twig->addFunction(new \Twig_Function('f_permissions', function(){
|
||
|
$permReq = new ModuleRequest('clusterDefault/getPermissions', []);
|
||
|
|
||
|
$permRes = $permReq->dispatch();
|
||
|
|
||
|
// si erreur, on affiche rien par défaut
|
||
|
if( $permRes->error != Error::Success )
|
||
|
return [];
|
||
|
|
||
|
return $permRes->get('permissions');
|
||
|
}));
|
||
|
|
||
|
$twig->addFunction(new \Twig_Function('f_userclusters', function($id_cluster, $id_permission){
|
||
|
$ucReq = new ModuleRequest('clusterDefault/getAuthenticatedClusters', [
|
||
|
'id_target' => $id_cluster,
|
||
|
'id_action' => $id_permission
|
||
|
]);
|
||
|
|
||
|
$ucRes = $ucReq->dispatch();
|
||
|
|
||
|
// si erreur, on affiche rien par défaut
|
||
|
if( $ucRes->error != Error::Success )
|
||
|
return [];
|
||
|
|
||
|
return $ucRes->get('clusters');
|
||
|
}));
|
||
|
|
||
|
|
||
|
/* [4] Build the whole stuff
|
||
|
=========================================================*/
|
||
|
return $twig->render('group/permission.twig', [
|
||
|
'p_icon' => $variables['p_icon'],
|
||
|
'p_theme' => $variables['p_theme']
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
?>
|