SMMP/build/viewer/view/group/permission.php

126 lines
3.3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace viewer\view\group;
use \viewer\core\Viewer;
2017-01-30 17:39:21 +00:00
use \api\core\Request;
use \api\core\Authentification;
2017-01-30 17:39:21 +00:00
use \error\core\Err;
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(){
2017-01-30 17:39:21 +00:00
$request = new Request('clusterDefault/getAll', [
'class' => 1
]);
$answer = $request->dispatch();
// si erreur, on affiche rien par défaut
2017-01-30 17:39:21 +00:00
if( $answer->error->get() != Err::Success )
return [];
return $answer->get('clusters');
}));
$twig->addFunction(new \Twig_Function('f_nbmachines', function($id_cluster){
2017-01-30 17:39:21 +00:00
$machineReq = new Request('clusterDefault/getMembers', [
'id_cluster' => (int) $id_cluster,
'class' => 1
]);
$machineRes = $machineReq->dispatch();
// si erreur, on affiche rien par défaut
2017-01-30 17:39:21 +00:00
if( $machineRes->error->get() != Err::Success )
return [];
return count($machineRes->get('members'));
}));
$twig->addFunction(new \Twig_Function('f_permissions', function(){
2017-01-30 17:39:21 +00:00
$permReq = new Request('clusterDefault/getPermissions', []);
$permRes = $permReq->dispatch();
// si erreur, on affiche rien par défaut
2017-01-30 17:39:21 +00:00
if( $permRes->error->get() != Err::Success )
return [];
return $permRes->get('permissions');
}));
$twig->addFunction(new \Twig_Function('f_userclusters', function($id_cluster, $id_permission){
2017-01-30 17:39:21 +00:00
$ucReq = new Request('clusterDefault/getAuthenticatedClusters', [
'id_target' => $id_cluster,
'id_action' => $id_permission
]);
$ucRes = $ucReq->dispatch();
// si erreur, on affiche rien par défaut
2017-01-30 17:39:21 +00:00
if( $ucRes->error->get() != Err::Success )
return [];
return $ucRes->get('clusters');
}));
2017-01-17 13:22:33 +00:00
$twig->addFilter(new \Twig_Filter('translate', function($word, $lang){
$word = strtolower($word);
if( $lang === 'fr' ){
switch($word){
case 'start': return 'démarrer'; break;
case 'stop': return 'arrêter'; break;
case 'signal': return 'signaler'; break;
case 'lock': return 'bloquer'; break;
case 'unlock': return 'débloquer'; break;
default: return 'inconnu'; break;
}
}else
return $word;
2017-01-17 13:22:33 +00:00
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('group/permission.twig', [
'p_icon' => $variables['p_icon'],
'p_theme' => $variables['p_theme']
]);
}
}
?>