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:
parent
23c62e940f
commit
cbfb39a116
|
@ -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
|
||||
=========================================================*/
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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', [
|
||||
|
|
|
@ -66,6 +66,8 @@
|
|||
->select('id_history', Rows::SEL_COUNT, Rows::SEL_DISTINCT)
|
||||
->fetch();
|
||||
|
||||
var_dump($selected);
|
||||
|
||||
|
||||
echo "<article class='inline-row' style='border: 0; box-shadow: none;background: transparent;'>";
|
||||
echo "<span>Machine</span>";
|
||||
|
|
Loading…
Reference in New Issue