2016-07-08 15:47:03 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
namespace api\module;
|
|
|
|
use \viewer\core\Viewer;
|
|
|
|
use \database\core\Database;
|
2016-07-08 15:47:03 +00:00
|
|
|
use \manager\sessionManager;
|
|
|
|
use \manager\ManagerError;
|
2016-10-18 14:03:03 +00:00
|
|
|
use \database\core\Repo;
|
2016-07-08 15:47:03 +00:00
|
|
|
use \manager\repo\cluster as clusterRepo;
|
|
|
|
|
|
|
|
class clusterDefault{
|
|
|
|
|
|
|
|
|
|
|
|
/* CREATION D'UN NOUVEL UTILISATEUR DANS LA BDD
|
|
|
|
*
|
2016-07-11 15:44:18 +00:00
|
|
|
* @name<String> Nom du groupe
|
|
|
|
* @class<int> Type de groupe (0:user;1:machine)
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-11 15:44:18 +00:00
|
|
|
* @return id_cluster<int> Retourne l'UID du groupe
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function create($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
/* [2] Creation du groupe
|
2016-07-08 15:47:03 +00:00
|
|
|
=========================================================*/
|
2016-07-18 14:46:06 +00:00
|
|
|
$repoMethod = ($class==0) ? 'user_cluster/create' : 'machine_cluster/create';
|
|
|
|
|
|
|
|
$create_cluster = new Repo($repoMethod, [
|
2016-07-08 15:47:03 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-07-18 14:46:06 +00:00
|
|
|
$name
|
2016-07-08 15:47:03 +00:00
|
|
|
]);
|
2016-07-11 15:44:18 +00:00
|
|
|
$id_cluster = $create_cluster->answer();
|
2016-07-08 15:47:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
2016-07-11 15:44:18 +00:00
|
|
|
if( $id_cluster === false )
|
2016-07-08 15:47:03 +00:00
|
|
|
return ['ModuleError' => ManagerError::ModuleError];
|
|
|
|
|
|
|
|
|
|
|
|
/* [5] Gestion du retour
|
|
|
|
=========================================================*/
|
|
|
|
return [
|
2016-07-11 15:44:18 +00:00
|
|
|
'id_cluster' => $id_cluster
|
2016-07-08 15:47:03 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
/* RENVOIE UN GROUPE EN FONCTION D'UN MOT CLE
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
|
|
|
* @keywords<String> Element de recherche
|
2016-07-20 17:01:11 +00:00
|
|
|
* @class<int> Type de groupe (0:user;1:machine) [OPTIONNEL]
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-18 14:46:06 +00:00
|
|
|
* @return clusters<Array> Retourne la liste des groupes trouves
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function search($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-07-20 17:01:11 +00:00
|
|
|
$result = [];
|
2016-07-08 15:47:03 +00:00
|
|
|
|
2016-07-20 17:01:11 +00:00
|
|
|
if( is_null($class) || $class == 0 ){
|
2016-07-20 16:16:36 +00:00
|
|
|
|
2016-07-20 17:01:11 +00:00
|
|
|
// On recupere les donnees des groupes utilisateurs
|
|
|
|
$userClusters = new Repo('user_cluster/search', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$keywords
|
|
|
|
]);
|
|
|
|
|
|
|
|
$result = array_merge($result, $userClusters->answer());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( is_null($class) || $class == 1 ){
|
|
|
|
|
|
|
|
// On recupere les donnees des groupes utilisateurs
|
|
|
|
$machineClusters = new Repo('machine_cluster/search', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$keywords
|
|
|
|
]);
|
|
|
|
|
|
|
|
$result = array_merge($result, $machineClusters->answer());
|
|
|
|
|
|
|
|
}
|
2016-07-20 16:16:36 +00:00
|
|
|
|
|
|
|
|
2016-07-20 17:01:11 +00:00
|
|
|
return [ 'clusters' => $result ];
|
2016-07-08 15:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-08 18:28:44 +00:00
|
|
|
/* RENVOIE LA LISTE EXHAUSTIVE DES GROUPES
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-18 14:46:06 +00:00
|
|
|
* @class<int> Type de groupe
|
|
|
|
*
|
2016-07-08 18:28:44 +00:00
|
|
|
* @return clusters<Array> Liste des groupes
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-07-18 14:46:06 +00:00
|
|
|
public static function getAll($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-07-20 17:41:43 +00:00
|
|
|
$result = [];
|
|
|
|
|
|
|
|
if( is_null($class) || $class == 0 ){
|
|
|
|
|
|
|
|
// On recupere les donnees des groupes utilisateurs
|
|
|
|
$userClusters = new Repo('user_cluster/getAll', [
|
|
|
|
$_SESSION['WAREHOUSE']['id']
|
|
|
|
]);
|
|
|
|
|
|
|
|
$result = array_merge($result, $userClusters->answer());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( is_null($class) || $class == 1 ){
|
|
|
|
|
|
|
|
// On recupere les donnees des groupes utilisateurs
|
|
|
|
$machineClusters = new Repo('machine_cluster/getAll', [
|
|
|
|
$_SESSION['WAREHOUSE']['id']
|
|
|
|
]);
|
|
|
|
|
|
|
|
$result = array_merge($result, $machineClusters->answer());
|
|
|
|
|
|
|
|
}
|
2016-07-18 14:46:06 +00:00
|
|
|
|
2016-07-08 15:47:03 +00:00
|
|
|
|
2016-07-20 17:41:43 +00:00
|
|
|
return [ 'clusters' => $result ];
|
2016-07-08 15:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* RENVOIE UN GROUPE D'UID DONNE
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-13 14:58:39 +00:00
|
|
|
* @id_cluster<int> UID du groupe en question
|
2016-07-18 14:46:06 +00:00
|
|
|
* @class<int> Type de groupe
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-13 14:58:39 +00:00
|
|
|
* @return cluster<Array> Groupe d'UID donne
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getById($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
$repoMethod = ($class==0) ? 'user_cluster/getById' : 'machine_cluster/getById';
|
|
|
|
|
2016-07-08 15:47:03 +00:00
|
|
|
// On recupere les donnees
|
2016-07-18 14:46:06 +00:00
|
|
|
$request = new Repo($repoMethod, [
|
2016-07-08 15:47:03 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-07-13 14:58:39 +00:00
|
|
|
$id_cluster
|
2016-07-08 15:47:03 +00:00
|
|
|
]);
|
2016-07-18 14:46:06 +00:00
|
|
|
$answer = $request->answer();
|
2016-07-08 15:47:03 +00:00
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
|
|
|
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
return [ 'cluster' => $answer ];
|
2016-07-08 15:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
/* RENVOIE UN GROUPE DE NOM DONNE
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-18 14:46:06 +00:00
|
|
|
* @name<String> Nom du groupe en question
|
|
|
|
* @class<int> Type de groupe
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-18 14:46:06 +00:00
|
|
|
* @return cluster<Array> Groupe de nom donne
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-07-18 14:46:06 +00:00
|
|
|
public static function getByName($params){
|
2016-07-08 15:47:03 +00:00
|
|
|
extract($params);
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
$repoMethod = ($class==0) ? 'user_cluster/getByName' : 'machine_cluster/getByName';
|
2016-07-08 15:47:03 +00:00
|
|
|
|
|
|
|
// On recupere les donnees
|
2016-07-18 14:46:06 +00:00
|
|
|
$request = new Repo($repoMethod, [
|
2016-07-08 15:47:03 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-07-18 14:46:06 +00:00
|
|
|
$name
|
2016-07-08 15:47:03 +00:00
|
|
|
]);
|
2016-07-18 14:46:06 +00:00
|
|
|
$answer = $request->answer();
|
2016-07-08 15:47:03 +00:00
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
|
|
|
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
|
|
|
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
return [ 'cluster' => $answer ];
|
2016-07-08 15:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-09 10:44:06 +00:00
|
|
|
/* RENVOIE LES MEMBRES D'UN GROUPE DONNE
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-09 10:44:06 +00:00
|
|
|
* @id_cluster<int> UID du groupe en question
|
2016-07-18 14:46:06 +00:00
|
|
|
* @class<int> Type du groupe en question
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-09 10:44:06 +00:00
|
|
|
* @return members<Array> Membres du groupe donne
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-07-09 10:44:06 +00:00
|
|
|
public static function getMembers($params){
|
2016-07-08 15:47:03 +00:00
|
|
|
extract($params);
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
$repoMethod = ($class==0) ? 'user_cluster/getMembers' : 'machine_cluster/getMembers';
|
2016-07-08 15:47:03 +00:00
|
|
|
|
|
|
|
// On recupere les donnees
|
2016-07-18 14:46:06 +00:00
|
|
|
$request = new Repo($repoMethod, [
|
2016-07-08 15:47:03 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-07-09 10:44:06 +00:00
|
|
|
$id_cluster
|
2016-07-08 15:47:03 +00:00
|
|
|
]);
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
|
|
|
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
|
|
|
|
|
|
|
|
2016-07-09 10:44:06 +00:00
|
|
|
return [ 'members' => $answer ];
|
2016-07-08 15:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
/* MODIFIE UN groupe DONNEE
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
2016-07-20 17:41:43 +00:00
|
|
|
* @id_cluster<int> UID du groupe
|
2016-07-18 14:46:06 +00:00
|
|
|
* @class<int> Type de groupe
|
|
|
|
* @name<String> Nouveau nom
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
|
|
|
* @return status<Boolean> Retourne si oui ou non tout s'est bien deroule
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function edit($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
|
2016-07-20 17:41:43 +00:00
|
|
|
/* [1] On verifie l'existence du groupe
|
2016-07-08 15:47:03 +00:00
|
|
|
=========================================================*/
|
2016-07-20 17:41:43 +00:00
|
|
|
$repo = ($class==0) ? 'user_cluster' : 'machine_cluster';
|
|
|
|
|
|
|
|
$cluster_exists = new Repo($repo.'/getById', [
|
2016-07-08 15:47:03 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-07-20 17:41:43 +00:00
|
|
|
$id_cluster
|
2016-07-08 15:47:03 +00:00
|
|
|
]);
|
2016-07-20 17:41:43 +00:00
|
|
|
$cluster_data = $cluster_exists->answer();
|
2016-07-08 15:47:03 +00:00
|
|
|
|
|
|
|
// Si on a recupere aucun utilisateur, on retourne une erreur
|
2016-07-20 17:41:43 +00:00
|
|
|
if( $cluster_data === false )
|
2016-07-08 15:47:03 +00:00
|
|
|
return ['ModuleError' => ManagerError::NoMatchFound];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Normalisation + verification des donnees
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Verification des parametres (si non nul + differents)*/
|
|
|
|
$diff_param = [
|
2016-07-20 17:41:43 +00:00
|
|
|
'name' => $cluster_data['name'] != $name
|
2016-07-08 15:47:03 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/* (2) Gestion des parametres optionnels */
|
|
|
|
$opt_data = [
|
2016-07-20 17:41:43 +00:00
|
|
|
'name' => ($diff_param['name']) ? $name : $cluster_data['name'],
|
2016-07-08 15:47:03 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
2016-07-20 17:41:43 +00:00
|
|
|
/* [3] Modification du groupe
|
2016-07-08 15:47:03 +00:00
|
|
|
=========================================================*/
|
2016-07-20 17:41:43 +00:00
|
|
|
$request = new Repo($repo.'/edit', [
|
2016-07-08 15:47:03 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-07-20 17:41:43 +00:00
|
|
|
$id_cluster,
|
|
|
|
$opt_data['name'],
|
2016-07-08 15:47:03 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
return [ 'status' => $request->answer() ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* SUPPRIME UN UTILISATEUR DONNEE
|
|
|
|
*
|
2016-07-18 14:46:06 +00:00
|
|
|
* @id_cluster<int> UID du groupe en question
|
|
|
|
* @class<int> Type de groupe
|
2016-07-08 15:47:03 +00:00
|
|
|
*
|
|
|
|
* @return status<Boolean> Retourne si oui ou non tout s'est bien deroule
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function delete($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
$repoMethod = ($class==0) ? 'user_cluster/delete' : 'machine_cluster/delete';
|
2016-07-08 15:47:03 +00:00
|
|
|
|
|
|
|
// On recupere les donnees
|
2016-07-18 14:46:06 +00:00
|
|
|
$request = new Repo($repoMethod, [
|
2016-07-08 15:47:03 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-07-18 14:46:06 +00:00
|
|
|
$id_cluster
|
2016-07-08 15:47:03 +00:00
|
|
|
]);
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
return [ 'status' => $answer ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|