127 lines
3.5 KiB
PHP
127 lines
3.5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace view\group\member\choice;
|
||
|
|
||
|
use \generic\core\i_view;
|
||
|
use \api\core\Request;
|
||
|
use \error\core\Err;
|
||
|
use \generic\core\View;
|
||
|
|
||
|
|
||
|
class main extends i_view{
|
||
|
|
||
|
public $class;
|
||
|
public $name;
|
||
|
public $id_cluster;
|
||
|
|
||
|
public function __construct(String $id_cluster, int $class){
|
||
|
|
||
|
/* (1) On vérifie le type de groupe (user/machine)
|
||
|
---------------------------------------------------------*/ {
|
||
|
|
||
|
/* (1) On vérifie les paramètres */
|
||
|
if( !isset($id_cluster) || !is_numeric($id_cluster) || !isset($class) || !is_numeric($class) )
|
||
|
return View::$html_error;
|
||
|
|
||
|
/* (2) On récupère le groupe */
|
||
|
$checktypeRequest = new Request('clusterDefault/getById', [
|
||
|
'id_cluster' => $id_cluster,
|
||
|
'class' => $class
|
||
|
]);
|
||
|
$checktypeResponse = $checktypeRequest->dispatch();
|
||
|
|
||
|
/* (3) Si on ne le trouve pas, on retourne une erreur */
|
||
|
if( $checktypeResponse->error->get() != Err::Success )
|
||
|
return View::$html_error;
|
||
|
|
||
|
/* (4) On récupère les données du groupe */
|
||
|
$currentCluster = $checktypeResponse->get('cluster');
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/* (2) Fill attributes
|
||
|
---------------------------------------------------------*/
|
||
|
$this->id_cluster = $id_cluster;
|
||
|
$this->class = $class;
|
||
|
$this->name = $currentCluster['name'];
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
public function get_members($id_cluster, $class){
|
||
|
|
||
|
/* (1) On récupère les membres
|
||
|
---------------------------------------------------------*/ {
|
||
|
|
||
|
/* (1) On exécute la requête */
|
||
|
$getmembersRequest = new Request('clusterDefault/getMembers', [
|
||
|
'id_cluster' => $id_cluster,
|
||
|
'class' => $class
|
||
|
]);
|
||
|
$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('members') as $member)
|
||
|
$members_ids[] = ($class==0) ? $member['id_user'] : $member['id_machine'];
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/* (2) On récupère les utilisateurs non membres
|
||
|
---------------------------------------------------------*/
|
||
|
/* (1) On récupère les utilisateurs */
|
||
|
if( $class == 0 ){
|
||
|
|
||
|
/* (2) On exécute la requête */
|
||
|
$getusersRequest = new Request('userDefault/getAll');
|
||
|
// On recupere la reponse
|
||
|
$getusersResponse = $getusersRequest->dispatch();
|
||
|
|
||
|
/* (3) si erreur, on affiche l'explicitation */
|
||
|
if( $getusersResponse->error->get() != Err::Success )
|
||
|
return [];
|
||
|
|
||
|
/* (4) On récupère la liste des utilisateurs */
|
||
|
$users = $getusersResponse->get('users');
|
||
|
|
||
|
/* (5) On ajoute s'ils sont dans le groupe ou non */
|
||
|
foreach($users as $u=>$user)
|
||
|
$users[$u]['already'] = in_array($user['id_user'], $members_ids);
|
||
|
return $users;
|
||
|
|
||
|
|
||
|
/* (3) On récupère les machines non membres
|
||
|
---------------------------------------------------------*/
|
||
|
/* (1) On récupère les machines */
|
||
|
}else{
|
||
|
|
||
|
/* (2) On exécute la requête */
|
||
|
$getmachinesRequest = new Request('machineDefault/getAll');
|
||
|
// On recupere la reponse
|
||
|
$getmachinesResponse = $getmachinesRequest->dispatch();
|
||
|
|
||
|
/* (3) si erreur, on affiche l'explicitation */
|
||
|
if( $getmachinesResponse->error->get() != Err::Success )
|
||
|
return [];
|
||
|
|
||
|
/* (4) On récupère la liste des machines */
|
||
|
$machines = $getmachinesResponse->get('machines');
|
||
|
|
||
|
/* (5) On ajoute s'ils sont dans le groupe ou non */
|
||
|
foreach($machines as $u=>$machine)
|
||
|
$machines[$u]['already'] = in_array($machine['id_machine'], $members_ids);
|
||
|
|
||
|
return $machines;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|