[POST cours|td|tp] adds the default formation if exists + given formations as arguments - also it returns as output the added formation id list
This commit is contained in:
parent
367d3c5988
commit
ca9ca6e290
|
@ -25,10 +25,31 @@ class coursController{
|
||||||
$formations = [];
|
$formations = [];
|
||||||
extract($args);
|
extract($args);
|
||||||
|
|
||||||
/* Get the cours repo */
|
/* Get the repos */
|
||||||
/** @var cours $cours_repo */
|
/** @var cours $cours_repo */
|
||||||
$cours_repo = Repo::getRepo('cours');
|
$cours_repo = Repo::getRepo('cours');
|
||||||
|
/** @var ue $ue_repo */
|
||||||
|
$ue_repo = Repo::getRepo('ue');
|
||||||
|
|
||||||
|
|
||||||
|
/* (1) Fetch default formation from UE
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
/* (1) Try to fetch the cours' UE */
|
||||||
|
$fetched_ue = $ue_repo->get($code);
|
||||||
|
|
||||||
|
/* (2) Manage error */
|
||||||
|
if( !is_array($fetched_ue) || count($fetched_ue) < 1 )
|
||||||
|
return ['error' => new Error(Err::RepoError)];
|
||||||
|
|
||||||
|
$defaultForm = intval($fetched_ue[0]['idForm']);
|
||||||
|
|
||||||
|
/* (3) Add to formation list if got a valid default formation */
|
||||||
|
if( is_int($defaultForm) && $defaultForm >= 0 && !in_array($defaultForm, $formations) )
|
||||||
|
$formations[] = $defaultForm;
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Create the cours
|
||||||
|
---------------------------------------------------------*/
|
||||||
/* (1) Try to create cours */
|
/* (1) Try to create cours */
|
||||||
$created_id = $cours_repo->create($code, $idProf, $volume, $formations);
|
$created_id = $cours_repo->create($code, $idProf, $volume, $formations);
|
||||||
|
|
||||||
|
@ -36,6 +57,7 @@ class coursController{
|
||||||
if( is_null($created_id) || !is_int($created_id) )
|
if( is_null($created_id) || !is_int($created_id) )
|
||||||
return ['error' => new Error(Err::RepoError)];
|
return ['error' => new Error(Err::RepoError)];
|
||||||
|
|
||||||
|
|
||||||
return ['created_id' => $created_id];
|
return ['created_id' => $created_id];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,31 @@ class tdController{
|
||||||
$formations = [];
|
$formations = [];
|
||||||
extract($args);
|
extract($args);
|
||||||
|
|
||||||
/* Get the td repo */
|
/* Get the repos */
|
||||||
/** @var td $td_repo */
|
/** @var td $td_repo */
|
||||||
$td_repo = Repo::getRepo('td');
|
$td_repo = Repo::getRepo('td');
|
||||||
|
/** @var ue $ue_repo */
|
||||||
|
$ue_repo = Repo::getRepo('ue');
|
||||||
|
|
||||||
|
|
||||||
|
/* (1) Fetch default formation from UE
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
/* (1) Try to fetch the TD' UE */
|
||||||
|
$fetched_ue = $ue_repo->get($code);
|
||||||
|
|
||||||
|
/* (2) Manage error */
|
||||||
|
if( !is_array($fetched_ue) || count($fetched_ue) < 1 )
|
||||||
|
return ['error' => new Error(Err::RepoError)];
|
||||||
|
|
||||||
|
$defaultForm = intval($fetched_ue[0]['idForm']);
|
||||||
|
|
||||||
|
/* (3) Add to formation list if got a valid default formation */
|
||||||
|
if( is_int($defaultForm) && $defaultForm >= 0 && !in_array($defaultForm, $formations) )
|
||||||
|
$formations[] = $defaultForm;
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Create the TD
|
||||||
|
---------------------------------------------------------*/
|
||||||
/* (1) Try to create td */
|
/* (1) Try to create td */
|
||||||
$created_id = $td_repo->create($code, $idProf, $volume, $formations);
|
$created_id = $td_repo->create($code, $idProf, $volume, $formations);
|
||||||
|
|
||||||
|
@ -36,7 +57,7 @@ class tdController{
|
||||||
if( is_null($created_id) || !is_int($created_id) )
|
if( is_null($created_id) || !is_int($created_id) )
|
||||||
return ['error' => new Error(Err::RepoError)];
|
return ['error' => new Error(Err::RepoError)];
|
||||||
|
|
||||||
return ['created_id' => $created_id];
|
return ['created_id' => $created_id, 'formations' => $formations];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,31 @@ class tpController{
|
||||||
$formations = [];
|
$formations = [];
|
||||||
extract($args);
|
extract($args);
|
||||||
|
|
||||||
/* Get the tp repo */
|
/* Get the repos */
|
||||||
/** @var tp $tp_repo */
|
/** @var tp $tp_repo */
|
||||||
$tp_repo = Repo::getRepo('tp');
|
$tp_repo = Repo::getRepo('tp');
|
||||||
|
/** @var ue $ue_repo */
|
||||||
|
$ue_repo = Repo::getRepo('ue');
|
||||||
|
|
||||||
|
|
||||||
|
/* (1) Fetch default formation from UE
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
/* (1) Try to fetch the TP' UE */
|
||||||
|
$fetched_ue = $ue_repo->get($code);
|
||||||
|
|
||||||
|
/* (2) Manage error */
|
||||||
|
if( !is_array($fetched_ue) || count($fetched_ue) < 1 )
|
||||||
|
return ['error' => new Error(Err::RepoError)];
|
||||||
|
|
||||||
|
$defaultForm = intval($fetched_ue[0]['idForm']);
|
||||||
|
|
||||||
|
/* (3) Add to formation list if got a valid default formation */
|
||||||
|
if( is_int($defaultForm) && $defaultForm >= 0 && !in_array($defaultForm, $formations) )
|
||||||
|
$formations[] = $defaultForm;
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Create the TP
|
||||||
|
---------------------------------------------------------*/
|
||||||
/* (1) Try to create tp */
|
/* (1) Try to create tp */
|
||||||
$created_id = $tp_repo->create($code, $idProf, $volume, $formations);
|
$created_id = $tp_repo->create($code, $idProf, $volume, $formations);
|
||||||
|
|
||||||
|
|
|
@ -316,7 +316,8 @@
|
||||||
"formations": { "des": "List of formations (ids)", "typ": "array<id>", "opt": true, "def": [] }
|
"formations": { "des": "List of formations (ids)", "typ": "array<id>", "opt": true, "def": [] }
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"created_id" : { "des": "The id of the created Cours", "typ": "id" }
|
"created_id" : { "des": "The id of the created Cours", "typ": "id" },
|
||||||
|
"formations" : { "des": "The ids of the linked formations", "typ": "array<id>" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -368,7 +369,8 @@
|
||||||
"formations": { "des": "List of formations (ids)", "typ": "array<id>", "opt": true, "def": [] }
|
"formations": { "des": "List of formations (ids)", "typ": "array<id>", "opt": true, "def": [] }
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"created_id" : { "des": "The id of the created TD", "typ": "id" }
|
"created_id" : { "des": "The id of the created TD", "typ": "id" },
|
||||||
|
"formations" : { "des": "The ids of the linked formations", "typ": "array<id>" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -420,7 +422,8 @@
|
||||||
"formations": { "des": "List of formations (ids)", "typ": "array<id>", "opt": true, "def": [] }
|
"formations": { "des": "List of formations (ids)", "typ": "array<id>", "opt": true, "def": [] }
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"created_id" : { "des": "The id of the created TP", "typ": "id" }
|
"created_id" : { "des": "The id of the created TP", "typ": "id" },
|
||||||
|
"formations" : { "des": "The ids of the linked formations", "typ": "array<id>" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue