Refactor module 'userDefault' et repo 'user' pour que soit un param du repo, mais automatiquement rempli par le module
This commit is contained in:
parent
798b88caa4
commit
b3d25eb8d7
|
@ -37,7 +37,10 @@
|
|||
|
||||
/* [2] Creation du groupe de meme nom que la machine
|
||||
=========================================================*/
|
||||
$create_group = new Repo('cluster/create', [$name] );
|
||||
$create_group = new Repo('cluster/create', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$name
|
||||
]);
|
||||
$id_group = $create_group->answer();
|
||||
|
||||
// Si une erreur est retournee, on retourne une erreur
|
||||
|
@ -51,8 +54,8 @@
|
|||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_group,
|
||||
$id_machine,
|
||||
clusterRepo::MACHINE_CLASS]
|
||||
);
|
||||
clusterRepo::MACHINE_CLASS
|
||||
]);
|
||||
$id_assoc = $assoc_goup->answer();
|
||||
|
||||
// Si une erreur est retournee, on retourne une erreur
|
||||
|
@ -332,6 +335,7 @@
|
|||
/* [3] Modification de la machine
|
||||
=========================================================*/
|
||||
$request = new Repo('machine/edit', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_machine,
|
||||
$opt_data['code'],
|
||||
$opt_data['name']
|
||||
|
|
|
@ -32,7 +32,16 @@
|
|||
|
||||
/* [2] Creation de l'utilisateur
|
||||
=========================================================*/
|
||||
$create_user = new Repo('user/create', [$code, $username, $firstname, $lastname, $mail, $password_hash, $status] );
|
||||
$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);
|
||||
|
@ -45,7 +54,10 @@
|
|||
|
||||
/* [3] Creation du groupe de meme nom que l'username
|
||||
=========================================================*/
|
||||
$create_group = new Repo('cluster/create', [$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
|
||||
|
@ -57,7 +69,12 @@
|
|||
|
||||
/* [4] Association au groupe
|
||||
=========================================================*/
|
||||
$assoc_goup = new Repo('cluster/link', [$id_group, $id_user, clusterRepo::USER_CLASS]);
|
||||
$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
|
||||
|
@ -92,7 +109,12 @@
|
|||
|
||||
/* [1] Creation de l'association
|
||||
=========================================================*/
|
||||
$link_user = new Repo('cluster/link', [$id_cluster, $id_user, clusterRepo::USER_CLASS]);
|
||||
$link_user = new Repo('cluster/link', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_cluster,
|
||||
$id_user,
|
||||
clusterRepo::USER_CLASS
|
||||
]);
|
||||
|
||||
return [];
|
||||
|
||||
|
@ -116,7 +138,12 @@
|
|||
|
||||
/* [1] Suppression de l'association
|
||||
=========================================================*/
|
||||
$link_user = new Repo('cluster/unlink', [$id_cluster, $id_user, clusterRepo::USER_CLASS]);
|
||||
$link_user = new Repo('cluster/unlink', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_cluster,
|
||||
$id_user,
|
||||
clusterRepo::USER_CLASS
|
||||
]);
|
||||
|
||||
return [];
|
||||
|
||||
|
@ -137,7 +164,10 @@
|
|||
extract($params);
|
||||
|
||||
// On recupere les donnees
|
||||
$user = new Repo('user/search', [$keywords]);
|
||||
$user = new Repo('user/search', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$keywords
|
||||
]);
|
||||
|
||||
return [ 'users' => $user->answer() ];
|
||||
}
|
||||
|
@ -153,7 +183,7 @@
|
|||
*/
|
||||
public static function getAll(){
|
||||
// On recupere les donnees
|
||||
$users = new Repo('user/getAll');
|
||||
$users = new Repo('user/getAll', [ $_SESSION['WAREHOUSE']['id'] ]);
|
||||
|
||||
return [ 'users' => $users->answer() ];
|
||||
}
|
||||
|
@ -173,7 +203,10 @@
|
|||
extract($params);
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/getById', [$id_user]);
|
||||
$request = new Repo('user/getById', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_user
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
|
@ -199,7 +232,10 @@
|
|||
extract($params);
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/getByCode', [$code]);
|
||||
$request = new Repo('user/getByCode', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$code
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
|
@ -226,7 +262,10 @@
|
|||
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/getByUsername', [$username]);
|
||||
$request = new Repo('user/getByUsername', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$username
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
|
@ -253,7 +292,10 @@
|
|||
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/getClusters', [$id_user]);
|
||||
$request = new Repo('user/getClusters', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_user
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
|
@ -287,7 +329,10 @@
|
|||
|
||||
/* [1] On verifie l'existence de l'utilisateur
|
||||
=========================================================*/
|
||||
$user_exists = new Repo('user/getById', [$id_user]);
|
||||
$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
|
||||
|
@ -328,6 +373,7 @@
|
|||
/* [3] Modification de l'utilisateur
|
||||
=========================================================*/
|
||||
$request = new Repo('user/edit', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_user,
|
||||
$opt_data['code'],
|
||||
$opt_data['username'],
|
||||
|
@ -358,7 +404,10 @@
|
|||
|
||||
|
||||
// On recupere les donnees
|
||||
$request = new Repo('user/delete', [$id_user]);
|
||||
$request = new Repo('user/delete', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_user
|
||||
]);
|
||||
$answer = $request->answer();
|
||||
|
||||
return [ 'status' => $answer ];
|
||||
|
|
|
@ -243,7 +243,7 @@
|
|||
if( $found === false )
|
||||
return false;
|
||||
|
||||
return Database::delNumeric( $found );
|
||||
return Database::delNumeric( $found, true );
|
||||
}
|
||||
|
||||
|
||||
|
@ -283,7 +283,7 @@
|
|||
if( $found === false )
|
||||
return false;
|
||||
|
||||
return Database::delNumeric( $found );
|
||||
return Database::delNumeric( $found, true );
|
||||
}
|
||||
|
||||
|
||||
|
@ -323,7 +323,7 @@
|
|||
if( $found === false )
|
||||
return false;
|
||||
|
||||
return Database::delNumeric( $found );
|
||||
return Database::delNumeric( $found, true );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
/* CREATION D'UN UTILISATEUR ET DE SON GROUPE INDIVIDUEL
|
||||
*
|
||||
* @id_warehouse<int> UID de l'entrepot
|
||||
* @code<String> Code RFID de l'utilisateur
|
||||
* @username<String> Identifiant l'utilisateur
|
||||
* @firstname<String> Prenom de l'utilisateur
|
||||
|
@ -22,11 +23,11 @@
|
|||
* Renvoie FALSE si une erreur occure
|
||||
*
|
||||
*/
|
||||
public static function create($code, $username, $firstname, $lastname, $mail, $password, $status){
|
||||
public static function create($id_warehouse, $code, $username, $firstname, $lastname, $mail, $password, $status){
|
||||
/* [1] Verification de l'unicite de code+username
|
||||
=========================================================*/
|
||||
$check_unique = !is_array(self::getByCode($code));
|
||||
$check_unique = $check_unique && !is_array(self::getByUsername($username));
|
||||
$check_unique = !is_array(self::getByCode($id_warehouse, $code));
|
||||
$check_unique = $check_unique && !is_array(self::getByUsername($id_warehouse, $username));
|
||||
|
||||
// Si un utilisateur a deja ce code ou cet username, on renvoie une erreur
|
||||
if( !$check_unique )
|
||||
|
@ -37,7 +38,7 @@
|
|||
$insert_user = Database::getPDO()->prepare("INSERT INTO user(id_user, id_warehouse, code, username, firstname, lastname, mail, password, status)
|
||||
VALUES(DEFAULT, :id_warehouse, :code, :username, :firstname, :lastname, :mail, :password, :status)");
|
||||
$insert_user->execute([
|
||||
':id_warehouse' => $_SESSION['WAREHOUSE']['id'],
|
||||
':id_warehouse' => $id_warehouse,
|
||||
':code' => $code,
|
||||
':username' => $username,
|
||||
':firstname' => $firstname,
|
||||
|
@ -66,12 +67,13 @@
|
|||
|
||||
/* RENVOIE UNE LISTE D'UTILISATEURS EN FONCTION D'UN MOT CLE
|
||||
*
|
||||
* @id_warehouse<int> UID de l'entrepot
|
||||
* @keyword<String> Element de recherche
|
||||
*
|
||||
* @return users<Array> Retourne les utilisateurs trouves
|
||||
*
|
||||
*/
|
||||
public static function search($keyword){
|
||||
public static function search($id_warehouse, $keyword){
|
||||
// On recupere les donnees
|
||||
$searchusers = Database::getPDO()->prepare("SELECT * FROM user
|
||||
WHERE id_warehouse = :id_warehouse
|
||||
|
@ -84,7 +86,7 @@
|
|||
");
|
||||
|
||||
$searchusers->execute([
|
||||
':id_warehouse' => $_SESSION['WAREHOUSE']['id']
|
||||
':id_warehouse' => $id_warehouse
|
||||
]);
|
||||
|
||||
return Database::delNumeric( $searchusers->fetchAll() );
|
||||
|
@ -99,20 +101,25 @@
|
|||
|
||||
/* RENVOIE LES GROUPES AUQUEL APPARTIENT UN UTILISATEUR DONNE
|
||||
*
|
||||
* @id_warehouse<int> UID de l'entrepot
|
||||
* @id_user<int> UID de l'utilisateur en question
|
||||
*
|
||||
* @return clusters<Array> Retourne la liste des groupes auquel appartient l'utilisateur
|
||||
*
|
||||
*/
|
||||
public static function getClusters($id_user){
|
||||
public static function getClusters($id_warehouse, $id_user){
|
||||
/* [1] On redige/execute la requete
|
||||
=========================================================*/
|
||||
$get_clusters = Database::getPDO()->prepare("SELECT c.* FROM cluster as c, cluster_merge as cm
|
||||
$get_clusters = Database::getPDO()->prepare("SELECT c.*
|
||||
FROM cluster as c, cluster_merge as cm, user as u
|
||||
WHERE cm.id_cluster = c.id_cluster
|
||||
AND cm.id_entity = u.id_user
|
||||
AND cm.id_entity = :id_user
|
||||
AND cm.class = :class
|
||||
AND u.id_warehouse = :id_warehouse
|
||||
ORDER BY c.id_cluster");
|
||||
$get_clusters->execute([
|
||||
':id_warehouse' => $id_warehouse,
|
||||
':id_user' => $id_user,
|
||||
':class' => clusterRepo::USER_CLASS
|
||||
]);
|
||||
|
@ -131,6 +138,7 @@
|
|||
|
||||
/* MODIFICATION D'UN UTILISATEUR
|
||||
*
|
||||
* @id_warehouse<int> UID de l'entrepot
|
||||
* @id_user<int> UID de l'utilisateur
|
||||
* @code<String> Code RFID de l'utilisateur
|
||||
* @username<String> Identifiant l'utilisateur
|
||||
|
@ -143,13 +151,13 @@
|
|||
* @return status<Boolean> Renvoie si oui ou non tout s'est bien passe
|
||||
*
|
||||
*/
|
||||
public static function edit($id_user=null, $code=null, $username=null, $firstname=null, $lastname=null, $mail=null, $password=null, $status=null){
|
||||
public static function edit($id_warehouse, $id_user=null, $code=null, $username=null, $firstname=null, $lastname=null, $mail=null, $password=null, $status=null){
|
||||
/* [1] Verification de l'unicite de code+username (si differents)
|
||||
=========================================================*/
|
||||
// On recupere les utilisateurs ayant le meme code ou username (si existent)
|
||||
// pour éviter les collisions (car code/username doivent être uniquent)
|
||||
$getbycode = self::getByCode($code);
|
||||
$getbyusername = self::getByUsername($username);
|
||||
$getbycode = self::getByCode($id_warehouse, $code);
|
||||
$getbyusername = self::getByUsername($id_warehouse, $username);
|
||||
|
||||
$check_unique = is_array($getbycode) && $getbycode['id_user'] == $id_user || !is_array($getbycode);
|
||||
$check_unique = $check_unique && is_array($getbyusername) && $getbyusername['id_user'] == $id_user || !is_array($getbyusername);
|
||||
|
@ -179,14 +187,14 @@
|
|||
':password' => $password,
|
||||
':status' => $status,
|
||||
':id_user' => $id_user,
|
||||
':id_warehouse' => $_SESSION['WAREHOUSE']['id']
|
||||
':id_warehouse' => $id_warehouse
|
||||
]);
|
||||
|
||||
|
||||
|
||||
/* [3] On retourne si tout a ete modifie, si erreur
|
||||
=========================================================*/
|
||||
$check_user = self::getById($id_user);
|
||||
$check_user = self::getById($id_warehouse, $id_user);
|
||||
|
||||
$checker = $check_user['id_user'] == $id_user;
|
||||
$checker = $checker && $check_user['code'] == $code;
|
||||
|
@ -210,18 +218,21 @@
|
|||
|
||||
/* SUPPRIME UN UTILISATEUR DONNE
|
||||
*
|
||||
* @id_warehouse<int> UID de l'entrepot
|
||||
* @id_user<int> UID de l'utilisateur en question
|
||||
*
|
||||
* @return status<Boolean> Retourne si oui ou non l'utilisateur a bien ete supprime
|
||||
*
|
||||
*/
|
||||
public static function delete($id_user){
|
||||
public static function delete($id_warehouse, $id_user){
|
||||
/* [1] On redige/execute la requete
|
||||
=========================================================*/
|
||||
$delete_user = Database::getPDO()->prepare("DELETE FROM user WHERE id_user = :id_user AND id_warehouse = :id_warehouse");
|
||||
$delete_user = Database::getPDO()->prepare("DELETE FROM user
|
||||
WHERE id_user = :id_user
|
||||
AND id_warehouse = :id_warehouse");
|
||||
$delete_user->execute([
|
||||
':id_user' => $id_user,
|
||||
':id_warehouse' => $_SESSION['WAREHOUSE']['id']
|
||||
':id_warehouse' => $id_warehouse
|
||||
]);
|
||||
|
||||
|
||||
|
@ -237,6 +248,152 @@
|
|||
|
||||
|
||||
|
||||
/* RETOURNE UN UTILISATEUR SPECIFIQUE
|
||||
*
|
||||
* @id_warehouse<int> UID de l'entrepot
|
||||
* @id_user<int> UID de l'utilisateur
|
||||
*
|
||||
* @return user<Array> Données de l'utilisateur
|
||||
* FALSE si aucun résultat
|
||||
*
|
||||
*/
|
||||
public static function getById($id_warehouse, $id_user){
|
||||
/* [1] On rédige/execute la requête
|
||||
=========================================================*/
|
||||
$get = Database::getPDO()->prepare("SELECT u.id_user, u.code, u.username, u.firstname, u.lastname, u.mail, u.status
|
||||
FROM user as u
|
||||
WHERE u.id_warehouse = :id_warehouse
|
||||
AND u.id_user = :id_user");
|
||||
$get->execute([
|
||||
':id_warehouse' => $id_warehouse,
|
||||
':id_user' => $id_user
|
||||
]);
|
||||
|
||||
/* [2] Gestion des données
|
||||
=========================================================*/
|
||||
$found = $get->fetch();
|
||||
|
||||
// Si aucun résultat
|
||||
if( $found === false )
|
||||
return false;
|
||||
|
||||
return Database::delNumeric( $found, true );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RETOURNE UN UTILISATEUR SPECIFIQUE
|
||||
*
|
||||
* @id_warehouse<int> UID de l'entrepot
|
||||
* @code<String> Code RFID de l'utilisateur
|
||||
*
|
||||
* @return user<Array> Données de l'utilisateur
|
||||
* FALSE si aucun résultat
|
||||
*
|
||||
*/
|
||||
public static function getByCode($id_warehouse, $code){
|
||||
/* [1] On rédige/execute la requête
|
||||
=========================================================*/
|
||||
$get = Database::getPDO()->prepare("SELECT u.id_user, u.code, u.username, u.firstname, u.lastname, u.mail, u.status
|
||||
FROM user as u
|
||||
WHERE u.id_warehouse = :id_warehouse
|
||||
AND u.code = :code");
|
||||
$get->execute([
|
||||
':id_warehouse' => $id_warehouse,
|
||||
':code' => $code
|
||||
]);
|
||||
|
||||
/* [2] Gestion des données
|
||||
=========================================================*/
|
||||
$found = $get->fetch();
|
||||
|
||||
// Si aucun résultat
|
||||
if( $found === false )
|
||||
return false;
|
||||
|
||||
return Database::delNumeric( $found, true );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RETOURNE UN UTILISATEUR SPECIFIQUE
|
||||
*
|
||||
* @id_warehouse<int> UID de l'entrepot
|
||||
* @username<String> Identifiant de l'utilisateur
|
||||
*
|
||||
* @return user<Array> Données de l'utilisateur
|
||||
* FALSE si aucun résultat
|
||||
*
|
||||
*/
|
||||
public static function getByUsername($id_warehouse, $username){
|
||||
/* [1] On rédige/execute la requête
|
||||
=========================================================*/
|
||||
$get = Database::getPDO()->prepare("SELECT u.id_user, u.code, u.username, u.firstname, u.lastname, u.mail, u.status
|
||||
FROM user as u
|
||||
WHERE u.id_warehouse = :id_warehouse
|
||||
AND u.username = :username");
|
||||
$get->execute([
|
||||
':id_warehouse' => $id_warehouse,
|
||||
':username' => $username
|
||||
]);
|
||||
|
||||
/* [2] Gestion des données
|
||||
=========================================================*/
|
||||
$found = $get->fetch();
|
||||
|
||||
// Si aucun résultat
|
||||
if( $found === false )
|
||||
return false;
|
||||
|
||||
return Database::delNumeric( $found, true );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RETOURNE TOUS LES UTILISATEURS DE L'ENTREPOT
|
||||
*
|
||||
* @id_warehouse<int> UID de l'entrepot
|
||||
*
|
||||
* @return users<Array> Données des utilisateurs
|
||||
*
|
||||
*/
|
||||
public static function getAll($id_warehouse){
|
||||
/* [1] On rédige/execute la requête
|
||||
=========================================================*/
|
||||
$get = Database::getPDO()->prepare("SELECT u.id_user, u.code, u.username, u.firstname, u.lastname, u.mail, u.status
|
||||
FROM user as u
|
||||
WHERE u.id_warehouse = :id_warehouse");
|
||||
$get->execute([
|
||||
':id_warehouse' => $id_warehouse
|
||||
]);
|
||||
|
||||
/* [2] Gestion des données
|
||||
=========================================================*/
|
||||
return Database::delNumeric( $get->fetchAll() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue