Correction : 'class' pour le type d'entité dans 'cluster' plutôt que 'cluster_merge'
This commit is contained in:
parent
ddc3e7a752
commit
22c130bff7
|
@ -355,6 +355,98 @@
|
|||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
"clusterDefault": {
|
||||
|
||||
"create": {
|
||||
"description": "Création d'un nouveau groupe.",
|
||||
"permissions": ["warehouse", "admin"],
|
||||
"parameters": {
|
||||
"name": { "description": "Nom de l'entrepot", "type": "varchar(1,30,alphanumeric)" }
|
||||
},
|
||||
"output": {
|
||||
"id_cluster": { "description": "UID du groupe créé.", "type": "id" }
|
||||
}
|
||||
},
|
||||
|
||||
"search": {
|
||||
"description": "Recherche d'un groupe par mots-clés.",
|
||||
"permissions": ["warehouse", "admin"],
|
||||
"parameters": {
|
||||
"keywords": { "description": "Mots-clés de la recherche.", "type": "text" }
|
||||
},
|
||||
"output": {
|
||||
"clusters": { "description": "Liste des groupes correspondants aux mots-clés.", "type": "array<mixed>" }
|
||||
}
|
||||
},
|
||||
|
||||
"getAll": {
|
||||
"description": "Liste de tous les groupes",
|
||||
"permissions": ["warehouse", "admin"],
|
||||
"parameters": {},
|
||||
"output": {
|
||||
"clusters": { "description": "Liste de tous les groupes.", "type": "array<array<mixed>>" }
|
||||
}
|
||||
},
|
||||
|
||||
"getById": {
|
||||
"description": "Retourne un groupe spécifique.",
|
||||
"permissions": ["warehouse", "admin"],
|
||||
"parameters": {
|
||||
"id_cluster": { "description": "UID du groupe.", "type": "id" }
|
||||
},
|
||||
"output": {
|
||||
"cluster": { "description": "Données du groupe.", "type": "array<mixed>" }
|
||||
}
|
||||
},
|
||||
|
||||
"getByName": {
|
||||
"description": "Retourne un groupe de nom donné.",
|
||||
"permissions": ["warehouse", "admin"],
|
||||
"parameters": {
|
||||
"name": { "description": "Nom du groupe.", "type": "varchar(1,30,alphanumeric)" }
|
||||
},
|
||||
"output": {
|
||||
"cluster": { "description": "Données du groupe.", "type": "array<mixed>" }
|
||||
}
|
||||
},
|
||||
|
||||
"getMembers": {
|
||||
"description": "Retourne les membres d'un groupe.",
|
||||
"permissions": ["warehouse", "admin"],
|
||||
"parameters": {
|
||||
"id_cluster": { "description": "UID du groupe.", "type": "id" }
|
||||
},
|
||||
"output": {
|
||||
"members": { "description": "Liste des membres du groupe.", "type": "array<array<mixed>>" }
|
||||
}
|
||||
},
|
||||
|
||||
"edit": {
|
||||
"description": "Modifie le nom d'un groupe.",
|
||||
"permissions": ["warehouse", "admin"],
|
||||
"parameters": {
|
||||
"id_cluster": { "description": "UID du groupe.", "type": "id" },
|
||||
"name": { "description": "Nom du groupe.", "type": "varchar(1,30,alphanumeric)", "optional": true }
|
||||
},
|
||||
"output": {
|
||||
"status": { "description": "Status de la modification.", "type": "boolean" }
|
||||
}
|
||||
},
|
||||
|
||||
"delete": {
|
||||
"description": "Suppression d'un groupe.",
|
||||
"permissions": ["warehouse", "admin"],
|
||||
"parameters": {
|
||||
"id_cluster": { "description": "UID du groupe.", "type": "id" }
|
||||
},
|
||||
"output": {
|
||||
"status": { "description": "Status de la suppression.", "type": "boolean" }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,420 @@
|
|||
<?php
|
||||
|
||||
namespace manager\module;
|
||||
use \manager\Database;
|
||||
use \manager\sessionManager;
|
||||
use \manager\ManagerError;
|
||||
use \manager\Repo;
|
||||
use \manager\repo\cluster as clusterRepo;
|
||||
|
||||
class clusterDefault{
|
||||
|
||||
|
||||
/* CREATION D'UN NOUVEL UTILISATEUR DANS LA BDD
|
||||
*
|
||||
* @code<String> Code RFID de l'utilisateur
|
||||
* @username<String> Identifiant l'utilisateur
|
||||
* @firstname<String> Prenom de l'utilisateur
|
||||
* @lastcode<String> Nom de l'utilisateur
|
||||
* @mail<String> Adresse email de l'utilisateur
|
||||
* @password<String> Mot de passe de l'utilisateur
|
||||
* @status<String> Status de l'utilisateur
|
||||
*
|
||||
* @return status<Boolean> Retourne si oui ou non, tout s'est bien passe
|
||||
*
|
||||
*/
|
||||
public static function create($params){
|
||||
extract($params);
|
||||
|
||||
/* [1] Normalisation + verification des donnees
|
||||
=========================================================*/
|
||||
$password_hash = sessionManager::secure_hash($password);
|
||||
|
||||
/* [2] Creation de l'utilisateur
|
||||
=========================================================*/
|
||||
$create_user = new Repo('user/create', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$code,
|
||||
$username,
|
||||
$firstname,
|
||||
$lastname,
|
||||
$mail,
|
||||
$password_hash,
|
||||
$status
|
||||
]);
|
||||
$id_user = $create_user->answer();
|
||||
|
||||
var_dump($create_user);
|
||||
|
||||
// Si une erreur est retournee, on retourne une erreur
|
||||
if( $id_user === false )
|
||||
return ['ModuleError' => ManagerError::ModuleError];
|
||||
|
||||
|
||||
|
||||
/* [3] Creation du groupe de meme nom que l'username
|
||||
=========================================================*/
|
||||
$create_group = new Repo('cluster/create', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$username
|
||||
]);
|
||||
$id_group = $create_group->answer();
|
||||
|
||||
// Si une erreur est retournee, on retourne une erreur
|
||||
if( $id_group === false )
|
||||
return ['ModuleError' => ManagerError::ModuleError];
|
||||
|
||||
|
||||
|
||||
|
||||
/* [4] Association au groupe
|
||||
=========================================================*/
|
||||
$assoc_goup = new Repo('cluster/link', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_group,
|
||||
$id_user,
|
||||
clusterRepo::USER_CLASS
|
||||
]);
|
||||
$id_assoc = $assoc_goup->answer();
|
||||
|
||||
// Si une erreur est retournee, on retourne une erreur
|
||||
if( $id_assoc === false )
|
||||
return ['ModuleError' => ManagerError::ModuleError];
|
||||
|
||||
|
||||
|
||||
/* [5] Gestion du retour
|
||||
=========================================================*/
|
||||
return [
|
||||
'id_user' => $id_user,
|
||||
'id_cluster' => $id_group
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* AJOUTE UN UTILISATEUR DONNEE A UN GROUPE DONNE
|
||||
*
|
||||
* @id_cluster<int> UID du groupe
|
||||
* @id_user<int> UID de l'utilisateur
|
||||
*
|
||||
* @return association<int> Renvoie l'UID de l'association cree
|
||||
* Renvoie FALSE si une erreur occure
|
||||
*
|
||||
*/
|
||||
public static function link($params){
|
||||
extract($params);
|
||||
|
||||
/* [1] Creation de l'association
|
||||
=========================================================*/
|
||||
$link_user = new Repo('cluster/link', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_cluster,
|
||||
$id_user,
|
||||
clusterRepo::USER_CLASS
|
||||
]);
|
||||
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RETIRE UNE MACHINE DONNEE A UN GROUPE DONNE
|
||||
*
|
||||
* @id_cluster<int> UID du groupe
|
||||
* @id_user<int> UID de l'utilisateur
|
||||
*
|
||||
* @return association<int> Renvoie l'UID de l'association cree
|
||||
* Renvoie FALSE si une erreur occure
|
||||
*
|
||||
*/
|
||||
public static function unlink($params){
|
||||
extract($params);
|
||||
|
||||
/* [1] Suppression de l'association
|
||||
=========================================================*/
|
||||
$link_user = new Repo('cluster/unlink', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_cluster,
|
||||
$id_user,
|
||||
clusterRepo::USER_CLASS
|
||||
]);
|
||||
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RENVOIE UN UTILISATEUR EN FONCTION D'UN MOT CLE
|
||||
*
|
||||
* @keywords<String> Element de recherche
|
||||
*
|
||||
* @return users<Array> Retourne la liste des utilisateurs trouves
|
||||
*
|
||||
*/
|
||||
public static function search($params){
|
||||
extract($params);
|
||||
|
||||
// On recupere les donnees
|
||||
$user = new Repo('user/search', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$keywords
|
||||
]);
|
||||
|
||||
return [ 'users' => $user->answer() ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RENVOIE LA LISTE EXHAUSTIVE DES UTILISATEURS
|
||||
*
|
||||
* @return utilisateurs<Array> Liste des utilisateurs
|
||||
*
|
||||
*/
|
||||
public static function getAll(){
|
||||
// On recupere les donnees
|
||||
$users = new Repo('user/getAll', [ $_SESSION['WAREHOUSE']['id'] ]);
|
||||
|
||||
return [ 'users' => $users->answer() ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RENVOIE L'UTILISATEURS D'UID DONNE
|
||||
*
|
||||
* @id_user<int> UID de l'utilisateur en question
|
||||
*
|
||||
* @return utilisateur<Array> Utilisateur d'UID donne
|
||||
*
|
||||
*/
|
||||
public static function getById($params){
|
||||
extract($params);
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/getById', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_user
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
if( $answer === false )
|
||||
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
||||
|
||||
|
||||
return [ 'user' => $answer ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RENVOIE L'UTILISATEURS DE CODE DONNE
|
||||
*
|
||||
* @code<String> Code de l'utilisateur en question
|
||||
*
|
||||
* @return utilisateur<Array> Utilisateur de code donne
|
||||
*
|
||||
*/
|
||||
public static function getByCode($params){
|
||||
extract($params);
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/getByCode', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$code
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
if( $answer === false )
|
||||
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
||||
|
||||
|
||||
return [ 'user' => $answer ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RENVOIE L'UTILISATEURS D'USERNAME DONNE
|
||||
*
|
||||
* @username<String> Username de l'utilisateur en question
|
||||
*
|
||||
* @return utilisateur<Array> Utilisateur d'username donne
|
||||
*
|
||||
*/
|
||||
public static function getByUsername($params){
|
||||
extract($params);
|
||||
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/getByUsername', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$username
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
if( $answer === false )
|
||||
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
||||
|
||||
|
||||
return [ 'user' => $answer ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RENVOIE LES GROUPES D'UN UTILISATEUR DONNE
|
||||
*
|
||||
* @id_user<int> UID de l'utilisateur en question
|
||||
*
|
||||
* @return clusters<Array> Groupes de l'utilisateur donne
|
||||
*
|
||||
*/
|
||||
public static function getClusters($params){
|
||||
extract($params);
|
||||
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/getClusters', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_user
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
if( $answer === false )
|
||||
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
||||
|
||||
|
||||
return [ 'clusters' => $answer ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* MODIFIE UN UTILISATEUR DONNEE
|
||||
*
|
||||
* @id_user<int> UID de l'utilisateur
|
||||
* @code<String> Code RFID de l'utilisateur
|
||||
* @username<String> Identifiant l'utilisateur
|
||||
* @firstname<String> Prenom de l'utilisateur
|
||||
* @lastcode<String> Nom de l'utilisateur
|
||||
* @mail<String> Adresse email de l'utilisateur
|
||||
* @password<String> Mot de passe de l'utilisateur
|
||||
* @status<String> Status de l'utilisateur
|
||||
*
|
||||
* @return status<Boolean> Retourne si oui ou non tout s'est bien deroule
|
||||
*
|
||||
*/
|
||||
public static function edit($params){
|
||||
extract($params);
|
||||
|
||||
/* [1] On verifie l'existence de l'utilisateur
|
||||
=========================================================*/
|
||||
$user_exists = new Repo('user/getById', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_user
|
||||
]);
|
||||
$user_data = $user_exists->answer();
|
||||
|
||||
// Si on a recupere aucun utilisateur, on retourne une erreur
|
||||
if( !is_array($user_data) )
|
||||
return ['ModuleError' => ManagerError::NoMatchFound];
|
||||
|
||||
|
||||
|
||||
/* [2] Normalisation + verification des donnees
|
||||
=========================================================*/
|
||||
$password_hash = sessionManager::secure_hash($password);
|
||||
|
||||
/* (1) Verification des parametres (si non nul + differents)*/
|
||||
$diff_param = [
|
||||
'code' => !is_null($code) && $user_data['code'] != $code,
|
||||
'username' => !is_null($username) && $user_data['username'] != $username,
|
||||
'firstname' => !is_null($firstname) && $user_data['firstname'] != $firstname,
|
||||
'lastname' => !is_null($lastname) && $user_data['lastname'] != $lastname,
|
||||
'mail' => !is_null($mail) && $user_data['mail'] != $mail,
|
||||
'password' => !is_null($password) && $user_data['password'] != $password_hash,
|
||||
'status' => !is_null($status) && $user_data['status'] != $status
|
||||
];
|
||||
|
||||
/* (2) Gestion des parametres optionnels */
|
||||
$opt_data = [
|
||||
'code' => ($diff_param['code']) ? $code : $user_data['code'],
|
||||
'username' => ($diff_param['username']) ? $username : $user_data['username'],
|
||||
'firstname' => ($diff_param['firstname']) ? $firstname : $user_data['firstname'],
|
||||
'lastname' => ($diff_param['lastname']) ? $lastname : $user_data['lastname'],
|
||||
'mail' => ($diff_param['mail']) ? $mail : $user_data['mail'],
|
||||
'password' => ($diff_param['password']) ? $password : $user_data['password'],
|
||||
'status' => ($diff_param['status']) ? $status : $user_data['status'],
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
/* [3] Modification de l'utilisateur
|
||||
=========================================================*/
|
||||
$request = new Repo('user/edit', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_user,
|
||||
$opt_data['code'],
|
||||
$opt_data['username'],
|
||||
$opt_data['firstname'],
|
||||
$opt_data['lastname'],
|
||||
$opt_data['mail'],
|
||||
$opt_data['password'],
|
||||
$opt_data['status']
|
||||
]);
|
||||
|
||||
|
||||
return [ 'status' => $request->answer() ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* SUPPRIME UN UTILISATEUR DONNEE
|
||||
*
|
||||
* @id_user<int> UID de l'utilisateur en question
|
||||
*
|
||||
* @return status<Boolean> Retourne si oui ou non tout s'est bien deroule
|
||||
*
|
||||
*/
|
||||
public static function delete($params){
|
||||
extract($params);
|
||||
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/delete', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_user
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
return [ 'status' => $answer ];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -39,7 +39,8 @@
|
|||
=========================================================*/
|
||||
$create_group = new Repo('cluster/create', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$name
|
||||
$name,
|
||||
clusterRepo::MACHINE_CLASS
|
||||
]);
|
||||
$id_group = $create_group->answer();
|
||||
|
||||
|
|
|
@ -56,7 +56,8 @@
|
|||
=========================================================*/
|
||||
$create_group = new Repo('cluster/create', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$username
|
||||
$username,
|
||||
clusterRepo::USER_CLASS
|
||||
]);
|
||||
$id_group = $create_group->answer();
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* Renvoie FALSE si une erreur occure
|
||||
*
|
||||
*/
|
||||
public static function create($id_warehouse, $name){
|
||||
public static function create($id_warehouse, $name, $class){
|
||||
/* [1] Verification de l'unicite de name
|
||||
=========================================================*/
|
||||
$check_unique = ( self::getByName($id_warehouse, $name) === false );
|
||||
|
@ -33,11 +33,12 @@
|
|||
|
||||
/* [2] Creation du groupe
|
||||
=========================================================*/
|
||||
$insert_user = Database::getPDO()->prepare("INSERT INTO cluster(id_cluster, id_warehouse, name)
|
||||
VALUES(DEFAULT, :id_warehouse, :name)");
|
||||
$insert_user = Database::getPDO()->prepare("INSERT INTO cluster(id_cluster, id_warehouse, name, class)
|
||||
VALUES(DEFAULT, :id_warehouse, :name, :class)");
|
||||
$insert_user->execute([
|
||||
':id_warehouse' => $id_warehouse,
|
||||
':name' => $name
|
||||
':name' => $name,
|
||||
':class' => $class
|
||||
]);
|
||||
|
||||
/* [3] On retourne l'id_group ou FALSE si erreur
|
||||
|
@ -114,12 +115,11 @@
|
|||
|
||||
/* [4] On cree l'association
|
||||
=========================================================*/
|
||||
$link_entity = Database::getPDO()->prepare("INSERT INTO cluster_merge(id_cluster_merge, id_cluster, id_entity, class)
|
||||
VALUES(DEFAULT, :id_cluster, :id_entity, :class)");
|
||||
$link_entity = Database::getPDO()->prepare("INSERT INTO cluster_merge(id_cluster_merge, id_cluster, id_entity)
|
||||
VALUES(DEFAULT, :id_cluster, :id_entity)");
|
||||
$link_entity->execute([
|
||||
':id_cluster' => $id_cluster,
|
||||
':id_entity' => $id_entity,
|
||||
':class' => $class
|
||||
':id_entity' => $id_entity
|
||||
]);
|
||||
|
||||
/* [5] On retourne l'id_cluster_merge ou FALSE si erreur
|
||||
|
@ -159,7 +159,7 @@
|
|||
AND c.id_warehouse = :id_warehouse
|
||||
AND cm.id_cluster = :id_cluster
|
||||
AND cm.id_entity = :id_entity
|
||||
AND cm.class = :class");
|
||||
AND c.class = :class");
|
||||
$delete_cluster_merge->execute([
|
||||
':id_warehouse' => $id_warehouse,
|
||||
':id_cluster' => $id_cluster,
|
||||
|
@ -191,10 +191,12 @@
|
|||
*/
|
||||
public static function getMerge($id_cluster, $id_entity, $class){
|
||||
// On ecrit la requete
|
||||
$request = Database::getPDO()->prepare("SELECT * FROM cluster_merge
|
||||
WHERE id_cluster = :id_cluster
|
||||
AND id_entity = :id_entity
|
||||
AND class = :class");
|
||||
$request = Database::getPDO()->prepare("SELECT cm.*
|
||||
FROM cluster_merge as cm, cluster as c
|
||||
WHERE cm.id_cluster = c.id_cluster
|
||||
AND cm.id_cluster = :id_cluster
|
||||
AND cm.id_entity = :id_entity
|
||||
AND c.class = :class");
|
||||
|
||||
// On execute la requete
|
||||
$request->execute([
|
||||
|
|
Loading…
Reference in New Issue