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

64 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/**
* Created by PhpStorm.
* User: lucas
* Date: 20/02/18
* Time: 20:30
*/
namespace database\repo;
use database\core\Repo_i;
class ue extends Repo_i {
public function create(string $code, string $label, bool $required, float $volumeCours, float $volumeTD, float $volumeTP, bool $disabled = false) : int {
$st = $this->pdo->prepare("INSERT INTO UE(code, label, required, volumeCours, volumeTD, volumeTP, disabled)
VALUE(:code, :label, :required, :volCours, :volTD, :volTP, :disabled) ");
$st->execute([
"code" => $code,
"label" => $label,
"required" => $required ? 1 : 0,
"volCours" => $volumeCours,
"volTD" => $volumeTD,
"volTP" => $volumeTP,
"disabled" => $disabled ? 1 : 0
]);
return $this->pdo->lastInsertId();
}
public function update(string $code, array $data) : bool{
$updSt = "";
foreach ($data as $key => $field){
$updSt .= "$key = :$key,";
}
$updSt = rtrim($updSt,",");
$st = $this->pdo->prepare("UPDATE UE SET $updSt WHERE code = :code");
return $st->execute(array_merge($data,[
"code" => $code
]));
}
public function delete(string $code) : bool {
$st = $this->pdo->prepare("DELETE FROM UE WHERE code = :code");
return $st->execute([
"code" => $code
]);
}
public function disable(string $code) : bool {
return $this->update($code, ["disabled" => 1]);
}
public function enable(string $code) : bool {
return $this->update($code, ["disabled" => 0]);
}
}