[OPT] Department id * * @return departments Matching departments * ---------------------------------------------------------*/ public function get($args){ $id_dep = null; extract($args); /** @var meta $meta_repo */ $meta_repo = Repo::getRepo('meta'); /* (1) Get the list of linked departments for this @cas_login */ $departments = $meta_repo->get_prof_departments($_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){ $department = 0; extract($args); /** @var meta $meta_repo */ $meta_repo = Repo::getRepo('meta'); $deps = $meta_repo->get_prof_departments($_SESSION['CAS']['login']); if( count($deps) > 0 ){ foreach($deps as $dep){ if( $dep['idDep'] == $department ){ $_SESSION['AvailableDepartments'] = $deps; $_SESSION['CurrentDepartmentId'] = $dep['idDep']; $_SESSION['VERSION'] = [ 'list' => $dep['versions'], 'current' => null ]; // select version with default = 1 foreach($_SESSION['VERSION']['list'] as $v){ if( $v['default'] == 1 ){ $_SESSION['VERSION']['current'] = intval($v['iddatabase']); $_SESSION['CurrentDatabase'] = $v['dbName']; break; } } // if no default -> select first if( !is_int($_SESSION['VERSION']) ){ $_SESSION['VERSION']['current'] = intval($_SESSION['VERSION']['list'][0]['iddatabase']); $_SESSION['CurrentDatabase'] = $_SESSION['VERSION']['list'][0]['dbName']; } return ['switched' => true]; } } } return ['switched' => false]; } }