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
|
|
|
|
*
|
|
|
|
* @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-07-20 18:05:32 +00:00
|
|
|
/* [1] Creation de l'utilisateur
|
2016-02-13 16:28:28 +00:00
|
|
|
=========================================================*/
|
2016-07-06 10:16:11 +00:00
|
|
|
$create_user = new Repo('user/create', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$code,
|
|
|
|
$username,
|
|
|
|
$firstname,
|
|
|
|
$lastname,
|
2016-07-20 18:05:32 +00:00
|
|
|
$mail
|
2016-07-06 10:16:11 +00:00
|
|
|
]);
|
|
|
|
$id_user = $create_user->answer();
|
2016-02-13 16:28:28 +00:00
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_user === false )
|
2016-07-04 13:45:29 +00:00
|
|
|
return ['ModuleError' => ManagerError::ModuleError];
|
2016-02-13 17:41:19 +00:00
|
|
|
|
|
|
|
|
2016-07-20 18:05:32 +00:00
|
|
|
/* [2] Gestion du retour
|
2016-02-13 16:28:28 +00:00
|
|
|
=========================================================*/
|
2016-07-04 13:45:29 +00:00
|
|
|
return [
|
2016-07-21 09:04:18 +00:00
|
|
|
'id_user' => $id_user
|
2016-07-04 13:45:29 +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){
|
2016-07-03 12:20:42 +00:00
|
|
|
extract($params);
|
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
|
|
|
=========================================================*/
|
2016-07-18 10:51:32 +00:00
|
|
|
$link_user = new Repo('user_cluster/link', [
|
2016-07-06 10:16:11 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_cluster,
|
2016-07-20 16:41:24 +00:00
|
|
|
$id_user
|
2016-07-06 10:16:11 +00:00
|
|
|
]);
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (1) On retourne l'erreur du repo */
|
|
|
|
return [ 'ModuleError' => $link_user->answer() ];
|
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
|
|
|
=========================================================*/
|
2016-07-18 10:51:32 +00:00
|
|
|
$link_user = new Repo('user_cluster/unlink', [
|
2016-07-06 10:16:11 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_cluster,
|
2016-07-20 15:33:38 +00:00
|
|
|
$id_user
|
2016-07-06 10:16:11 +00:00
|
|
|
]);
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (1) On retourne l'erreur du repo */
|
|
|
|
return [ 'ModuleError' => $link_user->answer() ];
|
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
|
|
|
|
*
|
2016-07-03 12:20:42 +00:00
|
|
|
* @keywords<String> Element de recherche
|
2016-02-16 13:25:06 +00:00
|
|
|
*
|
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
|
2016-07-06 10:16:11 +00:00
|
|
|
$user = new Repo('user/search', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$keywords
|
|
|
|
]);
|
2016-02-16 13:25:06 +00:00
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'users' => $user->answer() ];
|
2016-02-16 13:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2016-07-06 10:16:11 +00:00
|
|
|
$users = new Repo('user/getAll', [ $_SESSION['WAREHOUSE']['id'] ]);
|
2016-02-14 14:17:26 +00:00
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'users' => $users->answer() ];
|
2016-02-14 14:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
2016-07-06 10:16:11 +00:00
|
|
|
$request = new Repo('user/getById', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_user
|
|
|
|
]);
|
2016-02-14 14:17:26 +00:00
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
2016-02-14 14:17:26 +00:00
|
|
|
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'user' => $answer ];
|
2016-02-14 14:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
2016-07-06 10:16:11 +00:00
|
|
|
$request = new Repo('user/getByCode', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$code
|
|
|
|
]);
|
2016-02-14 14:17:26 +00:00
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
2016-02-14 14:17:26 +00:00
|
|
|
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'user' => $answer ];
|
2016-02-14 14:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
2016-07-06 10:16:11 +00:00
|
|
|
$request = new Repo('user/getByUsername', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$username
|
|
|
|
]);
|
2016-02-14 14:17:26 +00:00
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
2016-02-14 14:17:26 +00:00
|
|
|
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'user' => $answer ];
|
2016-02-14 14:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2016-07-06 10:16:11 +00:00
|
|
|
$request = new Repo('user/getClusters', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_user
|
|
|
|
]);
|
2016-02-14 14:30:35 +00:00
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
2016-02-14 14:30:35 +00:00
|
|
|
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'clusters' => $answer ];
|
2016-02-14 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @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-07-06 10:16:11 +00:00
|
|
|
$user_exists = new Repo('user/getById', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_user
|
|
|
|
]);
|
2016-07-20 18:05:32 +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-07-04 13:45:29 +00:00
|
|
|
return ['ModuleError' => ManagerError::NoMatchFound];
|
2016-02-16 08:03:12 +00:00
|
|
|
|
|
|
|
|
2016-02-16 18:37:44 +00:00
|
|
|
|
|
|
|
/* [2] Normalisation + verification des donnees
|
|
|
|
=========================================================*/
|
2016-07-02 16:35:34 +00:00
|
|
|
/* (1) Verification des parametres (si non nul + differents)*/
|
2016-07-04 13:45:29 +00:00
|
|
|
$diff_param = [
|
2016-07-03 12:20:42 +00:00
|
|
|
'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,
|
2016-07-20 18:05:32 +00:00
|
|
|
'mail' => !is_null($mail) && $user_data['mail'] != $mail
|
2016-07-04 13:45:29 +00:00
|
|
|
];
|
2016-02-16 18:37:44 +00:00
|
|
|
|
|
|
|
/* (2) Gestion des parametres optionnels */
|
2016-07-04 13:45:29 +00:00
|
|
|
$opt_data = [
|
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'],
|
2016-07-20 18:05:32 +00:00
|
|
|
'mail' => ($diff_param['mail']) ? $mail : $user_data['mail']
|
2016-07-04 13:45:29 +00:00
|
|
|
];
|
2016-02-16 18:37:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 08:03:12 +00:00
|
|
|
/* [3] Modification de l'utilisateur
|
|
|
|
=========================================================*/
|
2016-07-04 13:45:29 +00:00
|
|
|
$request = new Repo('user/edit', [
|
2016-07-06 10:16:11 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-02-16 18:37:44 +00:00
|
|
|
$id_user,
|
|
|
|
$opt_data['code'],
|
|
|
|
$opt_data['username'],
|
|
|
|
$opt_data['firstname'],
|
|
|
|
$opt_data['lastname'],
|
2016-07-20 18:05:32 +00:00
|
|
|
$opt_data['mail']
|
2016-07-04 15:23:19 +00:00
|
|
|
]);
|
2016-02-16 18:37:44 +00:00
|
|
|
|
2016-02-16 08:03:12 +00:00
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ '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-07-12 13:16:07 +00:00
|
|
|
/* [1] On supprime l'utilisateur
|
|
|
|
=========================================================*/
|
|
|
|
$del_user = new Repo('user/delete', [
|
2016-07-06 10:16:11 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_user
|
|
|
|
]);
|
2016-07-12 13:16:07 +00:00
|
|
|
$deleted_user = $del_user->answer();
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
|
2016-07-20 18:05:32 +00:00
|
|
|
return [ 'status' => $deleted_user ];
|
2016-02-14 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-11 15:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-02 15:46:59 +00:00
|
|
|
?>
|