ptut-vhost/build/database/repo/td.php

88 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/**
* Created by PhpStorm.
* User: lucas
* Date: 22/02/18
* Time: 13:27
*/
namespace database\repo;
use database\core\Repo_i;
class td extends Repo_i {
public function create(string $codeUE, ?int $idProf, float $volume, array $formations) : int{
//create the group
$st = $this->pdo->prepare("INSERT INTO TD(UE_code, Professeur_idProfesseur, volume)
VALUE(:UE, :idProf, :vol)");
$st->execute([
"UE" => $codeUE,
"idProf" => $idProf,
"vol" => $volume
]);
$idTD = $this->pdo->lastInsertId();
//if there is formations, link them with the group
if(count($formations) > 0){
$linkSt = $this->pdo->prepare("INSERT INTO GroupeTD(Formation_idFormation, TD_idTD)
VALUE (:form, :TD)");
foreach ($formations as $form){
$linkSt->execute([
"form" => $form,
"TD" => $idTD
]);
}
}
return $idTD;
}
public function unlinkFormation(int $idFormation, int $idTD) : bool{
$st = $this->pdo->prepare("DELETE FROM GroupeTD WHERE TD_idTD = :TD AND Formation_idFormation = :form");
return $st->execute([
"TD" => $idTD,
"form" => $idFormation
]);
}
public function linkFormation(int $idFormation, int $idTD) : bool{
$st = $this->pdo->prepare("INSERT INTO GroupeTD(TD_idTD,Formation_idFormation)
VALUE(:TD, :form)");
return $st->execute([
"TD" => $idTD,
"form" => $idFormation
]);
}
public function updateProf(?int $prof) : bool {
$st = $this->pdo->prepare("UPDATE TD SET Professeur_idProfesseur = :prof");
return $st->execute([
"prof" => $prof
]);
}
public function updateVolume(float $volume) : bool {
$st = $this->pdo->prepare("UPDATE TD SET volume = :vol");
return $st->execute([
"vol" => $volume
]);
}
public function delete(int $id) :bool {
$st = $this->pdo->prepare("DELETE FROM TD WHERE idTD = :id");
return $st->execute([
"id" => $id
]);
}
}