[repo.ue] now GET returns the field 'formations' that is a JSON array (shitty SQL) [module.ue] converts to real array data

This commit is contained in:
xdrm-brackets 2018-03-13 21:17:32 +01:00
parent 76ade95c18
commit 7d2d59402b
2 changed files with 31 additions and 9 deletions

View File

@ -36,6 +36,10 @@ class ueController{
/* (1) Get All ues or 1 by its code (if set) */
$fetched = $ue_repo->get($code);
/* (2) Parse 'formations' from json array */
foreach($fetched as $f=>$v)
$fetched[$f]['formations'] = \json_decode($v['formations']);
/* (3) Return data */
return ['ues' => $fetched];

View File

@ -174,7 +174,7 @@ class ue extends Repo_i {
public function get(?String $code=null) : array{
/* (1) Manage if no id given */
$cond = is_null($code) ? '' : 'WHERE `code` = :code';
$cond = is_null($code) ? '' : 'AND `ue.`code` = :code';
$parm = is_null($code) ? [] : [':code' => $code];
/* (2) Prepare Statement */
@ -188,15 +188,33 @@ class ue extends Repo_i {
ue.volumeTD,
ue.volumeTP,
IFNULL(ue.Formation_idFormation, -1) idForm,
f.labelFormation labelForm,
IFNULL(CONCAT('[', GROUP_CONCAT(fc.idForm, ',', ftd.idForm, ',', ftp.idForm), ']'), '[]') formations
FROM `UE` ue
LEFT JOIN Formation f ON ue.Formation_idFormation = f.idFormation
LEFT JOIN ( SELECT DISTINCT gc.Formation_idFormation idForm, c.UE_code as code FROM GroupeCours gc, Cours c WHERE gc.Cours_idCours = c.idCours GROUP BY gc.Formation_idFormation ) fc ON fc.code = ue.code
LEFT JOIN ( SELECT DISTINCT gtd.Formation_idFormation idForm, td.UE_code as code FROM GroupeTD gtd, TD td WHERE gtd.TD_idTD = td.idTD GROUP BY gtd.Formation_idFormation ) ftd ON ftd.code = ue.code
LEFT JOIN ( SELECT DISTINCT gtp.Formation_idFormation idForm, tp.UE_code as code FROM GroupeTP gtp, TP tp WHERE gtp.TP_idTP = tp.idTP GROUP BY gtp.Formation_idFormation ) ftp ON ftp.code = ue.code
fdef.labelFormation labelForm,
IFNULL(formlist.formations, '[]') formations
FROM UE ue
LEFT JOIN Formation fdef ON ue.Formation_idFormation = fdef.idFormation
LEFT JOIN (
SELECT ue2.code code, CONCAT('[',GROUP_CONCAT(fform.idFormation), ']') formations
FROM UE ue2, Formation fform
WHERE ( fform.idFormation IN (
SELECT DISTINCT Formation_idFormation as idForm
FROM GroupeCours
WHERE Cours_idCours IN ( SELECT idCours FROM Cours WHERE UE_code = ue2.code GROUP BY idForm )
)
OR fform.idFormation IN (
SELECT DISTINCT Formation_idFormation as idForm
FROM GroupeTD
WHERE TD_idTD IN ( SELECT idTD FROM TD WHERE UE_code = ue2.code GROUP BY idForm )
)
OR fform.idFormation IN (
SELECT DISTINCT Formation_idFormation as idForm
FROM GroupeTP
WHERE TP_idTP IN ( SELECT idTP FROM TP WHERE UE_code = ue2.code GROUP BY idForm )
)
)
GROUP BY `ue2`.`code`
) formlist ON formlist.code = ue.code
$cond
GROUP BY ue.code
GROUP BY `ue`.`code`
ORDER BY `ue`.`label` ASC");
/* (3) Bind params and execute statement */