From cbfb39a1161db4595e6cc01bda80e81ef2284391 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 25 Jul 2016 11:19:05 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20:=20ORM=20GROUP=20BY=20pour=20tout?= =?UTF-8?q?=20les=20champs=20qui=20ne=20sont=20pas=20'*'=20si=20ils=20le?= =?UTF-8?q?=20sont=20on=20prend=20les=20cl=C3=A9s=20primaires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manager/ORM/Rows.php | 16 ++++++++--- manager/repo/action_merge.php | 43 +++++++++++------------------ test/automate.php | 51 ----------------------------------- view/history.php | 2 ++ 4 files changed, 31 insertions(+), 81 deletions(-) diff --git a/manager/ORM/Rows.php b/manager/ORM/Rows.php index 5d1da63..85bbffd 100644 --- a/manager/ORM/Rows.php +++ b/manager/ORM/Rows.php @@ -853,11 +853,22 @@ /* (1) On cherche dans les champs locaux local */ foreach($selectTables as $table=>$fields) foreach($fields as $field=>$sel) + // Si aucune fonction d'aggrégation if( is_null($sel[0]) ){ if( !isset($groupBy[$table]) ) $groupBy[$table] = []; - $groupBy[$table][] = $field; + // Si le champ est *, on trouve les clés primaires + if( $field == '*' ){ + $columns = Table::get($table)->schema['columns']; + foreach($columns as $col=>$data) + if( $data['primary'] ) + $groupBy[$table][] = $col; + }else + $groupBy[$table][] = $field; + + + $groupBy[$table] = array_unique($groupBy[$table]); } @@ -880,11 +891,10 @@ /* (2) On compose la requête */ $requestString = SQLBuilder::BUILD($requestS).';'; - var_dump($requestString); - var_dump($bound); /* (3) On prépare la requête */ $request = Database::getPDO()->prepare($requestString); + // var_dump($requestString); /* [8] On exécute la requête et retourne le résultat =========================================================*/ diff --git a/manager/repo/action_merge.php b/manager/repo/action_merge.php index 145ce1b..ac50fea 100644 --- a/manager/repo/action_merge.php +++ b/manager/repo/action_merge.php @@ -7,7 +7,7 @@ use \manager\ORM\Table; use \manager\ORM\Rows; - + class action_merge extends parentRepo{ protected static function table_name(){ static $table_name = 'action_merge'; return $table_name; } @@ -175,37 +175,26 @@ */ public static function getPermissions($id_warehouse, $id_machine){ - $getPermissions = Database::getPDO()->prepare("SELECT u.id_user, u.code, GROUP_CONCAT(DISTINCT a.id_action ORDER BY a.id_action ASC) as actions - FROM - user as u, - user_cluster as uc, - user_cluster_merge as ucm, - machine as m, - machine_cluster as mc, - machine_cluster_merge as mcm, - action as a, - action_merge as am + //TODO: GROUP_CONCAT(DISTINCT a.id_action ORDER BY a.id_action ASC) + $u = Table::get('user') + ->select('id_user') + ->select('code'); - WHERE u.id_user = ucm.id_user - AND uc.id_user_cluster = ucm.id_user_cluster - AND am.id_source = uc.id_user_cluster - AND m.id_warehouse = u.id_warehouse - AND m.id_warehouse = :id_warehouse - AND m.id_machine = :id_machine - AND m.id_machine = mcm.id_machine - AND mc.id_machine_cluster = mcm.id_machine_cluster - AND am.id_target = mc.id_machine_cluster - AND a.id_action = am.id_action + $ucm = Table::get('user_cluster_merge') + ->join('id_user', $u); - GROUP BY u.id_user, u.code"); + $m = Table::get('machine') + ->whereId(5); - $getPermissions->execute([ - ':id_warehouse' => $id_warehouse, - ':id_machine' => $id_machine - ]); + $mcm = Table::get('machine_cluster_merge') + ->join('id_machine', $m); + $am= Table::get('action_merge') + ->join('id_source', $ucm) + ->join('id_target', $mcm) + ->select('id_action', Rows::SEL_CONCAT, Rows::SEL_DISTINCT); - return Database::delNumeric( $getPermissions->fetchAll() ); + return $am->fetch(); } diff --git a/test/automate.php b/test/automate.php index b76c050..e662819 100755 --- a/test/automate.php +++ b/test/automate.php @@ -445,57 +445,6 @@ // var_dump($myUser); - $getPermissions = Database::getPDO()->prepare("SELECT u.id_user, u.code, GROUP_CONCAT(DISTINCT a.id_action ORDER BY a.id_action ASC) as actions - FROM - user as u, - user_cluster as uc, - user_cluster_merge as ucm, - machine as m, - machine_cluster as mc, - machine_cluster_merge as mcm, - action as a, - action_merge as am - - WHERE u.id_user = ucm.id_user - AND uc.id_user_cluster = ucm.id_user_cluster - AND am.id_source = uc.id_user_cluster - AND m.id_warehouse = u.id_warehouse - AND m.id_warehouse = :id_warehouse - AND m.id_machine = :id_machine - AND m.id_machine = mcm.id_machine - AND mc.id_machine_cluster = mcm.id_machine_cluster - AND am.id_target = mc.id_machine_cluster - AND a.id_action = am.id_action - - GROUP BY u.id_user, u.code"); - - $getPermissions->execute([ - ':id_warehouse' => 7, - ':id_machine' => 5 - ]); - - - var_dump( Database::delNumeric( $getPermissions->fetchAll() ) ); - - $u = Table::get('user') - ->select('id_user') - ->select('code'); - - $ucm = Table::get('user_cluster_merge') - ->join('id_user', $u); - - $m = Table::get('machine') - ->whereId(5); - - $mcm = Table::get('machine_cluster_merge') - ->join('id_machine', $m); - - $am= Table::get('action_merge') - ->join('id_source', $ucm) - ->join('id_target', $mcm) - ->select('id_action', Rows::SEL_CONCAT, Rows::SEL_DISTINCT); - - var_dump($am->fetch()); // $a = new ModuleRequest('authentificationDefault/warehouse', [ diff --git a/view/history.php b/view/history.php index 62c6ba9..3f2eccb 100755 --- a/view/history.php +++ b/view/history.php @@ -66,6 +66,8 @@ ->select('id_history', Rows::SEL_COUNT, Rows::SEL_DISTINCT) ->fetch(); + var_dump($selected); + echo "
"; echo "Machine";