[repo.ue]Fix additionnals data computation

This commit is contained in:
Unknown 2018-03-29 23:51:15 +02:00
parent 5ea9d901a9
commit a79710f3fe
1 changed files with 50 additions and 46 deletions

View File

@ -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 [];