2018-02-27 13:46:38 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: lucas
|
|
|
|
* Date: 20/02/18
|
|
|
|
* Time: 21:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace database\repo;
|
|
|
|
|
|
|
|
|
|
|
|
use database\core\Repo_i;
|
|
|
|
|
|
|
|
class category extends Repo_i{
|
|
|
|
|
2018-03-05 19:30:05 +00:00
|
|
|
public function create(int $id, string $label) : bool{
|
2018-02-27 13:46:38 +00:00
|
|
|
//create the category or update the label
|
2018-03-05 19:30:05 +00:00
|
|
|
$st = $this->pdo->prepare("INSERT INTO Categorie (idCategorie, labelCategorie) VALUE (:id, :label)");
|
2018-02-27 13:46:38 +00:00
|
|
|
|
2018-03-05 19:30:05 +00:00
|
|
|
return $st->execute([
|
2018-02-27 13:46:38 +00:00
|
|
|
"id" => $id,
|
|
|
|
"label" => $label
|
|
|
|
]);
|
2018-03-05 19:30:05 +00:00
|
|
|
|
2018-02-27 13:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function delete(int $id) :bool{
|
|
|
|
$st = $this->pdo->prepare("DELETE FROM Categorie WHERE idCategorie = :id");
|
|
|
|
|
|
|
|
return $st->execute([
|
|
|
|
"id" => $id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-03-01 15:57:44 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 13:46:38 +00:00
|
|
|
}
|