Correction : ORM GROUP BY pour tout les champs qui ne sont pas '*' si ils le sont on prend les clés primaires

This commit is contained in:
xdrm-brackets 2016-07-25 11:19:05 +02:00
parent 9fca3a0546
commit 8b23102e7c
4 changed files with 31 additions and 81 deletions

View File

@ -853,11 +853,22 @@
/* (1) On cherche dans les champs locaux local */ /* (1) On cherche dans les champs locaux local */
foreach($selectTables as $table=>$fields) foreach($selectTables as $table=>$fields)
foreach($fields as $field=>$sel) foreach($fields as $field=>$sel)
// Si aucune fonction d'aggrégation
if( is_null($sel[0]) ){ if( is_null($sel[0]) ){
if( !isset($groupBy[$table]) ) if( !isset($groupBy[$table]) )
$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 */ /* (2) On compose la requête */
$requestString = SQLBuilder::BUILD($requestS).';'; $requestString = SQLBuilder::BUILD($requestS).';';
var_dump($requestString);
var_dump($bound);
/* (3) On prépare la requête */ /* (3) On prépare la requête */
$request = Database::getPDO()->prepare($requestString); $request = Database::getPDO()->prepare($requestString);
// var_dump($requestString);
/* [8] On exécute la requête et retourne le résultat /* [8] On exécute la requête et retourne le résultat
=========================================================*/ =========================================================*/

View File

@ -175,37 +175,26 @@
*/ */
public static function getPermissions($id_warehouse, $id_machine){ 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 //TODO: GROUP_CONCAT(DISTINCT a.id_action ORDER BY a.id_action ASC)
FROM $u = Table::get('user')
user as u, ->select('id_user')
user_cluster as uc, ->select('code');
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 $ucm = Table::get('user_cluster_merge')
AND uc.id_user_cluster = ucm.id_user_cluster ->join('id_user', $u);
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"); $m = Table::get('machine')
->whereId(5);
$getPermissions->execute([ $mcm = Table::get('machine_cluster_merge')
':id_warehouse' => $id_warehouse, ->join('id_machine', $m);
':id_machine' => $id_machine
]);
$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();
} }

View File

@ -445,57 +445,6 @@
// var_dump($myUser); // 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', [ // $a = new ModuleRequest('authentificationDefault/warehouse', [

View File

@ -66,6 +66,8 @@
->select('id_history', Rows::SEL_COUNT, Rows::SEL_DISTINCT) ->select('id_history', Rows::SEL_COUNT, Rows::SEL_DISTINCT)
->fetch(); ->fetch();
var_dump($selected);
echo "<article class='inline-row' style='border: 0; box-shadow: none;background: transparent;'>"; echo "<article class='inline-row' style='border: 0; box-shadow: none;background: transparent;'>";
echo "<span>Machine</span>"; echo "<span>Machine</span>";