Repository 'warehouse' utilise entièrement ORM
This commit is contained in:
parent
7bcf154afb
commit
2889114b28
|
@ -42,11 +42,11 @@
|
||||||
$check_admin = self::getByUsername($username);
|
$check_admin = self::getByUsername($username);
|
||||||
|
|
||||||
// Si n'existe pas on retourne FALSE
|
// Si n'existe pas on retourne FALSE
|
||||||
if( count($check_admin) == 0 )
|
if( $check_admin === false )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Sinon, on retourne son id
|
// Sinon, on retourne son id
|
||||||
return $check_admin[0]['id_admin'];
|
return $check_admin['id_admin'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -171,6 +171,7 @@
|
||||||
->whereId($id_admin)
|
->whereId($id_admin)
|
||||||
->whereIdWarehouse($id_warehouse)
|
->whereIdWarehouse($id_warehouse)
|
||||||
->unique()
|
->unique()
|
||||||
|
->select('*')
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
/* [2] On retourne le résultat
|
/* [2] On retourne le résultat
|
||||||
|
@ -201,6 +202,7 @@
|
||||||
->whereUsername($username)
|
->whereUsername($username)
|
||||||
->whereIdWarehouse($id_warehouse)
|
->whereIdWarehouse($id_warehouse)
|
||||||
->unique()
|
->unique()
|
||||||
|
->select('*')
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
/* [2] On retourne le résultat
|
/* [2] On retourne le résultat
|
||||||
|
@ -231,6 +233,7 @@
|
||||||
->whereMail($mail)
|
->whereMail($mail)
|
||||||
->whereIdWarehouse($id_warehouse)
|
->whereIdWarehouse($id_warehouse)
|
||||||
->unique()
|
->unique()
|
||||||
|
->select('*')
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
/* [2] On retourne le résultat
|
/* [2] On retourne le résultat
|
||||||
|
@ -261,6 +264,7 @@
|
||||||
->whereToken($token)
|
->whereToken($token)
|
||||||
->whereIdWarehouse($id_warehouse)
|
->whereIdWarehouse($id_warehouse)
|
||||||
->unique()
|
->unique()
|
||||||
|
->select('*')
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
/* [2] On retourne le résultat
|
/* [2] On retourne le résultat
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
namespace manager\repo;
|
namespace manager\repo;
|
||||||
use \manager\Database;
|
use \manager\Database;
|
||||||
use \manager\sessionManager;
|
use \manager\sessionManager;
|
||||||
use \manager\repo\cluster as clusterRepo;
|
use \manager\ORM\Table;
|
||||||
|
use \manager\ORM\Rows;
|
||||||
|
|
||||||
class warehouse extends parentRepo{
|
class warehouse extends parentRepo{
|
||||||
|
|
||||||
|
@ -19,34 +20,30 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function create($name, $password){
|
public static function create($name, $password){
|
||||||
/* [1] Verification de l'unicite du nom (name)
|
/* [1] On rédige/exécute la requête
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$check_unique = count(self::getByName($name)) == 0;
|
$created = Table::get('warehouse')
|
||||||
|
->insert([
|
||||||
|
'id_warehouse' => Rows::DEFAULT,
|
||||||
|
'name' => $name,
|
||||||
|
'password' => sessionManager::secure_hash( $password ),
|
||||||
|
'token' => sessionManager::secure_hash( uniqid() )
|
||||||
|
]);
|
||||||
|
|
||||||
// Si un entrepot a deja ce nom, on renvoie une erreur
|
// Si name déja pris, erreur
|
||||||
if( !$check_unique )
|
if( !$created )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* [2] Creation de l'utilisateur
|
|
||||||
=========================================================*/
|
|
||||||
$insert_warehouse = Database::getPDO()->prepare("INSERT INTO warehouse(id_warehouse, name, password, token)
|
|
||||||
VALUES(DEFAULT, :name, :password, :token)");
|
|
||||||
$insert_warehouse->execute([
|
|
||||||
':name' => $name,
|
|
||||||
':password' => sessionManager::secure_hash( $password ),
|
|
||||||
':token' => sessionManager::secure_hash( uniqid() )
|
|
||||||
]);
|
|
||||||
|
|
||||||
/* [3] On retourne l'id_warehouse ou FALSE si erreur
|
/* [3] On retourne l'id_warehouse ou FALSE si erreur
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$check_warehouse = self::getByName($name);
|
$check_warehouse = self::getByName($name);
|
||||||
|
|
||||||
// Si n'existe pas on retourne FALSE
|
// Si n'existe pas on retourne FALSE
|
||||||
if( !isset($check_warehouse[0]) || !is_array($check_warehouse[0]) )
|
if( $check_warehouse === false )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Sinon, on retourne son id
|
// Sinon, on retourne son id
|
||||||
return intval( $check_warehouse[0]['id_warehouse'] );
|
return $check_warehouse['id_warehouse'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +61,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function updateToken($id_warehouse=null){
|
public static function updateToken($id_warehouse=null){
|
||||||
|
|
||||||
/* [1] On vérifie que l'entrepot existe
|
/* [1] On vérifie que l'entrepot existe
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
if( self::getById($id_warehouse) === false )
|
if( self::getById($id_warehouse) === false )
|
||||||
|
@ -76,20 +72,13 @@
|
||||||
/* (1) On crée un nouveau token */
|
/* (1) On crée un nouveau token */
|
||||||
$new_token = sessionManager::secure_hash( uniqid() );
|
$new_token = sessionManager::secure_hash( uniqid() );
|
||||||
|
|
||||||
/* (2) On applique le nouveau token */
|
$updated = Table::get('warehouse')
|
||||||
$update_token = Database::getPDO()->prepare("UPDATE warehouse
|
->whereId($id_warehouse)
|
||||||
SET token = :token
|
->edit([ 'token' => $new_token ]);
|
||||||
WHERE id_warehouse = :id_warehouse");
|
|
||||||
|
|
||||||
$update_token->execute([
|
|
||||||
':token' => $new_token,
|
|
||||||
':id_warehouse' => $id_warehouse
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
|
||||||
/* [3] On renvoie le token
|
/* [3] On renvoie le token
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
return $new_token;
|
return ( $updated ) ? $new_token : false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,17 +97,14 @@
|
||||||
public static function getModules($id_warehouse){
|
public static function getModules($id_warehouse){
|
||||||
/* [1] On récupère les modules
|
/* [1] On récupère les modules
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$getModules = Database::getPDO()->prepare("SELECT m.name
|
$module = Table::get('module')
|
||||||
FROM module_merge as wm, module as m
|
->select('name');
|
||||||
WHERE wm.id_module = m.id_module
|
|
||||||
AND wm.id_warehouse = :id_warehouse
|
|
||||||
ORDER BY m.name ASC");
|
|
||||||
|
|
||||||
$getModules->execute([
|
$merge = Table::get('module_merge')
|
||||||
':id_warehouse' => $id_warehouse
|
->whereIdWarehouse($id_warehouse)
|
||||||
]);
|
->join('id_module', $module);
|
||||||
|
|
||||||
$modules = $getModules->fetchAll();
|
$modules = $merge->fetch();
|
||||||
|
|
||||||
/* [2] On formatte les données pour avoir 1 niveau de tableau
|
/* [2] On formatte les données pour avoir 1 niveau de tableau
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
|
@ -128,7 +114,7 @@
|
||||||
|
|
||||||
/* [3] On retourne la liste
|
/* [3] On retourne la liste
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
return Database::delNumeric( $modules );
|
return $modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,42 +134,20 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function edit($id_warehouse=null, $name=null, $password=null){
|
public static function edit($id_warehouse=null, $name=null, $password=null){
|
||||||
/* [1] Verification de l'unicite du nom (name) (si different)
|
/* [1] On rédige/exécute la requête
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
// On recupere les entrepots ayant le meme nom (si existent)
|
$updated = Table::get('warehouse')
|
||||||
// pour éviter les collisions (car le nom doit être unique)
|
->whereId($id_warehouse)
|
||||||
$getbyname = self::getByName($name);
|
->edit([
|
||||||
|
'name' => $name,
|
||||||
|
'password' => sessionManager::secure_hash( $password )
|
||||||
|
]);
|
||||||
|
|
||||||
$check_unique = is_array($getbyname) && $getbyname['id_user'] == $id_user || !is_array($getbyname);
|
|
||||||
|
|
||||||
// Si un utilisateur a deja ce name ou cet username (sauf lui), on renvoie une erreur
|
/* [2] On retourne le résultat
|
||||||
if( !$check_unique )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* [2] Modification de l'utilisateur
|
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$edit_warehouse = Database::getPDO()->prepare("UPDATE warehouse
|
// FAUX si @name est déja pris et si erreur
|
||||||
SET name = :name,
|
return $updated;
|
||||||
password = :password
|
|
||||||
WHERE id_warehouse = :id_warehouse");
|
|
||||||
$edit_warehouse->execute([
|
|
||||||
':name' => $name,
|
|
||||||
':password' => $password,
|
|
||||||
':id_warehouse' => $id_warehouse
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [3] On retourne si tout a ete modifie, si erreur
|
|
||||||
=========================================================*/
|
|
||||||
$check_warehouse = self::getById($id_warehouse);
|
|
||||||
|
|
||||||
$checker = $check_warehouse['id_warehouse'] == $id_warehouse;
|
|
||||||
$checker = $checker && $check_warehouse['name'] == $name;
|
|
||||||
$checker = $checker && $check_warehouse['password'] == $password;
|
|
||||||
|
|
||||||
// On retourne l'etat de la modification
|
|
||||||
return $checker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -203,15 +167,14 @@
|
||||||
public static function delete($id_warehouse){
|
public static function delete($id_warehouse){
|
||||||
/* [1] On redige/execute la requete
|
/* [1] On redige/execute la requete
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$delete_warehouse = Database::getPDO()->prepare("DELETE FROM warehouse WHERE id_warehouse = :id_warehouse");
|
$deleted = Table::get('warehouse')
|
||||||
$delete_warehouse->execute([
|
->whereId($id_warehouse)
|
||||||
':id_warehouse' => $id_warehouse
|
->delete();
|
||||||
]);
|
|
||||||
|
|
||||||
|
|
||||||
/* [2] On verifie que l'utilisateur n'existe plus
|
/* [2] On verifie que l'entrepot n'existe plus
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
return ( self::getById($id_warehouse) === false );
|
return $deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -431,33 +431,15 @@
|
||||||
$id_user_cluster = 2;
|
$id_user_cluster = 2;
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
$get_users = Database::getPDO()->prepare("SELECT u.*
|
$module = Table::get('module')
|
||||||
FROM user_cluster_merge as cm, user_cluster as c, user as u
|
->select('name');
|
||||||
WHERE cm.id_user_cluster = c.id_user_cluster
|
|
||||||
AND c.id_user_cluster = :id_user_cluster
|
|
||||||
AND c.id_warehouse = :id_warehouse
|
|
||||||
AND cm.id_user = u.id_user");
|
|
||||||
$get_users->execute([
|
|
||||||
':id_warehouse' => $id_warehouse,
|
|
||||||
':id_user_cluster' => $id_user_cluster
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
$merge = Table::get('module_merge')
|
||||||
/* [2] On verifie que le groupe n'existe plus
|
|
||||||
=========================================================*/
|
|
||||||
var_dump( count($get_users->fetchAll()) );
|
|
||||||
|
|
||||||
|
|
||||||
$user_cluster = Table::get('user_cluster')
|
|
||||||
->whereIdWarehouse($id_warehouse)
|
->whereIdWarehouse($id_warehouse)
|
||||||
->whereId($id_user_cluster);
|
->join('id_module', $module);
|
||||||
|
|
||||||
$user = Table::get('user')->select('*');
|
|
||||||
|
|
||||||
$user_cluster_merge = Table::get('user_cluster_merge')
|
$modules = $merge->fetch();
|
||||||
->join('id_user_cluster', $user_cluster)
|
var_dump($modules);
|
||||||
->join('id_user', $user);
|
|
||||||
|
|
||||||
var_dump( count($user_cluster_merge->fetch()) );
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue