54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?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{
|
|
|
|
public function create(int $id, string $label) : bool{
|
|
//create the category or update the label
|
|
$st = $this->pdo->prepare("INSERT INTO Categorie (idCategorie, labelCategorie) VALUE (:id, :label)");
|
|
|
|
return $st->execute([
|
|
"id" => $id,
|
|
"label" => $label
|
|
]);
|
|
|
|
}
|
|
|
|
public function delete(int $id) :bool{
|
|
$st = $this->pdo->prepare("DELETE FROM Categorie WHERE idCategorie = :id");
|
|
|
|
return $st->execute([
|
|
"id" => $id
|
|
]);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
} |