From 56cc3eec82ef8e5ad6590a84e01ee87d657f64a9 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 5 Mar 2018 19:35:35 +0100 Subject: [PATCH] [module.root] to test params | [config.mdules] --- .../api/module/professor/filterController.php | 109 ++++++++++++++++++ build/api/module/rootController.php | 2 +- config/modules.json | 16 ++- 3 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 build/api/module/professor/filterController.php diff --git a/build/api/module/professor/filterController.php b/build/api/module/professor/filterController.php new file mode 100644 index 0000000..20c5526 --- /dev/null +++ b/build/api/module/professor/filterController.php @@ -0,0 +1,109 @@ + [OPT] Array of formation IDS + * @ues [OPT] Array of UE codes + * + * @return matches 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)]; + + } + +} \ No newline at end of file diff --git a/build/api/module/rootController.php b/build/api/module/rootController.php index 4195916..b210dfb 100644 --- a/build/api/module/rootController.php +++ b/build/api/module/rootController.php @@ -10,7 +10,7 @@ /* Generates the API documentation * */ - public function get($args){ + public function post($args){ extract($args); return [ 'args' => $args ]; diff --git a/config/modules.json b/config/modules.json index 5b96093..247cd0b 100644 --- a/config/modules.json +++ b/config/modules.json @@ -1,9 +1,21 @@ { - "GET": { + "POST": { "des": "Returns the API documentation", "per": [], "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 type", "typ": "array", "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 } } },