From b2bce3163267d90dccf53cf879b59eab79b23dd4 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 1 Mar 2018 17:31:15 +0100 Subject: [PATCH] [module.professor] implemented GET method (getById if id given, else getAll) --- build/api/module/ProfessorController.php | 33 +++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/build/api/module/ProfessorController.php b/build/api/module/ProfessorController.php index eae9b0e..1218352 100644 --- a/build/api/module/ProfessorController.php +++ b/build/api/module/ProfessorController.php @@ -14,11 +14,42 @@ use database\repo\professor; class ProfessorController{ + + /* (1) Returns 1 or all professors + * + * @prof_id [OPT] The professor UID + * + * @return professors The professor(s) data + * + ---------------------------------------------------------*/ public static function get($args){ $prof_id = null; extract($args); - return ['teachers' => [1, 2]]; + /* Get the professor repo */ + $prof_repo = Repo::getRepo('professor'); + + + /* (1) If @prof_id is set -> getById() + ---------------------------------------------------------*/ + if( !is_null($prof_id) ){ + + /* (1) Only get one professor by its id */ + $fetch_prof = $prof_repo->getById((int) $prof_id); + + /* (2) If nothing found -> return empty set */ + if( is_null($fetch_prof) ) + return ['professors' => []]; + + /* (3) Else -> return the professor */ + return ['professors' => [$fetch_prof]]; + + } + + + /* (2) Else -> getAll() + ---------------------------------------------------------*/ + return ['professors' => $prof_repo->getAll($prof_id)]; } } \ No newline at end of file