2018-03-01 14:57:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: lucas
|
|
|
|
* Date: 27/02/18
|
2018-03-01 16:21:48 +00:00
|
|
|
* Time: 16:19
|
2018-03-01 14:57:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace api\module;
|
|
|
|
|
|
|
|
|
|
|
|
use database\core\Repo;
|
2018-03-01 16:21:48 +00:00
|
|
|
use database\repo\professor;
|
2018-03-01 14:57:25 +00:00
|
|
|
|
2018-03-01 16:21:48 +00:00
|
|
|
class ProfessorController{
|
2018-03-01 14:57:25 +00:00
|
|
|
|
2018-03-01 16:31:15 +00:00
|
|
|
|
|
|
|
/* (1) Returns 1 or all professors
|
|
|
|
*
|
|
|
|
* @prof_id<int> [OPT] The professor UID
|
|
|
|
*
|
|
|
|
* @return professors<array> The professor(s) data
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2018-03-01 14:57:25 +00:00
|
|
|
public static function get($args){
|
2018-03-01 16:21:48 +00:00
|
|
|
$prof_id = null;
|
2018-03-01 14:57:25 +00:00
|
|
|
extract($args);
|
|
|
|
|
2018-03-01 16:31:15 +00:00
|
|
|
/* 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)];
|
2018-03-01 14:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|