pdo->prepare("INSERT INTO Cours(UE_code, Professeur_idProfesseur, volume) VALUE(:UE, :idProf, :vol)"); $st->execute([ "UE" => $codeUE, "idProf" => $idProf, "vol" => $volume ]); $idCours = $this->pdo->lastInsertId(); //if there is formations, link them with the group if(count($formations) > 0){ $linkSt = $this->pdo->prepare("INSERT INTO GroupeCours(Formation_idFormation, Cours_idCours) VALUE (:form, :cours)"); foreach ($formations as $form){ $linkSt->execute([ "form" => $form, "cours" => $idCours ]); } } return $idCours; } public function unlinkFormation(int $idFormation, int $idCours) : bool{ $st = $this->pdo->prepare("DELETE FROM GroupeCours WHERE Cours_idCours = :cours AND Formation_idFormation = :form"); return $st->execute([ "cours" => $idCours, "form" => $idFormation ]); } public function linkFormation(int $idFormation, int $idCours) : bool{ $st = $this->pdo->prepare("INSERT INTO GroupeCours(Cours_idCours,Formation_idFormation) VALUE(:cours, :form)"); return $st->execute([ "cours" => $idCours, "form" => $idFormation ]); } public function updateProf(?int $prof) : bool { $st = $this->pdo->prepare("UPDATE Cours SET Professeur_idProfesseur = :prof"); return $st->execute([ "prof" => $prof ]); } public function updateVolume(float $volume) : bool { $st = $this->pdo->prepare("UPDATE Cours SET volume = :vol"); return $st->execute([ "vol" => $volume ]); } public function delete(int $id) :bool { $st = $this->pdo->prepare("DELETE FROM Cours WHERE idCours = :id"); return $st->execute([ "id" => $id ]); } }