From 2b71469530f0d2ff9fbb0238dff98f95da011e95 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 1 Mar 2018 18:25:21 +0100 Subject: [PATCH] [module.professor] implemented PUT --- build/api/module/ProfessorController.php | 44 ++++++++++++++++++++++++ build/database/repo/professor.php | 14 ++++---- config/modules.json | 18 ++++++++++ 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/build/api/module/ProfessorController.php b/build/api/module/ProfessorController.php index 788293f..bea813e 100644 --- a/build/api/module/ProfessorController.php +++ b/build/api/module/ProfessorController.php @@ -134,4 +134,48 @@ class ProfessorController{ } + + /* (4) Edits an existing professor + * + * @prof_id The professor UID + * @lastName [OPT] The professor's lastName + * @firstName [OPT] The professor's firstName + * @category [OPT] The professor's category ID + * @hoursToDo [OPT] The professor's number of hours to do + * @initials [OPT] The professor's initials + * @isAdmin [OPT] Whether the professor is an admin + * @casLogin [OPT] The professor's CAS username + * + * @return updated Whether it has been updated + * + ---------------------------------------------------------*/ + public static function put($args){ + $prof_id = 0; + $lastName = null; + $firstName = null; + $category = null; + $hoursToDo = null; + $initials = null; + $isAdmin = null; + $casLogin = null; + extract($args); + + /* Get the professor repo */ + /** @var professor $prof_repo */ + $prof_repo = Repo::getRepo('professor'); + + /* (1) Try to update */ + return ['updated' => $prof_repo->update( + $prof_id, + $lastName, + $firstName, + $category, + $hoursToDo, + $initials, + $isAdmin, + $casLogin + )]; + + } + } \ No newline at end of file diff --git a/build/database/repo/professor.php b/build/database/repo/professor.php index 7270d93..3c05319 100644 --- a/build/database/repo/professor.php +++ b/build/database/repo/professor.php @@ -111,13 +111,13 @@ class professor extends Repo_i { $build_rq = []; $bind_param = [ ':idProfesseur' => $id ]; - if( !is_null($lastName) ){ $build_rq[] = '`lastName` = :lastName'; $bind_param[':lastName'] = $lastName; } - if( !is_null($firstName) ){ $build_rq[] = '`firstName` = :firstName'; $bind_param[':firstName'] = $firstName; } - if( !is_null($category) ){ $build_rq[] = '`category` = :category'; $bind_param[':category'] = $category; } - if( !is_null($hoursToDo) ){ $build_rq[] = '`hoursToDo` = :hoursToDo'; $bind_param[':hoursToDo'] = $hoursToDo; } - if( !is_null($initials) ){ $build_rq[] = '`initials` = :initials'; $bind_param[':initials'] = $initials; } - if( !is_null($isAdmin) ){ $build_rq[] = '`isAdmin` = :isAdmin'; $bind_param[':isAdmin'] = $isAdmin; } - if( !is_null($casLogin) ){ $build_rq[] = '`casLogin` = :casLogin'; $bind_param[':casLogin'] = $casLogin; } + if( !is_null($lastName) ){ $build_rq[] = '`lastName` = :lastName'; $bind_param[':lastName'] = $lastName; } + if( !is_null($firstName) ){ $build_rq[] = '`firstName` = :firstName'; $bind_param[':firstName'] = $firstName; } + if( !is_null($category) ){ $build_rq[] = '`Categorie_idCategorie` = :category'; $bind_param[':category'] = $category; } + if( !is_null($hoursToDo) ){ $build_rq[] = '`hoursToDo` = :hoursToDo'; $bind_param[':hoursToDo'] = $hoursToDo; } + if( !is_null($initials) ){ $build_rq[] = '`abreviation` = :initials'; $bind_param[':initials'] = $initials; } + if( !is_null($isAdmin) ){ $build_rq[] = '`admin` = :isAdmin'; $bind_param[':isAdmin'] = $isAdmin; } + if( !is_null($casLogin) ){ $build_rq[] = '`casLogin` = :casLogin'; $bind_param[':casLogin'] = $casLogin; } /* (2) ERROR if no updated field */ if( count($build_rq) <= 0 || count($bind_param) <= 1 ) diff --git a/config/modules.json b/config/modules.json index 7fd7a63..e34a95d 100644 --- a/config/modules.json +++ b/config/modules.json @@ -71,6 +71,24 @@ } }, + "PUT": { + "des": "Edits an existing professor", + "per": [], + "par": { + "URL0": { "des": "Optional professor UID.", "typ": "id", "ren": "prof_id" }, + "firstName": { "des": "Professor last name.", "typ": "varchar(2,30,alphanumeric)", "opt": true }, + "lastName": { "des": "Professor first name.", "typ": "varchar(2,30,alphanumeric)", "opt": true }, + "category": { "des": "Professor category UID.", "typ": "id", "opt": true }, + "hoursToDo": { "des": "Number of hours professor have to do", "typ": "id", "opt": true }, + "initials": { "des": "Professor initials", "typ": "varchar(2,2,letters)", "opt": true }, + "isAdmin": { "des": "Whether professor is an admin", "typ": "boolean", "opt": true }, + "casLogin": { "des": "Optional CAS username", "typ": "varchar(6,10,letters)", "opt": true } + }, + "out": { + "updated": { "des": "Whether the professor has been updated", "typ": "boolean" } + } + }, + "Stats": { "GET":{