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 IFNULL(VHCours,0) VHCours, IFNULL(VHTd,0)VHTd, IFNULL(VHTp,0)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 LEFT JOIN UE U ON Cours.UE_code = U.code GROUP BY Prof.Categorie_idCategorie, U.disabled HAVING U.disabled = 0) 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 LEFT JOIN UE U2 ON TD.UE_code = U2.code GROUP BY Prof.Categorie_idCategorie, U2.disabled HAVING U2.disabled = 0) 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 LEFT JOIN UE U3 ON TP.UE_code = U3.code GROUP BY Prof.Categorie_idCategorie, U3.disabled HAVING U3.disabled = 0) 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(); } } /* (4) Gets a category by its UID ||| getAll * * @cat_id [OPT] The category UID, if not set, getAll() * * @return categories The categories matching id (NULL on error) * ---------------------------------------------------------*/ public function get(?int $cat_id=null) : ?array{ /* (1) Manage if no id given */ $cond = is_null($cat_id) ? '' : ' WHERE `idCategorie` = :id'; $parm = is_null($cat_id) ? [] : [':id' => $cat_id]; /* (2) Prepare Statement */ $st = $this->pdo->prepare("SELECT * FROM `Categorie`$cond ORDER BY `labelCategorie` ASC"); /* (3) Bind params and execute statement */ if( is_bool($st) ) return []; $success = $st->execute($parm); /* (4) Manage error */ if( !$success ) return []; /* (5) Get data */ $fetched = $st->fetchAll(); /* (6) Return [] on no result */ if( $fetched === false ) return []; /* (7) Return data */ return $fetched; } }