From 726f328a14ccaf13460bcfb3319dfc985c1c80ff Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 23 Jul 2016 16:02:04 +0200 Subject: [PATCH] =?UTF-8?q?Repository=20'user'=20fonctionne=20avec=20ORM?= =?UTF-8?q?=20sauf=20la=20m=C3=A9thode=20'search'=20ou=20il=20y=20a=20des?= =?UTF-8?q?=20'WHERE=20..=20OR=20...'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manager/repo/user.php | 52 +++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/manager/repo/user.php b/manager/repo/user.php index eed1c12..81572f4 100755 --- a/manager/repo/user.php +++ b/manager/repo/user.php @@ -23,35 +23,29 @@ * */ public static function create($id_warehouse, $code, $username, $firstname, $lastname, $mail){ - /* [1] Verification de l'unicite de code+username + /* [1] On retourne l'id_user ou FALSE si erreur =========================================================*/ - $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 ) - return false; - - - /* [2] Creation de l'utilisateur - =========================================================*/ - $insert_user = Database::getPDO()->prepare("INSERT INTO user(id_user, id_warehouse, code, username, firstname, lastname, mail) - VALUES(DEFAULT, :id_warehouse, :code, :username, :firstname, :lastname, :mail)"); - $inserted = $insert_user->execute([ - ':id_warehouse' => $id_warehouse, - ':code' => $code, - ':username' => $username, - ':firstname' => $firstname, - ':lastname' => $lastname, - ':mail' => $mail + $inserted = Table::get('user')->insert([ + 'id_user' => Rows::DEFAULT, + 'id_warehouse' => $id_warehouse, + 'code' => $code, + 'username' => $username, + 'firstname' => $firstname, + 'lastname' => $lastname, + 'mail' => $mail ]); - /* [3] On retourne l'id_user ou FALSE si erreur + // Si erreur d'insertion, erreur + if( !$inserted ) + return false; // Si pb d'unicité du code ou username (car sont uniques) ou autre + + + /* [2] On récupère l'id_user =========================================================*/ $check_user = self::getByCode($id_warehouse, $code); - // Si n'existe pas on retourne FALSE - if( !$inserted || $check_user === false ) + // Si on trouve pas, erreur + if( $check_user === false ) return false; // Sinon, on retourne son id @@ -193,16 +187,12 @@ 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->execute([ - ':id_user' => $id_user, - ':id_warehouse' => $id_warehouse - ]); + $delete = Table::get('user') + ->whereId($id_user) + ->whereIdWarehouse($id_warehouse); // On retourne l'état - return ( self::getById($id_warehouse, $id_user) === false ); + return $delete->delete(); }