pdo->prepare("INSERT INTO Professeur (casLogin, lastName, firstName, abreviation, admin,hoursToDo, Categorie_idCategorie) VALUE (:casLogin, :lastName, :firstName, :abrev, :admin, :hoursToDo, :cat); "); $st->execute([ "casLogin" => $casLogin, "lastName" => $lastName, "firstName" => $firstName, "abrev" => $initials, "admin" => $isAdmin? 1 : 0, "hoursToDo" => $hoursToDo, "cat" => $category ]); return $this->pdo->lastInsertId(); } public function exists(string $lastName, string $firstName) : int{ $st = $this->pdo->prepare("SELECT idProfesseur FROM Professeur WHERE firstName = :firstName AND lastName = :lastName"); $st->execute([ "firstName" => $firstName, "lastName" => $lastName ]); return $st->fetch()["idProfesseur"]?: 0; } public function update(int $id, array $data) : bool{ $updSt = ""; foreach ($data as $key => $field){ $updSt .= "$key = :$key,"; } $updSt = rtrim($updSt,","); $st = $this->pdo->prepare("UPDATE Professeur SET $updSt WHERE idProfesseur = :id"); return $st->execute(array_merge($data,[ "id" => $id ])); } public function isAdmin(int $id) : bool{ $st = $this->pdo->prepare("SELECT admin FROM Professeur WHERE idProfesseur = :id"); $st->execute([ "id" => $id ]); return $st->fetch()["admin"] == 1; } public function get(int $id) : array{ $st = $this->pdo->prepare("SELECT * FROM Professeur WHERE idProfesseur = :id"); $st->execute([ "id" => $id ]); return $st->fetch(); } public function delete(int $id) : bool{ $st = $this->pdo->prepare("DELETE FROM Professeur WHERE idProfesseur = :id"); return $st->execute([ "id" => $id ]); } public function getVH(int $id) : array{ $st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, Cat.idCategorie idCat, Prof.hoursToDo du FROM Professeur Prof, Categorie Cat, (SELECT IFNULL(SUM(Cours.volume),0) VHCours, Prof.idProfesseur idProf FROM Professeur Prof LEFT JOIN Cours ON Prof.idProfesseur = Cours.Professeur_idProfesseur GROUP BY Prof.idProfesseur) VHCours, (SELECT IFNULL(SUM(TD.volume),0) VHTd , Prof.idProfesseur idProf FROM Professeur Prof LEFT JOIN TD ON TD.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.idProfesseur) VHTd, (SELECT IFNULL(SUM(TP.volume),0) VHTp, Prof.idProfesseur idProf FROM Professeur Prof LEFT JOIN TP ON TP.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.idProfesseur) VHTp WHERE Prof.idProfesseur = :idProf AND Prof.Categorie_idCategorie = Cat.idCategorie AND VHCours.idProf = Prof.idProfesseur AND VHTp.idProf = Prof.idProfesseur AND VHTd.idProf = Prof.idProfesseur;"); $st->execute([ "idProf" => $id ]); return $st->fetch() ?: []; } }