65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?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 $defaultFormation = null) : int {
|
|
$st = $this->pdo->prepare("INSERT INTO UE(code, label, required, volumeCours, volumeTD, volumeTP, disabled, Formation_idFormation)
|
|
VALUE(:code, :label, :required, :volCours, :volTD, :volTP, :disabled, :idFormation) ");
|
|
|
|
$st->execute([
|
|
"code" => $code,
|
|
"label" => $label,
|
|
"required" => $required ? 1 : 0,
|
|
"volCours" => $volumeCours,
|
|
"volTD" => $volumeTD,
|
|
"volTP" => $volumeTP,
|
|
"disabled" => $disabled ? 1 : 0,
|
|
"idFormation" => $defaultFormation
|
|
]);
|
|
|
|
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]);
|
|
}
|
|
} |