Implement Formation CRUD

This commit is contained in:
Unknown 2018-05-08 19:23:46 +02:00
parent d803925b2b
commit d2dfd2e962
3 changed files with 81 additions and 1 deletions

View File

@ -14,7 +14,7 @@ use database\core\Repo;
class formationController
{
public static function get($args){
public function get($args){
$form_id = null;
extract($args);
@ -24,4 +24,37 @@ class formationController
return ['formations' => $repo->get($form_id)];
}
public function post($args){
$label = null;
$isInternal = null;
extract($args);
/** @var \database\repo\formation $repo */
$repo = Repo::getRepo("formation");
return ['idFormation' => $repo->create($label,$isInternal)];
}
public function put($args){
$idFormation = null;
$label = null;
$isInternal = null;
extract($args);
/** @var \database\repo\formation $repo */
$repo = Repo::getRepo("formation");
return ['success' => $repo->update($idFormation,$label,$isInternal)];
}
public function delete($args){
$idFormation = null;
extract($args);
/** @var \database\repo\formation $repo */
$repo = Repo::getRepo("formation");
return ['success' => $repo->delete($idFormation)];
}
}

View File

@ -42,6 +42,26 @@ class formation extends Repo_i {
}
public function update(int $idFormation, ?String $label, ?bool $isInternal) : bool{
$req = "";
$execute = [];
if($label != null){
$req .= "labelFormation=:label,";
$execute["label"] = $label;
}
if($isInternal != null){
$req .= "isInternal=:isInternal,";
$execute["isInternal"] = $isInternal?1:0;
}
$req = rtrim($req,",");
$execute["idFormation"] = $idFormation;
$st = $this->pdo->prepare("UPDATE `Formation` SET $req WHERE idFormation=:idFormation");
return $st->execute($execute);
}
/* (2) Check if a formation exists (by its label)

View File

@ -472,6 +472,33 @@
"par": {
"URL0":{"des" : "Id of the formation", "typ": "id", "ren": "form_id", "opt" : true }
}
},
"POST":{
"des": "Create a new formation",
"per": [["cas_admin"]],
"par": {
"label":{"des" : "name of the formation", "typ": "text" },
"isInternal":{"des" : "is this formation internal to the department", "typ": "bool" }
}
},
"PUT":{
"des": "Update a formation",
"per": [["cas_admin"]],
"par": {
"URL0": { "des": "Id of the formation", "typ": "id", "ren": "idFormation" },
"label":{"des" : "name of the formation", "typ": "text", "opt":true },
"isInternal":{"des" : "is this formation internal to the department", "typ": "bool", "opt":true }
}
},
"DELETE":{
"des": "Delete a formation",
"per": [["cas_admin"]],
"par": {
"URL0": { "des": "Id of the formation", "typ": "id", "ren": "idFormation" }
}
}
},