fix DatabaseDriver encoding + implement prof category stats
(and add possiblity to get all formations stat in one query)
This commit is contained in:
parent
3ecda58c42
commit
ad56ce1751
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: lucas
|
||||||
|
* Date: 01/03/18
|
||||||
|
* Time: 16:43
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace api\module;
|
||||||
|
|
||||||
|
|
||||||
|
use database\core\Repo;
|
||||||
|
|
||||||
|
class Category
|
||||||
|
{
|
||||||
|
|
||||||
|
public function get($args){
|
||||||
|
$idCat = 0;
|
||||||
|
extract($args);
|
||||||
|
|
||||||
|
/** @var \database\repo\formation $repo */
|
||||||
|
$repo = Repo::getRepo("category");
|
||||||
|
|
||||||
|
return ["data" => $repo->getStats($idCat)];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ class Formation
|
||||||
/** @var \database\repo\formation $repo */
|
/** @var \database\repo\formation $repo */
|
||||||
$repo = Repo::getRepo("formation");
|
$repo = Repo::getRepo("formation");
|
||||||
|
|
||||||
return ["data" => $repo->getStat($idForm)];
|
return ["data" => $repo->getStats($idForm)];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -69,7 +69,7 @@
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
$this->pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->username, $this->password, [
|
$this->pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->dbname.';charset=utf8', $this->username, $this->password, [
|
||||||
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
||||||
\PDO::ATTR_TIMEOUT => 5
|
\PDO::ATTR_TIMEOUT => 5
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -31,4 +31,23 @@ class category extends Repo_i{
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getStats(?int $id = null){
|
||||||
|
$st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, Cat.idCategorie idCat, count(P.idProfesseur) nbrProf, Cat.labelCategorie labelCat
|
||||||
|
FROM Categorie Cat
|
||||||
|
LEFT JOIN (SELECT IFNULL(SUM(Cours.volume),0) VHCours, Prof.Categorie_idCategorie idCat FROM Professeur Prof LEFT JOIN Cours ON Prof.idProfesseur = Cours.Professeur_idProfesseur GROUP BY Prof.Categorie_idCategorie) VHCours ON VHCours.idCat = Cat.idCategorie
|
||||||
|
LEFT JOIN (SELECT IFNULL(SUM(TD.volume),0) VHTd , Prof.Categorie_idCategorie idCat FROM Professeur Prof LEFT JOIN TD ON TD.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.Categorie_idCategorie) VHTd ON VHTd.idCat = Cat.idCategorie
|
||||||
|
LEFT JOIN (SELECT IFNULL(SUM(TP.volume),0) VHTp, Prof.Categorie_idCategorie idCat FROM Professeur Prof LEFT JOIN TP ON TP.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.Categorie_idCategorie) VHTp ON VHTp.idCat = Cat.idCategorie
|
||||||
|
LEFT JOIN Professeur P ON Cat.idCategorie = P.Categorie_idCategorie
|
||||||
|
".($id ? " WHERE Cat.idCategorie = :idCat" : "")."
|
||||||
|
GROUP BY Cat.idCategorie;");
|
||||||
|
|
||||||
|
$st->execute($id ? ["idCat" => $id] : []);
|
||||||
|
|
||||||
|
if($id){
|
||||||
|
return $st->fetch() ?: [];
|
||||||
|
}else{
|
||||||
|
return $st->fetchAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -42,24 +42,22 @@ class formation extends Repo_i {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStat(int $id) :array{
|
public function getStats(?int $id) :array{
|
||||||
$st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, (VHCours + VHTd + VHTp) VHTotal, Form.isInternal isInternal
|
$st = $this->pdo->prepare("SELECT IFNULL(VHCours,0) VHCours, IFNULL(VHTd,0) VHTd, IFNULL(VHTp,0) VHTp, (IFNULL(VHCours,0) + IFNULL(VHTd,0) + IFNULL(VHTp,0)) VHTotal, Form.isInternal isInternal, Form.idFormation idForm, Form.labelFormation labelForm
|
||||||
FROM Formation Form,
|
FROM Formation Form
|
||||||
(SELECT IFNULL(SUM(C.volume),0) VHCours, GC.Formation_idFormation idForm FROM GroupeCours GC LEFT JOIN Cours C ON GC.Cours_idCours = C.idCours GROUP BY GC.Formation_idFormation) VHCours,
|
LEFT JOIN (SELECT IFNULL(SUM(C.volume),0) VHCours, GC.Formation_idFormation idForm FROM GroupeCours GC LEFT JOIN Cours C ON GC.Cours_idCours = C.idCours GROUP BY GC.Formation_idFormation) VHCours ON VHCours.idForm = Form.idFormation
|
||||||
(SELECT IFNULL(SUM(T.volume),0) VHTd, GTD.Formation_idFormation idForm FROM GroupeTD GTD LEFT JOIN TD T ON GTD.TD_idTD = T.idTD GROUP BY GTD.Formation_idFormation) VHTd,
|
LEFT JOIN (SELECT IFNULL(SUM(T.volume),0) VHTd, GTD.Formation_idFormation idForm FROM GroupeTD GTD LEFT JOIN TD T ON GTD.TD_idTD = T.idTD GROUP BY GTD.Formation_idFormation) VHTd ON VHTd.idForm = Form.idFormation
|
||||||
(SELECT IFNULL(SUM(T2.volume),0) VHTp, GTP.Formation_idFormation idForm FROM GroupeTP GTP LEFT JOIN TP T2 ON GTP.TP_idTP = T2.idTP GROUP BY GTP.Formation_idFormation) VHTp
|
LEFT JOIN (SELECT IFNULL(SUM(T2.volume),0) VHTp, GTP.Formation_idFormation idForm FROM GroupeTP GTP LEFT JOIN TP T2 ON GTP.TP_idTP = T2.idTP GROUP BY GTP.Formation_idFormation) VHTp ON VHTp.idForm = Form.idFormation
|
||||||
WHERE
|
".($id ? " WHERE Form.idFormation = :idForm" : "")."
|
||||||
Form.idFormation = :idForm AND
|
|
||||||
VHCours.idForm = Form.idFormation AND
|
|
||||||
VHTp.idForm = Form.idFormation AND
|
|
||||||
VHTd.idForm = Form.idFormation;
|
|
||||||
");
|
");
|
||||||
|
|
||||||
$st->execute([
|
$st->execute($id ? ["idForm" => $id] : []);
|
||||||
"idForm" => $id
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $st->fetch() ?: [];
|
if($id){
|
||||||
|
return $st->fetch() ?: [];
|
||||||
|
}else{
|
||||||
|
return $st->fetchAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -47,7 +47,17 @@
|
||||||
"des": "Get all data about a formation",
|
"des": "Get all data about a formation",
|
||||||
"per": [],
|
"per": [],
|
||||||
"par": {
|
"par": {
|
||||||
"URL0":{"des" : "Id of the formation", "typ": "id", "ren": "idForm", "opt" : false}
|
"URL0":{"des" : "Id of the formation", "typ": "id", "ren": "idForm", "opt" : true}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"Category": {
|
||||||
|
"GET": {
|
||||||
|
"des" : "Get all data about a professor category",
|
||||||
|
"per": [],
|
||||||
|
"par": {
|
||||||
|
"URL0":{"des" : "Id of the category", "typ": "id", "ren": "idCat", "opt" : true}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue