From 2bce5ab3bbf3af2ae859e17243152e9143f0f820 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 25 Jul 2016 01:14:35 +0200 Subject: [PATCH] Corrections des repositories pour la nouvelle version de Rows::select(ONLY_ONE_FIELD) --- manager/ORM/Rows.php | 1 - manager/repo/action_merge.php | 32 ++++++++++++++------------------ manager/repo/chip.php | 11 +++++------ manager/repo/machine.php | 12 ++++++++---- manager/repo/user.php | 8 ++++---- test/automate.php | 20 +++++--------------- 6 files changed, 36 insertions(+), 48 deletions(-) diff --git a/manager/ORM/Rows.php b/manager/ORM/Rows.php index 9f45d43..042f948 100644 --- a/manager/ORM/Rows.php +++ b/manager/ORM/Rows.php @@ -881,7 +881,6 @@ /* (2) On compose la requête */ $requestString = SQLBuilder::BUILD($requestS).';'; - var_dump($requestString); /* (3) On prépare la requête */ $request = Database::getPDO()->prepare($requestString); diff --git a/manager/repo/action_merge.php b/manager/repo/action_merge.php index 28aec95..66b38d9 100644 --- a/manager/repo/action_merge.php +++ b/manager/repo/action_merge.php @@ -80,13 +80,13 @@ /* [5] On ajoute la action =========================================================*/ /* (1) On effectue l'insertion */ - $insert = Database::getPDO()->prepare("INSERT INTO action_merge(id_action_merge, id_target, id_source, id_action) - VALUES(DEFAULT, :id_target, :id_source, :id_action)"); - $inserted = $insert->execute([ - ':id_target' => $id_target, - ':id_source' => $id_source, - ':id_action' => $id_action - ]); + $inserted = Table::get('action_merge') + ->insert([ + 'id_action_merge' => Rows::INSERT_DEFAULT, + 'id_target' => $id_target, + 'id_source' => $id_source, + 'id_action' => $id_action + ]); /* (2) Si erreur SQL, on retourne une erreur */ if( !$inserted ) @@ -138,17 +138,13 @@ /* [2] On supprime la action =========================================================*/ /* (1) On effectue la suppression */ - $delete = Database::getPDO()->prepare("DELETE FROM action_merge - WHERE id_action_merge = :id_action_merge - AND id_target = :id_target - AND id_source = :id_source - AND id_action = :id_action"); - $deleted = $delete->execute([ - ':id_action_merge' => $existingId, - ':id_target' => $id_target, - ':id_source' => $id_source, - ':id_action' => $id_action - ]); + $deleted = Table::get('action_merge') + ->whereId($existingId) + ->whereIdTarget($id_target) + ->whereIdSource($id_source) + ->whereIdAction($id_action) + ->unique() + ->delete(); /* (2) Si erreur SQL, on retourne une erreur */ if( !$deleted || self::getById($existingId) !== false ) diff --git a/manager/repo/chip.php b/manager/repo/chip.php index 54017dd..65f542f 100644 --- a/manager/repo/chip.php +++ b/manager/repo/chip.php @@ -20,20 +20,19 @@ public static function getAll($id_warehouse){ /* [1] On récupère les modules de l'entrepot courant =========================================================*/ - $module = Table::get('module') - ->whereName([ $_SESSION['WAREHOUSE']['modules'], Rows::COND_IN ]); + $module_merge = Table::get('module_merge') + ->whereIdWarehouse(7); + $chip = Table::get('chip') + ->join('id_module', $module_merge) ->select('*'); - $module_merge = Table::get('module_merge') - ->join('id_module', $module); - - // var_dump($module_merge->fetch()); /* [2] On retourne le résultat =========================================================*/ + return $chip->fetch(); } } diff --git a/manager/repo/machine.php b/manager/repo/machine.php index 5adfdc9..a3dab25 100755 --- a/manager/repo/machine.php +++ b/manager/repo/machine.php @@ -180,7 +180,8 @@ $machine = Table::get('machine') ->whereId($id_machine) ->whereIdWarehouse($id_warehouse) - ->select(['id_machine', 'name']) + ->select('id_machine') + ->select('name') ->unique(); return $machine->fetch(); @@ -209,7 +210,8 @@ $machine = Table::get('machine') ->whereName($name) ->whereIdWarehouse($id_warehouse) - ->select(['id_machine', 'name']) + ->select('id_machine') + ->selcet('name') ->unique(); return $machine->fetch(); @@ -238,7 +240,8 @@ $machine = Table::get('machine') ->whereToken($token) ->whereIdWarehouse($id_warehouse) - ->select(['id_machine', 'name']) + ->select('id_machine') + ->select('name') ->unique(); return $machine->fetch(); @@ -264,7 +267,8 @@ =========================================================*/ $machine = Table::get('machine') ->whereIdWarehouse($id_warehouse) - ->select(['id_machine', 'name']); + ->select('id_machine') + ->select('name'); return $machine->fetch(); } diff --git a/manager/repo/user.php b/manager/repo/user.php index 4f142cc..89ea05d 100755 --- a/manager/repo/user.php +++ b/manager/repo/user.php @@ -218,7 +218,7 @@ $user = Table::get('user') ->whereIdWarehouse($id_warehouse) ->whereIdUser($id_user) - ->select(['id_user', 'code', 'username', 'firstname', 'lastname', 'mail']) + ->select('*') ->unique(); return $user->fetch(); @@ -246,7 +246,7 @@ $user = Table::get('user') ->whereIdWarehouse($id_warehouse) ->whereCode($code) - ->select(['id_user', 'code', 'username', 'firstname', 'lastname', 'mail']) + ->select('*') ->unique(); return $user->fetch(); @@ -274,7 +274,7 @@ $user = Table::get('user') ->whereIdWarehouse($id_warehouse) ->whereUsername($username) - ->select(['id_user', 'code', 'username', 'firstname', 'lastname', 'mail']) + ->select('*') ->unique(); return $user->fetch(); @@ -299,7 +299,7 @@ =========================================================*/ $user = Table::get('user') ->whereIdWarehouse($id_warehouse) - ->select(['id_user', 'code', 'username', 'firstname', 'lastname', 'mail']); + ->select('*'); return $user->fetch(); } diff --git a/test/automate.php b/test/automate.php index fe9561a..2e7c163 100755 --- a/test/automate.php +++ b/test/automate.php @@ -445,25 +445,15 @@ // var_dump($myUser); + $module_merge = Table::get('module_merge') + ->whereIdWarehouse(7); - $selReq = Database::getPDO()->query("select m.*, max(h.timestamp) as last - from history as h, machine as m - where h.id_machine = m.id_machine - group by m.id_machine"); - $selected = Database::delNumeric( $selReq->fetchAll() ); - var_dump($selected); - - - $mac = Table::get('machine') + $chip = Table::get('chip') + ->join('id_module', $module_merge) ->select('*'); - $selected = Table::get('history') - ->join('id_machine', $mac) - ->select('timestamp', Rows::SEL_MAX); - - var_dump($selected->fetch()); - + var_dump($chip->fetch()); // $a = new ModuleRequest('authentificationDefault/warehouse', [