2016-02-11 15:00:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\module;
|
2016-02-13 17:41:19 +00:00
|
|
|
use \manager\Database;
|
|
|
|
use \manager\sessionManager;
|
|
|
|
use \manager\ManagerError;
|
|
|
|
use \manager\Repo;
|
2016-02-14 14:17:26 +00:00
|
|
|
use \manager\repo\cluster as clusterRepo;
|
2016-02-11 15:00:41 +00:00
|
|
|
|
|
|
|
class userDefault{
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function create($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-02-12 21:48:16 +00:00
|
|
|
/* [1] Normalisation + verification des donnees
|
|
|
|
=========================================================*/
|
2016-02-13 17:41:19 +00:00
|
|
|
$password_hash = sessionManager::secure_sha1($password);
|
2016-02-12 21:48:16 +00:00
|
|
|
|
2016-02-13 16:28:28 +00:00
|
|
|
/* [2] Creation de l'utilisateur
|
|
|
|
=========================================================*/
|
2016-02-13 17:41:19 +00:00
|
|
|
$create_user = new Repo('user/create', array($code, $username, $firstname, $lastname, $mail, $password_hash, $status) );
|
2016-02-13 16:28:28 +00:00
|
|
|
$id_user = $create_user->answer();
|
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_user === false )
|
2016-02-13 17:41:19 +00:00
|
|
|
return array('ModuleError' => ManagerError::ModuleError);
|
|
|
|
|
|
|
|
|
2016-02-13 16:28:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [3] Creation du groupe de meme nom que l'username
|
|
|
|
=========================================================*/
|
2016-02-14 11:37:19 +00:00
|
|
|
$create_group = new Repo('cluster/create', array($username) );
|
2016-02-13 16:28:28 +00:00
|
|
|
$id_group = $create_group->answer();
|
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_group === false )
|
2016-02-13 17:41:19 +00:00
|
|
|
return array('ModuleError' => ManagerError::ModuleError);
|
|
|
|
|
|
|
|
|
2016-02-12 23:04:00 +00:00
|
|
|
|
2016-02-13 16:28:28 +00:00
|
|
|
|
|
|
|
/* [4] Association au groupe
|
|
|
|
=========================================================*/
|
2016-02-14 14:17:26 +00:00
|
|
|
$assoc_goup = new Repo('cluster/link', array($id_group, $id_user, clusterRepo::USER_CLASS));
|
2016-02-13 16:28:28 +00:00
|
|
|
$id_assoc = $assoc_goup->answer();
|
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_assoc === false )
|
2016-02-13 17:41:19 +00:00
|
|
|
return array('ModuleError' => ManagerError::ModuleError);
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
|
|
|
|
|
2016-02-13 16:28:28 +00:00
|
|
|
/* [5] Gestion du retour
|
|
|
|
=========================================================*/
|
|
|
|
return array(
|
2016-02-14 12:28:35 +00:00
|
|
|
'id_user' => $id_user,
|
|
|
|
'id_cluster' => $id_group
|
2016-02-13 16:28:28 +00:00
|
|
|
);
|
2016-02-11 15:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function link($params){
|
|
|
|
extract($parmas);
|
2016-02-14 14:17:26 +00:00
|
|
|
|
2016-07-02 16:35:34 +00:00
|
|
|
/* [1] Creation de l'association
|
2016-02-14 14:17:26 +00:00
|
|
|
=========================================================*/
|
|
|
|
$link_user = new Repo('cluster/link', array($id_cluster, $id_user, clusterRepo::USER_CLASS));
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-02 16:35:34 +00:00
|
|
|
return array();
|
2016-02-14 14:17:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function unlink($params){
|
|
|
|
extract($params);
|
2016-02-14 14:17:26 +00:00
|
|
|
|
2016-07-02 16:35:34 +00:00
|
|
|
/* [1] Suppression de l'association
|
2016-02-14 14:17:26 +00:00
|
|
|
=========================================================*/
|
|
|
|
$link_user = new Repo('cluster/unlink', array($id_cluster, $id_user, clusterRepo::USER_CLASS));
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-02 16:35:34 +00:00
|
|
|
return array();
|
2016-02-14 14:17:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
/* RENVOIE UN UTILISATEUR EN FONCTION D'UN MOT CLE
|
|
|
|
*
|
|
|
|
* @keyword<String> Element de recherche
|
|
|
|
*
|
2016-02-16 13:32:33 +00:00
|
|
|
* @return users<Array> Retourne la liste des utilisateurs trouves
|
2016-02-16 13:25:06 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function search($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
// On recupere les donnees
|
|
|
|
$user = new Repo('user/search', array($keyword));
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'users' => $user->answer()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
/* 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');
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function getById($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
// On recupere les donnees
|
|
|
|
$request = new Repo('user/getById', array($id_user));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
|
|
|
return array( 'ModuleError' => ManagerError::ModuleError );
|
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'user' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE L'UTILISATEURS DE CODE DONNE
|
|
|
|
*
|
|
|
|
* @code<String> Code de l'utilisateur en question
|
|
|
|
*
|
|
|
|
* @return utilisateur<Array> Utilisateur de code donne
|
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function getByCode($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
// On recupere les donnees
|
|
|
|
$request = new Repo('user/getByCode', array($code));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
|
|
|
return array( 'ModuleError' => ManagerError::ModuleError );
|
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'user' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE L'UTILISATEURS D'USERNAME DONNE
|
|
|
|
*
|
|
|
|
* @username<String> Username de l'utilisateur en question
|
|
|
|
*
|
|
|
|
* @return utilisateur<Array> Utilisateur d'username donne
|
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function getByUsername($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
// On recupere les donnees
|
|
|
|
$request = new Repo('user/getByUsername', array($username));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
|
|
|
return array( 'ModuleError' => ManagerError::ModuleError );
|
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'user' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LES GROUPES D'UN UTILISATEUR DONNE
|
|
|
|
*
|
|
|
|
* @id_user<int> UID de l'utilisateur en question
|
|
|
|
*
|
|
|
|
* @return clusters<Array> Groupes de l'utilisateur donne
|
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function getClusters($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
// On recupere les donnees
|
|
|
|
$request = new Repo('user/getClusters', array($id_user));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
|
|
|
return array( 'ModuleError' => ManagerError::ModuleError );
|
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'clusters' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 08:03:12 +00:00
|
|
|
/* MODIFIE UN UTILISATEUR DONNEE
|
|
|
|
*
|
2016-02-16 13:51:19 +00:00
|
|
|
* @id_user<int> UID de l'utilisateur
|
2016-02-16 08:03:12 +00:00
|
|
|
* @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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function edit($params){
|
|
|
|
extract($params);
|
2016-02-16 08:03:12 +00:00
|
|
|
|
|
|
|
|
2016-02-16 18:37:44 +00:00
|
|
|
/* [1] On verifie l'existence de l'utilisateur
|
2016-02-16 08:03:12 +00:00
|
|
|
=========================================================*/
|
2016-02-16 13:51:19 +00:00
|
|
|
$user_exists = new Repo('user/getById', array($id_user));
|
2016-02-16 18:59:55 +00:00
|
|
|
$user_data = $user_exists->answer();
|
2016-02-16 08:03:12 +00:00
|
|
|
|
|
|
|
// Si on a recupere aucun utilisateur, on retourne une erreur
|
2016-02-16 18:37:44 +00:00
|
|
|
if( !is_array($user_data) )
|
2016-02-16 08:03:12 +00:00
|
|
|
return array('ModuleError' => ManagerError::ModuleError);
|
|
|
|
|
|
|
|
|
2016-02-16 18:37:44 +00:00
|
|
|
|
|
|
|
/* [2] Normalisation + verification des donnees
|
|
|
|
=========================================================*/
|
|
|
|
$password_hash = sessionManager::secure_sha1($password);
|
|
|
|
|
2016-07-02 16:35:34 +00:00
|
|
|
/* (1) Verification des parametres (si non nul + differents)*/
|
|
|
|
$diff_param = array(
|
|
|
|
'code' => !is_null($user_data['code']) && $user_data['code'] != $code,
|
|
|
|
'username' => !is_null($user_data['username']) && $user_data['username'] != $username,
|
|
|
|
'firstname' => !is_null($user_data['firstname']) && $user_data['firstname'] != $firstname,
|
|
|
|
'lastname' => !is_null($user_data['lastname']) && $user_data['lastname'] != $lastname,
|
|
|
|
'mail' => !is_null($user_data['mail']) && $user_data['mail'] != $mail,
|
|
|
|
'password' => !is_null($user_data['password']) && $user_data['password'] != $password_hash,
|
|
|
|
'status' => !is_null($user_data['status']) && $user_data['status'] != $status
|
2016-07-02 15:46:59 +00:00
|
|
|
);
|
2016-02-16 18:37:44 +00:00
|
|
|
|
|
|
|
/* (2) Gestion des parametres optionnels */
|
|
|
|
$opt_data = array(
|
2016-07-02 16:35:34 +00:00
|
|
|
'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'],
|
2016-02-16 18:37:44 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 08:03:12 +00:00
|
|
|
/* [3] Modification de l'utilisateur
|
|
|
|
=========================================================*/
|
2016-02-16 18:37:44 +00:00
|
|
|
$request = new Repo('user/edit', array(
|
|
|
|
$id_user,
|
|
|
|
$opt_data['code'],
|
|
|
|
$opt_data['username'],
|
|
|
|
$opt_data['firstname'],
|
|
|
|
$opt_data['lastname'],
|
|
|
|
$opt_data['mail'],
|
2016-02-16 18:59:55 +00:00
|
|
|
$opt_data['password'],
|
2016-02-16 18:37:44 +00:00
|
|
|
$opt_data['status'])
|
|
|
|
);
|
|
|
|
|
2016-02-16 08:03:12 +00:00
|
|
|
|
|
|
|
return array(
|
2016-02-16 18:59:55 +00:00
|
|
|
'status' => $request->answer()
|
2016-02-16 08:03:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
/* 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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-02 16:35:34 +00:00
|
|
|
public static function delete($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
// On recupere les donnees
|
|
|
|
$request = new Repo('user/delete', array($id_user));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'status' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-11 15:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-02 15:46:59 +00:00
|
|
|
?>
|