2016-02-11 09:34:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\repo;
|
2016-02-13 17:41:19 +00:00
|
|
|
use \manager\Database;
|
2016-02-14 11:37:19 +00:00
|
|
|
use \manager\repo\cluster as clusterRepo;
|
2016-02-11 09:34:26 +00:00
|
|
|
|
2016-07-04 10:13:35 +00:00
|
|
|
class user extends parentRepo{
|
|
|
|
|
|
|
|
protected static function table_name(){ static $table_name = 'user'; return $table_name; }
|
2016-02-11 09:34:26 +00:00
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
/* CREATION D'UN UTILISATEUR ET DE SON GROUPE INDIVIDUEL
|
|
|
|
*
|
2016-07-06 10:16:11 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-13 17:41:19 +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
|
|
|
|
*
|
2016-02-14 11:37:19 +00:00
|
|
|
* @return id_user<int> Renvoie l'UID de l'utilisateur cree
|
|
|
|
* Renvoie FALSE si une erreur occure
|
2016-02-13 17:41:19 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-07-06 10:16:11 +00:00
|
|
|
public static function create($id_warehouse, $code, $username, $firstname, $lastname, $mail, $password, $status){
|
2016-02-14 11:37:19 +00:00
|
|
|
/* [1] Verification de l'unicite de code+username
|
2016-02-13 17:41:19 +00:00
|
|
|
=========================================================*/
|
2016-07-06 10:16:11 +00:00
|
|
|
$check_unique = !is_array(self::getByCode($id_warehouse, $code));
|
|
|
|
$check_unique = $check_unique && !is_array(self::getByUsername($id_warehouse, $username));
|
2016-02-13 17:41:19 +00:00
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
// Si un utilisateur a deja ce code ou cet username, on renvoie une erreur
|
|
|
|
if( !$check_unique )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* [2] Creation de l'utilisateur
|
|
|
|
=========================================================*/
|
2016-07-05 13:50:24 +00:00
|
|
|
$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)");
|
2016-07-04 13:45:29 +00:00
|
|
|
$insert_user->execute([
|
2016-07-06 10:16:11 +00:00
|
|
|
':id_warehouse' => $id_warehouse,
|
2016-07-05 13:50:24 +00:00
|
|
|
':code' => $code,
|
|
|
|
':username' => $username,
|
|
|
|
':firstname' => $firstname,
|
|
|
|
':lastname' => $lastname,
|
|
|
|
':mail' => $mail,
|
|
|
|
':password' => $password,
|
|
|
|
':status' => $status
|
2016-07-04 13:45:29 +00:00
|
|
|
]);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
/* [3] On retourne l'id_user ou FALSE si erreur
|
|
|
|
=========================================================*/
|
2016-07-09 13:06:59 +00:00
|
|
|
$check_user = self::getByCode($id_warehouse, $code);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
// Si n'existe pas on retourne FALSE
|
|
|
|
if( $check_user === false )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Sinon, on retourne son id
|
|
|
|
return $check_user['id_user'];
|
2016-02-13 17:41:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 13:32:33 +00:00
|
|
|
/* RENVOIE UNE LISTE D'UTILISATEURS EN FONCTION D'UN MOT CLE
|
2016-02-16 13:25:06 +00:00
|
|
|
*
|
2016-07-06 10:16:11 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-16 13:25:06 +00:00
|
|
|
* @keyword<String> Element de recherche
|
|
|
|
*
|
2016-02-16 13:32:33 +00:00
|
|
|
* @return users<Array> Retourne les utilisateurs trouves
|
2016-02-16 13:25:06 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-07-06 10:16:11 +00:00
|
|
|
public static function search($id_warehouse, $keyword){
|
2016-02-16 13:25:06 +00:00
|
|
|
// On recupere les donnees
|
2016-07-05 13:50:24 +00:00
|
|
|
$searchusers = Database::getPDO()->prepare("SELECT * FROM user
|
|
|
|
WHERE id_warehouse = :id_warehouse
|
|
|
|
AND ( code LIKE '%".$keyword."%'
|
|
|
|
OR username LIKE '%".$keyword."%'
|
|
|
|
OR firstname LIKE '%".$keyword."%'
|
|
|
|
OR lastname LIKE '%".$keyword."%'
|
|
|
|
OR mail LIKE '%".$keyword."%'
|
|
|
|
)
|
2016-02-16 13:25:06 +00:00
|
|
|
");
|
|
|
|
|
2016-07-05 13:50:24 +00:00
|
|
|
$searchusers->execute([
|
2016-07-06 10:16:11 +00:00
|
|
|
':id_warehouse' => $id_warehouse
|
2016-07-05 13:50:24 +00:00
|
|
|
]);
|
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
return Database::delNumeric( $searchusers->fetchAll() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
|
2016-02-11 09:34:26 +00:00
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
|
2016-02-14 12:28:35 +00:00
|
|
|
/* RENVOIE LES GROUPES AUQUEL APPARTIENT UN UTILISATEUR DONNE
|
|
|
|
*
|
2016-07-06 10:16:11 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-14 12:28:35 +00:00
|
|
|
* @id_user<int> UID de l'utilisateur en question
|
|
|
|
*
|
|
|
|
* @return clusters<Array> Retourne la liste des groupes auquel appartient l'utilisateur
|
|
|
|
*
|
|
|
|
*/
|
2016-07-06 10:16:11 +00:00
|
|
|
public static function getClusters($id_warehouse, $id_user){
|
2016-02-14 12:28:35 +00:00
|
|
|
/* [1] On redige/execute la requete
|
|
|
|
=========================================================*/
|
2016-07-06 15:36:26 +00:00
|
|
|
$get_clusters = Database::getPDO()->prepare("SELECT c.id_cluster, c.name
|
2016-07-06 10:16:11 +00:00
|
|
|
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
|
2016-07-08 15:53:50 +00:00
|
|
|
AND c.class = :class
|
2016-07-06 10:16:11 +00:00
|
|
|
AND u.id_warehouse = :id_warehouse
|
2016-02-14 12:28:35 +00:00
|
|
|
ORDER BY c.id_cluster");
|
2016-07-04 13:45:29 +00:00
|
|
|
$get_clusters->execute([
|
2016-07-06 10:16:11 +00:00
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
':id_user' => $id_user,
|
|
|
|
':class' => clusterRepo::USER_CLASS
|
2016-07-04 13:45:29 +00:00
|
|
|
]);
|
2016-02-14 12:28:35 +00:00
|
|
|
|
|
|
|
/* [2] On retourne la liste des groupes
|
|
|
|
=========================================================*/
|
|
|
|
return Database::delNumeric( $get_clusters->fetchAll() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 08:03:12 +00:00
|
|
|
/* MODIFICATION D'UN UTILISATEUR
|
|
|
|
*
|
2016-07-06 10:16:11 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-16 08:03:12 +00:00
|
|
|
* @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> Renvoie si oui ou non tout s'est bien passe
|
|
|
|
*
|
|
|
|
*/
|
2016-07-06 10:16:11 +00:00
|
|
|
public static function edit($id_warehouse, $id_user=null, $code=null, $username=null, $firstname=null, $lastname=null, $mail=null, $password=null, $status=null){
|
2016-02-16 08:03:12 +00:00
|
|
|
/* [1] Verification de l'unicite de code+username (si differents)
|
|
|
|
=========================================================*/
|
|
|
|
// On recupere les utilisateurs ayant le meme code ou username (si existent)
|
2016-07-03 12:20:42 +00:00
|
|
|
// pour éviter les collisions (car code/username doivent être uniquent)
|
2016-07-06 10:16:11 +00:00
|
|
|
$getbycode = self::getByCode($id_warehouse, $code);
|
|
|
|
$getbyusername = self::getByUsername($id_warehouse, $username);
|
2016-02-16 08:03:12 +00:00
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
// Si un utilisateur a deja ce code ou cet username (sauf lui), on renvoie une erreur
|
|
|
|
if( !$check_unique )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* [2] Modification de l'utilisateur
|
|
|
|
=========================================================*/
|
|
|
|
$edit_user = Database::getPDO()->prepare("UPDATE user
|
|
|
|
SET code = :code,
|
2016-07-03 12:20:42 +00:00
|
|
|
username = :username,
|
|
|
|
firstname = :firstname,
|
|
|
|
lastname = :lastname,
|
|
|
|
mail = :mail,
|
|
|
|
password = :password,
|
|
|
|
status = :status
|
2016-07-05 13:50:24 +00:00
|
|
|
WHERE id_user = :id_user
|
|
|
|
AND id_warehouse = :id_warehouse");
|
2016-07-04 13:45:29 +00:00
|
|
|
$edit_user->execute([
|
2016-07-05 13:50:24 +00:00
|
|
|
':code' => $code,
|
|
|
|
':username' => $username,
|
|
|
|
':firstname' => $firstname,
|
|
|
|
':lastname' => $lastname,
|
|
|
|
':mail' => $mail,
|
|
|
|
':password' => $password,
|
|
|
|
':status' => $status,
|
|
|
|
':id_user' => $id_user,
|
2016-07-06 10:16:11 +00:00
|
|
|
':id_warehouse' => $id_warehouse
|
2016-07-04 13:45:29 +00:00
|
|
|
]);
|
2016-02-16 08:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] On retourne si tout a ete modifie, si erreur
|
|
|
|
=========================================================*/
|
2016-07-06 10:16:11 +00:00
|
|
|
$check_user = self::getById($id_warehouse, $id_user);
|
2016-02-16 08:03:12 +00:00
|
|
|
|
|
|
|
$checker = $check_user['id_user'] == $id_user;
|
|
|
|
$checker = $checker && $check_user['code'] == $code;
|
|
|
|
$checker = $checker && $check_user['username'] == $username;
|
|
|
|
$checker = $checker && $check_user['firstname'] == $firstname;
|
|
|
|
$checker = $checker && $check_user['lastname'] == $lastname;
|
|
|
|
$checker = $checker && $check_user['mail'] == $mail;
|
|
|
|
$checker = $checker && $check_user['password'] == $password;
|
|
|
|
$checker = $checker && $check_user['status'] == $status;
|
|
|
|
|
|
|
|
// On retourne l'etat de la modification
|
|
|
|
return $checker;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
/* SUPPRIME UN UTILISATEUR DONNE
|
|
|
|
*
|
2016-07-06 10:16:11 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-13 17:41:19 +00:00
|
|
|
* @id_user<int> UID de l'utilisateur en question
|
|
|
|
*
|
|
|
|
* @return status<Boolean> Retourne si oui ou non l'utilisateur a bien ete supprime
|
|
|
|
*
|
|
|
|
*/
|
2016-07-06 10:16:11 +00:00
|
|
|
public static function delete($id_warehouse, $id_user){
|
2016-02-13 17:41:19 +00:00
|
|
|
/* [1] On redige/execute la requete
|
|
|
|
=========================================================*/
|
2016-07-06 10:16:11 +00:00
|
|
|
$delete_user = Database::getPDO()->prepare("DELETE FROM user
|
|
|
|
WHERE id_user = :id_user
|
|
|
|
AND id_warehouse = :id_warehouse");
|
2016-07-05 13:50:24 +00:00
|
|
|
$delete_user->execute([
|
|
|
|
':id_user' => $id_user,
|
2016-07-06 10:16:11 +00:00
|
|
|
':id_warehouse' => $id_warehouse
|
2016-07-05 13:50:24 +00:00
|
|
|
]);
|
2016-02-11 15:00:41 +00:00
|
|
|
|
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
/* [2] On verifie que l'utilisateur n'existe plus
|
|
|
|
=========================================================*/
|
2016-07-09 13:06:59 +00:00
|
|
|
return ( self::getById($id_warehouse, $id_user) === false );
|
2016-02-11 15:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-06 10:16:11 +00:00
|
|
|
/* 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() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
|
|
|
|
|
2016-02-14 12:28:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-03 12:20:42 +00:00
|
|
|
|
|
|
|
|
2016-02-14 12:28:35 +00:00
|
|
|
|
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
|
|
|
|
|
2016-02-11 09:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-03 12:20:42 +00:00
|
|
|
?>
|