[module.root] to test params | [config.mdules]

This commit is contained in:
xdrm-brackets 2018-03-05 19:35:35 +01:00
parent 8abf8cca2e
commit 56cc3eec82
3 changed files with 124 additions and 3 deletions

View File

@ -0,0 +1,109 @@
<?php
/**
* Created by PhpStorm.
* User: lucas
* Date: 27/02/18
* Time: 16:19
*/
namespace api\module\professor;
use database\core\Repo;
use database\repo\formation;
use database\repo\ue;
use error\core\Error;
use error\core\Err;
class filterController{
/* (1) Get professor ID(s) matching a specific filter
*
* @formations<array> [OPT] Array of formation IDS
* @ues<array> [OPT] Array of UE codes
*
* @return matches<array> Array of matching professor IDs
*
---------------------------------------------------------*/
public static function post($args){
$formations = null;
$ues = null;
extract($args);
/** @var ue $ue_repo */
$ue_repo = Repo::getRepo('ue');
/* (1) If no filter -> return error
---------------------------------------------------------*/
/* (1) Exit if no filter */
if( is_null($formations) && is_null($ues) )
return ['error' => new Error(Err::MissingParam, 'You must give at least 1 parameter')];
/* (2) Init. result array (only keys used for unicity) */
$matches_uniq = [];
/* (2) Filter by formation
---------------------------------------------------------*/
if( !is_null($formations) ){
/** @var formation $form_repo */
$form_repo = Repo::getRepo('formation');
/* (1) For each formation -> get request */
foreach($formations as $form_id){
// 1. Ignore if wrong format
if( !is_numeric($form_id) || intval($form_id) !== $form_id )
continue;
// 2. Get from repo
$fetched_ids = $form_repo->getProfessors($form_id);
// 3. Add in unique set
foreach($fetched_ids as $prof_id)
$matches_uniq[ intval($prof_id) ] = null;
}
}
/* (3) Filter by ue
---------------------------------------------------------*/
// if( !is_null($ues) ){
// /** @var ue $ue_repo */
// $ue_repo = Repo::getRepo('ue');
// /* (1) For each ue -> get request */
// foreach($ues as $ue_code){
// // 1. Ignore if wrong format
// if( !is_numeric($ue_code) || intval($ue_code) !== $ue_code )
// continue;
// // 2. Get from repo
// $fetched_ids = $ue_repo->getProfessors($ue_code);
// // 3. Add in unique set
// foreach($fetched_ids as $prof_id)
// $matches_uniq[ intval($prof_id) ] = null;
// }
// }
return ['matches' => array_keys($matches_uniq)];
}
}

View File

@ -10,7 +10,7 @@
/* Generates the API documentation /* Generates the API documentation
* *
*/ */
public function get($args){ public function post($args){
extract($args); extract($args);
return [ 'args' => $args ]; return [ 'args' => $args ];

View File

@ -1,9 +1,21 @@
{ {
"GET": { "POST": {
"des": "Returns the API documentation", "des": "Returns the API documentation",
"per": [], "per": [],
"par": { "par": {
"URL0": { "des": "Method name", "typ": "varchar(1,30)", "ren": "method_name", "opt": true, "def": null } "URL0": { "des": "Method name", "typ": "varchar(1,30)", "ren": "method_name", "opt": true, "def": null },
"mixed": { "des": "mixed type", "typ": "mixed", "opt": true },
"id": { "des": "id type", "typ": "id", "opt": true },
"text": { "des": "text type", "typ": "text", "opt": true },
"mail": { "des": "mail type", "typ": "mail", "opt": true },
"alphanumeric": { "des": "alphanumeric type", "typ": "alphanumeric", "opt": true },
"letters": { "des": "letters type", "typ": "letters", "opt": true },
"array": { "des": "array type", "typ": "array", "opt": true },
"array_id": { "des": "array<id> type", "typ": "array<id>", "opt": true },
"boolean": { "des": "boolean type", "typ": "boolean", "opt": true },
"object": { "des": "object type", "typ": "object", "opt": true },
"numeric": { "des": "numeric type", "typ": "numeric", "opt": true },
"float": { "des": "float type", "typ": "float", "opt": true }
} }
}, },