2018-03-15 11:02:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: lucas
|
|
|
|
* Date: 15/03/18
|
|
|
|
* Time: 11:47
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace api\module;
|
|
|
|
|
|
|
|
|
|
|
|
use database\core\Repo;
|
2018-03-20 17:44:43 +00:00
|
|
|
use database\repo\meta;
|
2018-03-15 11:02:28 +00:00
|
|
|
|
2018-03-15 16:38:06 +00:00
|
|
|
class departmentController
|
2018-03-15 11:02:28 +00:00
|
|
|
{
|
|
|
|
|
2018-03-20 10:47:54 +00:00
|
|
|
/* (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);
|
|
|
|
|
2018-03-20 17:44:43 +00:00
|
|
|
/** @var meta $meta_repo */
|
|
|
|
$meta_repo = Repo::getRepo('meta');
|
2018-03-20 10:47:54 +00:00
|
|
|
|
|
|
|
/* (1) Get the list of linked departments for this @cas_login */
|
2018-03-20 17:44:43 +00:00
|
|
|
$departments = $meta_repo->get_prof_departments($_SESSION['CAS']['login']);
|
2018-03-20 10:47:54 +00:00
|
|
|
|
|
|
|
/* (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];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-15 11:02:28 +00:00
|
|
|
public function put($args){
|
|
|
|
$department = 0;
|
|
|
|
extract($args);
|
|
|
|
|
2018-03-20 09:49:53 +00:00
|
|
|
|
2018-03-20 17:44:43 +00:00
|
|
|
/** @var meta $meta_repo */
|
|
|
|
$meta_repo = Repo::getRepo('meta');
|
2018-03-15 11:02:28 +00:00
|
|
|
|
2018-03-20 09:49:53 +00:00
|
|
|
|
|
|
|
|
2018-03-20 17:44:43 +00:00
|
|
|
$deps = $meta_repo->get_prof_departments($_SESSION['CAS']['login']);
|
2018-03-15 11:02:28 +00:00
|
|
|
|
2018-03-20 09:49:53 +00:00
|
|
|
|
|
|
|
|
2018-03-19 18:05:19 +00:00
|
|
|
if( count($deps) > 0 ){
|
2018-03-20 09:49:53 +00:00
|
|
|
|
|
|
|
foreach($deps as $dep){
|
|
|
|
|
2018-05-09 13:12:26 +00:00
|
|
|
if( $dep['idDep'] == $department ){
|
2018-03-20 09:49:53 +00:00
|
|
|
|
|
|
|
$_SESSION['AvailableDepartments'] = $deps;
|
|
|
|
$_SESSION['CurrentDepartmentId'] = $dep['idDep'];
|
2018-05-09 13:12:26 +00:00
|
|
|
$_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'];
|
|
|
|
}
|
2018-03-15 11:02:28 +00:00
|
|
|
|
2018-03-17 18:07:44 +00:00
|
|
|
return ['switched' => true];
|
2018-03-20 09:49:53 +00:00
|
|
|
|
2018-03-15 11:02:28 +00:00
|
|
|
}
|
2018-03-20 09:49:53 +00:00
|
|
|
|
2018-03-15 11:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:07:44 +00:00
|
|
|
return ['switched' => false];
|
2018-03-15 11:02:28 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|