113 lines
2.6 KiB
PHP
113 lines
2.6 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace view\group\permission;
|
||
|
|
||
|
use \generic\core\i_view;
|
||
|
use \api\core\Request;
|
||
|
use \error\core\Err;
|
||
|
use \generic\core\View;
|
||
|
|
||
|
|
||
|
class main extends i_view{
|
||
|
|
||
|
public function __construct(){
|
||
|
|
||
|
/* (1) Setup attributes
|
||
|
---------------------------------------------------------*/
|
||
|
/* (1) Fill attributes */
|
||
|
$this->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')
|
||
|
];
|
||
|
|
||
|
$this->theme = $_SESSION['WAREHOUSE']['theme'];
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
public function get_clusters(){
|
||
|
$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');
|
||
|
}
|
||
|
|
||
|
|
||
|
public function get_nb_machines($id_cluster){
|
||
|
$machineReq = new Request('clusterDefault/getMembers', [
|
||
|
'id_cluster' => (int) $id_cluster,
|
||
|
'class' => 1
|
||
|
]);
|
||
|
|
||
|
$machineRes = $machineReq->dispatch();
|
||
|
|
||
|
// si erreur, on affiche rien par défaut
|
||
|
if( $machineRes->error->get() != Err::Success )
|
||
|
return [];
|
||
|
|
||
|
return count($machineRes->get('members'));
|
||
|
}
|
||
|
|
||
|
|
||
|
public function get_permissions(){
|
||
|
$permReq = new Request('clusterDefault/getPermissions', []);
|
||
|
|
||
|
$permRes = $permReq->dispatch();
|
||
|
|
||
|
// si erreur, on affiche rien par défaut
|
||
|
if( $permRes->error->get() != Err::Success )
|
||
|
return [];
|
||
|
|
||
|
return $permRes->get('permissions');
|
||
|
}
|
||
|
|
||
|
|
||
|
public function get_authed_user_clusters($id_cluster, $id_permission){
|
||
|
$ucReq = new Request('clusterDefault/getAuthenticatedClusters', [
|
||
|
'id_target' => $id_cluster,
|
||
|
'id_action' => $id_permission
|
||
|
]);
|
||
|
|
||
|
$ucRes = $ucReq->dispatch();
|
||
|
|
||
|
// si erreur, on affiche rien par défaut
|
||
|
if( $ucRes->error->get() != Err::Success )
|
||
|
return [];
|
||
|
|
||
|
return $ucRes->get('clusters');
|
||
|
}
|
||
|
|
||
|
|
||
|
public function permission_translate($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;
|
||
|
case 'unsignal': return 'désignaler'; break;
|
||
|
|
||
|
default: return 'inconnu'; break;
|
||
|
}
|
||
|
}else
|
||
|
return $word;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|