2018-03-05 09:39:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: lucas
|
|
|
|
* Date: 27/02/18
|
|
|
|
* Time: 16:19
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace api\module;
|
|
|
|
|
|
|
|
|
|
|
|
use database\core\Repo;
|
|
|
|
use database\repo\ue;
|
|
|
|
use error\core\Error;
|
|
|
|
use error\core\Err;
|
|
|
|
|
|
|
|
class ueController{
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) Returns 1 or all UEs
|
|
|
|
*
|
|
|
|
* @code<String> [OPT] The UE code
|
|
|
|
*
|
|
|
|
* @return ues<array> The UE(s) data
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public static function get($args){
|
|
|
|
$code = null;
|
|
|
|
extract($args);
|
|
|
|
|
|
|
|
/* Get the ue repo */
|
|
|
|
/** @var ue $ue_repo */
|
|
|
|
$ue_repo = Repo::getRepo('ue');
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) Get All ues or 1 by its code (if set) */
|
|
|
|
$fetched = $ue_repo->get($code);
|
|
|
|
|
|
|
|
/* (3) Return data */
|
|
|
|
return ['ues' => $fetched];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-11 18:34:11 +00:00
|
|
|
/* (2) Creates a new UE
|
|
|
|
*
|
|
|
|
* @code<String> The code of the UE
|
|
|
|
* @label<String> The UE label (name)
|
|
|
|
* @required<bool> If the UE is required
|
|
|
|
* @volumeCours<float> The UE required volume of COURSES
|
|
|
|
* @volumeTD<float> The UE required volume of TD
|
|
|
|
* @volumeTP<float> The UE required volume of TP
|
|
|
|
* @disabled<bool> [OPT] If it is disabled
|
|
|
|
* @defaultFormation<int> [OPT] If there is a foreign key for a default formation (if only one formation)
|
|
|
|
*
|
|
|
|
* @return created_code<int> The created UE code (if no error)
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public static function post($args){
|
|
|
|
$code = "";
|
|
|
|
$label = "";
|
|
|
|
$required = false;
|
|
|
|
$volumeCours = 0;
|
|
|
|
$volumeTD = 0;
|
|
|
|
$volumeTP = 0;
|
|
|
|
$disabled = true;
|
2018-03-12 09:43:08 +00:00
|
|
|
$defaultFormation = -1;
|
2018-03-11 18:34:11 +00:00
|
|
|
extract($args);
|
|
|
|
|
|
|
|
/* Get the ue repo */
|
|
|
|
/** @var ue $ue_repo */
|
|
|
|
$ue_repo = Repo::getRepo('ue');
|
|
|
|
|
|
|
|
/* (1) Check if ue code already exists */
|
|
|
|
$exists = $ue_repo->get($code);
|
|
|
|
|
|
|
|
/* (2) If found -> already exists */
|
|
|
|
if( count($exists) > 0 )
|
|
|
|
return ['error' => new Error(Err::AlreadyExists)];
|
|
|
|
|
|
|
|
/* (3) Else try to create */
|
|
|
|
$repo_rtn = $ue_repo->create(
|
|
|
|
$code,
|
|
|
|
$label,
|
|
|
|
$required,
|
|
|
|
$volumeCours,
|
|
|
|
$volumeTD,
|
|
|
|
$volumeTP,
|
|
|
|
$disabled,
|
2018-03-12 09:43:08 +00:00
|
|
|
is_int($defaultFormation) && $defaultFormation < 0 ? null : $defaultFormation
|
2018-03-11 18:34:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) If repo error -> return it */
|
|
|
|
if( is_null($repo_rtn) )
|
|
|
|
return ['error' => new Error(Err::RepoError)];
|
|
|
|
|
|
|
|
|
|
|
|
/* (5) Else return UID */
|
|
|
|
return ['created_code' => $repo_rtn];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-11 17:13:41 +00:00
|
|
|
/* (3) Deletes an existing UE
|
|
|
|
*
|
|
|
|
* @code<String> The UE code
|
|
|
|
*
|
|
|
|
* @return deleted<bool> Whether it has been removed
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public static function delete($args){
|
|
|
|
$code = '';
|
|
|
|
extract($args);
|
|
|
|
|
|
|
|
/* Get the ue repo */
|
|
|
|
/** @var ue $ue_repo */
|
|
|
|
$ue_repo = Repo::getRepo('ue');
|
|
|
|
|
|
|
|
/* (1) Try to delete */
|
|
|
|
return ['deleted' => $ue_repo->delete($code)];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-11 18:34:11 +00:00
|
|
|
/* (4) Edits an existing UE
|
|
|
|
*
|
|
|
|
* @code<String> The code of the UE
|
|
|
|
* @label<String> [OPT] The UE label (name)
|
|
|
|
* @required<bool> [OPT] If the UE is required
|
|
|
|
* @volumeCours<float> [OPT] The UE required volume of COURSES
|
|
|
|
* @volumeTD<float> [OPT] The UE required volume of TD
|
|
|
|
* @volumeTP<float> [OPT] The UE required volume of TP
|
|
|
|
* @disabled<bool> [OPT] If it is disabled
|
2018-03-12 09:57:53 +00:00
|
|
|
* @defaultFormation<int> [OPT] default formation for this UE (-1 to unset, NULL to ignore)
|
2018-03-11 18:34:11 +00:00
|
|
|
*
|
|
|
|
* @return updated<bool> Whether it has been updated
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public static function put($args){
|
|
|
|
$code = "";
|
|
|
|
$label = "";
|
|
|
|
$required = false;
|
|
|
|
$volumeCours = 0;
|
|
|
|
$volumeTD = 0;
|
|
|
|
$volumeTP = 0;
|
|
|
|
$disabled = true;
|
2018-03-12 09:57:53 +00:00
|
|
|
$defaultFormation = null;
|
2018-03-11 18:34:11 +00:00
|
|
|
extract($args);
|
|
|
|
|
|
|
|
/* Get the ue repo */
|
|
|
|
/** @var ue $ue_repo */
|
|
|
|
$ue_repo = Repo::getRepo('ue');
|
|
|
|
|
|
|
|
/* (1) Try to update */
|
|
|
|
return ['updated' => $ue_repo->update(
|
|
|
|
$code,
|
|
|
|
$label,
|
|
|
|
$required,
|
|
|
|
$volumeCours,
|
|
|
|
$volumeTD,
|
|
|
|
$volumeTP,
|
|
|
|
$disabled,
|
2018-03-12 09:57:53 +00:00
|
|
|
$defaultFormation
|
2018-03-11 18:34:11 +00:00
|
|
|
)];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-05 09:39:43 +00:00
|
|
|
}
|