ptut-vhost/build/api/module/ue/coursController.php

46 lines
889 B
PHP
Raw Permalink Normal View History

<?php
namespace api\module\ue;
use database\core\Repo;
use database\repo\cours;
use error\core\Error;
use error\core\Err;
class coursController{
/* (1) Get groups for a specific UE
*
* @code<String> UE code
*
* @return groups<array> The list of groups for this UE
*
---------------------------------------------------------*/
public static function get($args){
$code = "";
extract($args);
/* Get the cours repo */
/** @var cours $cours_repo */
$cours_repo = Repo::getRepo('cours');
/* (1) Try to fetch data */
$fetched = $cours_repo->getGroups($code);
/* (2) Manage error */
if( is_null($fetched) || !is_array($fetched) )
return ['error' => new Error(Err::RepoError)];
/* (3) Parse JSON list */
foreach($fetched as $f=>$v)
$fetched[$f]['formations'] = json_decode($v['formations']);
return ['groups' => $fetched];
}
}