[renamed] 'AvailableDepartment' -> 'AvailableDepartments' [renamed] 'CurrentDepartementId' -> 'CurrentDepartmentId'

This commit is contained in:
xdrm-brackets 2018-03-20 10:49:53 +01:00
parent 35b0cb36fa
commit b06b8666bc
4 changed files with 23 additions and 14 deletions

View File

@ -23,10 +23,11 @@
/* (1) Init session variables
---------------------------------------------------------*/
if( !isset($_SESSION['CAS']) || !is_array($_SESSION['CAS']) ) $_SESSION['CAS'] = [];
if( !isset($_SESSION['AUTH']) || !is_array($_SESSION['AUTH']) ) $_SESSION['AUTH'] = [];
if( !isset($_SESSION['AvailableDepartment']) || !is_array($_SESSION['AvailableDepartment']) ) $_SESSION['AvailableDepartment'] = [];
if( !isset($_SESSION['VERSION']) || !is_string($_SESSION['VERSION']) ) $_SESSION['VERSION'] = null;
if( !isset($_SESSION['CAS']) || !is_array($_SESSION['CAS']) ) $_SESSION['CAS'] = [];
if( !isset($_SESSION['AUTH']) || !is_array($_SESSION['AUTH']) ) $_SESSION['AUTH'] = [];
if( !isset($_SESSION['AvailableDepartments']) || !is_array($_SESSION['AvailableDepartments']) ) $_SESSION['AvailableDepartments'] = [];
if( !isset($_SESSION['VERSION']) || !is_string($_SESSION['VERSION']) ) $_SESSION['VERSION'] = null;
if( !isset($_SESSION['CurrentDepartmentId']) || !is_array($_SESSION['CurrentDepartmentId']) ) $_SESSION['CurrentDepartmentId'] = null;
/* (2) Process AUTH

View File

@ -119,7 +119,7 @@ class casController{
return [ 'headers' => $headers, 'body' => $body_start.'-3'.$body_end ];
/* (3) Set departments data */
$_SESSION['AvailableDepartment'] = $departments;
$_SESSION['AvailableDepartments'] = $departments;
/* (4) Choose first department by default */
$_SESSION['CurrentDatabase'] = $departments[0]['dbName'];

View File

@ -16,25 +16,33 @@ class departmentController
{
public function put($args){
$department = 0;
extract($args);
/** @var professor $prof_repo */
$prof_repo = Repo::getRepo('professor');
$deps = $prof_repo->getLinkedDepartments($_SESSION['CAS']['login']);
if( count($deps) > 0 ){
foreach ($deps as $dep){
if($dep["idDep"] == $department){
$_SESSION["AvailableDepartment"] = $deps;
$_SESSION['CurrentDatabase'] = $dep["dbName"];
$_SESSION['CurrentDepartementId'] = $dep["idDep"];
foreach($deps as $dep){
if( $dep['idDep'] == $department){
$_SESSION['AvailableDepartments'] = $deps;
$_SESSION['CurrentDatabase'] = $dep['dbName'];
$_SESSION['CurrentDepartmentId'] = $dep['idDep'];
return ['switched' => true];
}
}
}

View File

@ -30,8 +30,8 @@
'session' => [
'name' => $_SESSION['CAS']['login'],
'connected' => isset($_SESSION['AUTH']) ? count($_SESSION['AUTH']) > 0 : false,
'departments' => array_map(function($d){ return [ 'id' => $d['idDep'], 'label' => $d['labelDep']]; }, $_SESSION['AvailableDepartment']),
'department_id' => $_SESSION['CurrentDepartementId'],
'departments' => array_map(function($d){ return [ 'id' => $d['idDep'], 'label' => $d['labelDep']]; }, $_SESSION['AvailableDepartments']),
'department_id' => $_SESSION['CurrentDepartmentId'],
'version' => $_SESSION['VERSION']
]