160 lines
4.8 KiB
PHP
160 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace viewer\view\group;
|
|
use \viewer\core\Viewer;
|
|
use \api\core\Request;
|
|
use \error\core\Err;
|
|
use \error\core\Error;
|
|
use \api\core\Authentification;
|
|
|
|
class permission_choice{
|
|
|
|
public static function render($params){
|
|
/* [1] On vérifie les param + fetch données du groupe
|
|
=========================================================*/
|
|
/* (1) On vérifie les paramètres */
|
|
if( !isset($params['id_target']) || !is_numeric($params['id_target']) || !isset($params['id_action']) || !is_numeric($params['id_action']) )
|
|
return Viewer::$htmlError;
|
|
|
|
|
|
/* (2) On récupère le groupe cible */
|
|
$checktypeRequest = new Request('clusterDefault/getById', [
|
|
'id_cluster' => $params['id_target'],
|
|
'class' => 1
|
|
]);
|
|
$checktypeResponse = $checktypeRequest->dispatch();
|
|
|
|
/* (3) Si on ne le trouve pas, on retourne une erreur */
|
|
if( $checktypeResponse->error->get() != Err::Success )
|
|
return Viewer::$htmlError;
|
|
|
|
/* (4) On récupère les données du groupe */
|
|
$currentCluster = $checktypeResponse->get('cluster');
|
|
|
|
|
|
|
|
/* [2] On récupère les données de l'action
|
|
=========================================================*/
|
|
/* (1) Rédige la requête */
|
|
$permlistRequest = new Request('clusterDefault/getPermissions', []);
|
|
$permlistResponse = $permlistRequest->dispatch();
|
|
|
|
/* (2) Manage error */
|
|
if( $permlistResponse->error->get() != Err::Success )
|
|
return Viewer::$htmlError;
|
|
|
|
/* (3) Get action name (non-translated) */
|
|
$action_name = null;
|
|
foreach($permlistResponse->get('permissions') as $perm)
|
|
if( $perm['id_permission'] == $params['id_action'] )
|
|
$action_name = $perm['name'];
|
|
|
|
/* (4) Manage error (not found) */
|
|
if( is_null($action_name) )
|
|
return Viewer::$htmlError;
|
|
|
|
|
|
|
|
/* [2] Init Twig
|
|
=========================================================*/
|
|
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
|
|
$twig = new \Twig_Environment($loader, []);
|
|
|
|
|
|
/* [3] Store variables
|
|
=========================================================*/
|
|
$variables = [
|
|
'p_permname' => $action_name,
|
|
'p_id_target' => $params['id_target'],
|
|
'p_id_permission' => $params['id_action'],
|
|
'p_name' => $currentCluster['name'],
|
|
'p_theme' => $_SESSION['WAREHOUSE']['theme']
|
|
];
|
|
|
|
/* [4] Store functions
|
|
=========================================================*/
|
|
$twig->addFunction(new \Twig_Function('f_userclusters', function($id_target, $id_action){
|
|
/* [1] On récupère les groupes utilisateurs
|
|
=========================================================*/
|
|
/* (1) On exécute la requête */
|
|
$getmembersRequest = new Request('clusterDefault/getAuthenticatedClusters', [
|
|
'id_target' => $id_target,
|
|
'id_action' => $id_action
|
|
]);
|
|
$getmembersResponse = $getmembersRequest->dispatch();
|
|
|
|
/* (2) Si erreur, on retourne rien par défaut */
|
|
if( $getmembersResponse->error->get() != Err::Success )
|
|
return [];
|
|
|
|
/* (3) On récupère la liste des UID uniquement */
|
|
$members_ids = [];
|
|
foreach($getmembersResponse->get('clusters') as $member)
|
|
$members_ids[] = $member['id_user_cluster'];
|
|
|
|
|
|
|
|
/* [2] On récupère les utilisateurs non membres
|
|
=========================================================*/
|
|
|
|
/* (2) On exécute la requête */
|
|
$getuclusterRequest = new Request('clusterDefault/getAll', [
|
|
'class' => 0
|
|
]);
|
|
$getuclustersResponse = $getuclusterRequest->dispatch();
|
|
|
|
/* (3) si erreur, on affiche l'explicitation */
|
|
if( $getuclustersResponse->error->get() != Err::Success )
|
|
return [];
|
|
|
|
/* (4) On récupère la liste des utilisateurs */
|
|
$uclusters = $getuclustersResponse->get('clusters');
|
|
|
|
/* (5) On ajoute s'ils sont dans le groupe ou non */
|
|
foreach($uclusters as $u=>$ucluster)
|
|
$uclusters[$u]['already'] = in_array($ucluster['id_user_cluster'], $members_ids);
|
|
return $uclusters;
|
|
|
|
}));
|
|
|
|
|
|
$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 $word; break;
|
|
}
|
|
}else
|
|
return $word;
|
|
|
|
}));
|
|
|
|
|
|
|
|
/* [5] Build the whole stuff
|
|
=========================================================*/
|
|
return $twig->render('group/permission_choice.twig', [
|
|
'p_permname' => $variables['p_permname'],
|
|
'p_id_permission' => $variables['p_id_permission'],
|
|
'p_name' => $variables['p_name'],
|
|
'p_id_target' => $variables['p_id_target'],
|
|
'p_theme' => $variables['p_theme']
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|