From a79710f3fea3b26e34e933d23527a4563aa6717e Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 29 Mar 2018 23:51:15 +0200 Subject: [PATCH] [repo.ue]Fix additionnals data computation --- build/database/repo/ue.php | 96 ++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/build/database/repo/ue.php b/build/database/repo/ue.php index 641c2c5..6ec3f37 100644 --- a/build/database/repo/ue.php +++ b/build/database/repo/ue.php @@ -180,52 +180,56 @@ class ue extends Repo_i { $parm = is_null($code) ? [] : [':code' => $code]; /* (2) Prepare Statement */ - $st = $this->pdo->prepare("SELECT - ue.code, - ue.label, - ue.disabled, - ue.required, - ue.volumeCours, - ue.volumeTD, - ue.volumeTP, - IFNULL(ue.Formation_idFormation, -1) idForm, - fdef.labelFormation labelForm, - IFNULL(formlist.formations, '[]') formations, - IFNULL(formlist.nbrCours,0) nbrCours, - IFNULL(formlist.nbrTD,0) nbrTD, - IFNULL(formlist.nbrTP,0) nbrTP, - IFNULL(formlist.modCours,0) modCours, - IFNULL(formlist.modTD,0) modTD, - IFNULL(formlist.modTP,0) modTP, - IFNULL(formlist.nbrProfCours,0) nbrProfCours, - IFNULL(formlist.nbrProfTD,0) nbrProfTD, - IFNULL(formlist.nbrProfTP,0) nbrProfTP - FROM UE ue - LEFT JOIN Formation fdef ON ue.Formation_idFormation = fdef.idFormation - LEFT JOIN ( - SELECT ue2.code code, CONCAT('[',GROUP_CONCAT(DISTINCT Formation.idFormation), ']') formations, - count(DISTINCT C.idCours) nbrCours, count(DISTINCT T.idTD) nbrTD, count(DISTINCT T2.idTP) nbrTP, - MOD(sum(DISTINCT C.volume),ue2.volumeCours) modCours, - MOD(sum(DISTINCT T.volume),ue2.volumeTD) modTD, - MOD(sum(DISTINCT T2.volume),ue2.volumeTP) modTP, - count(DISTINCT C.Professeur_idProfesseur) nbrProfCours, - count(DISTINCT T.Professeur_idProfesseur) nbrProfTD, - count(DISTINCT T2.Professeur_idProfesseur) nbrProfTP - FROM UE ue2 - LEFT JOIN Cours C ON ue2.code = C.UE_code - LEFT JOIN TD T ON ue2.code = T.UE_code - LEFT JOIN TP T2 ON ue2.code = T2.UE_code - LEFT JOIN GroupeCours C2 ON C.idCours = C2.Cours_idCours - LEFT JOIN GroupeTD TD2 ON T.idTD = TD2.TD_idTD - LEFT JOIN GroupeTP TP2 ON T2.idTP = TP2.TP_idTP - JOIN Formation ON C2.Formation_idFormation = Formation.idFormation - OR TD2.Formation_idFormation = Formation.idFormation - OR TP2.Formation_idFormation = Formation.idFormation - GROUP BY `ue2`.`code` - ) formlist ON formlist.code = ue.code - GROUP BY `ue`.`code` - $cond - ORDER BY `ue`.`label` ASC"); + $st = $this->pdo->prepare(" + SELECT + ue.code, + ue.label, + ue.disabled, + ue.required, + ue.volumeCours, + ue.volumeTD, + ue.volumeTP, + IFNULL(ue.Formation_idFormation, -1) idForm, + fdef.labelFormation labelForm, + IFNULL(formlist.formations, '[]') formations, + IFNULL(formlist.nbrCours,0) nbrCours, + IFNULL(formlist.nbrTD,0) nbrTD, + IFNULL(formlist.nbrTP,0) nbrTP, + IFNULL(formlist.modCours,1) modCours, + IFNULL(formlist.modTD,1) modTD, + IFNULL(formlist.modTP,1) modTP, + IFNULL(formlist.nbrProfCours,0) nbrProfCours, + IFNULL(formlist.nbrProfTD,0) nbrProfTD, + IFNULL(formlist.nbrProfTP,0) nbrProfTP + FROM UE ue + LEFT JOIN Formation fdef ON ue.Formation_idFormation = fdef.idFormation + LEFT JOIN ( + SELECT ue2.code code, CONCAT('[',GROUP_CONCAT(DISTINCT Formation.idFormation), ']') formations, + count(DISTINCT C.idCours) nbrCours, count(DISTINCT T.idTD) nbrTD, count(DISTINCT T2.idTP) nbrTP, + MOD(volC.vol,ue2.volumeCours) modCours, + MOD(volTD.vol,ue2.volumeTD) modTD, + MOD(volTP.vol,ue2.volumeTP) modTP, + count(DISTINCT C.Professeur_idProfesseur,C.idCours) nbrProfCours, + count(DISTINCT T.Professeur_idProfesseur,T.idTD) nbrProfTD, + count(DISTINCT T2.Professeur_idProfesseur,T2.idTP) nbrProfTP + FROM UE ue2 + LEFT JOIN (SELECT sum(CO.volume) vol, CO.UE_code FROM Cours CO GROUP BY CO.UE_code) volC ON ue2.code = volC.UE_code + LEFT JOIN (SELECT sum(TD2.volume) vol, TD2.UE_code FROM TD TD2 GROUP BY TD2.UE_code) volTD ON ue2.code = volTD.UE_code + LEFT JOIN (SELECT sum(TP2.volume) vol, TP2.UE_code FROM TP TP2 GROUP BY TP2.UE_code) volTP ON ue2.code = volTP.UE_code + LEFT JOIN Cours C ON ue2.code = C.UE_code + LEFT JOIN TD T ON ue2.code = T.UE_code + LEFT JOIN TP T2 ON ue2.code = T2.UE_code + LEFT JOIN GroupeCours C2 ON C.idCours = C2.Cours_idCours + LEFT JOIN GroupeTD TD2 ON T.idTD = TD2.TD_idTD + LEFT JOIN GroupeTP TP2 ON T2.idTP = TP2.TP_idTP + JOIN Formation ON C2.Formation_idFormation = Formation.idFormation + OR TD2.Formation_idFormation = Formation.idFormation + OR TP2.Formation_idFormation = Formation.idFormation + GROUP BY `ue2`.`code` + ) formlist ON formlist.code = ue.code + GROUP BY `ue`.`code` + $cond + ORDER BY `ue`.`label` ASC"); /* (3) Bind params and execute statement */ if( is_bool($st) ) return [];