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

46 lines
865 B
PHP

<?php
namespace api\module\ue;
use database\core\Repo;
use database\repo\td;
use error\core\Error;
use error\core\Err;
class tdController{
/* (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 td repo */
/** @var td $td_repo */
$td_repo = Repo::getRepo('td');
/* (1) Try to fetch data */
$fetched = $td_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];
}
}