[api.department] added GET (id or ALL)
This commit is contained in:
parent
c5adb6d660
commit
e301a7eb2e
|
@ -15,6 +15,48 @@ use database\repo\professor;
|
||||||
class departmentController
|
class departmentController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* (1) Get 1 | all departments
|
||||||
|
*
|
||||||
|
* @id_dep<int> [OPT] Department id
|
||||||
|
*
|
||||||
|
* @return departments<array> Matching departments
|
||||||
|
*
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
public function get($args){
|
||||||
|
$id_dep = null;
|
||||||
|
extract($args);
|
||||||
|
|
||||||
|
/** @var professor $prof_repo */
|
||||||
|
$prof_repo = Repo::getRepo('professor');
|
||||||
|
|
||||||
|
/* (1) Get the list of linked departments for this @cas_login */
|
||||||
|
$departments = $prof_repo->getLinkedDepartments($_SESSION['CAS']['login']);
|
||||||
|
|
||||||
|
/* (2) If no @id_dep -> return all */
|
||||||
|
if( is_null($id_dep) )
|
||||||
|
return ['departments' => $departments];
|
||||||
|
|
||||||
|
/* (3) If @id_dep -> Only add elements that are @id_dep */
|
||||||
|
$filtered = [];
|
||||||
|
|
||||||
|
foreach($departments as $dep){
|
||||||
|
|
||||||
|
if( $dep['idDep'] == $id_dep ){
|
||||||
|
$filtered[] = $dep;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (4) Return filtered departments */
|
||||||
|
return ['departments' => $filtered];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function put($args){
|
public function put($args){
|
||||||
$department = 0;
|
$department = 0;
|
||||||
extract($args);
|
extract($args);
|
||||||
|
|
|
@ -75,6 +75,17 @@
|
||||||
|
|
||||||
"department":{
|
"department":{
|
||||||
|
|
||||||
|
"GET": {
|
||||||
|
"des": "Get one or all departments",
|
||||||
|
"per": [["cas_user"]],
|
||||||
|
"par": {
|
||||||
|
"URL0": { "des": "Optional department id.", "typ": "id", "ren": "id_dep", "opt": true }
|
||||||
|
},
|
||||||
|
"out": {
|
||||||
|
"departments": { "des": "department list", "typ": "array" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"PUT":{
|
"PUT":{
|
||||||
"des": "Switch the user on another department database",
|
"des": "Switch the user on another department database",
|
||||||
"per": [],
|
"per": [],
|
||||||
|
|
Loading…
Reference in New Issue