This commit is contained in:
xdrm-brackets 2018-05-09 17:51:47 +02:00
commit fa7d9ee6f2
3 changed files with 81 additions and 1 deletions

View File

@ -14,7 +14,7 @@ use database\core\Repo;
class formationController class formationController
{ {
public static function get($args){ public function get($args){
$form_id = null; $form_id = null;
extract($args); extract($args);
@ -24,4 +24,37 @@ class formationController
return ['formations' => $repo->get($form_id)]; 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) /* (2) Check if a formation exists (by its label)

View File

@ -495,6 +495,33 @@
"par": { "par": {
"URL0":{"des" : "Id of the formation", "typ": "id", "ren": "form_id", "opt" : true } "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" }
}
} }
}, },