From 4352f02dc95dbc9c867c88d817110d83081852c2 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 6 Mar 2018 14:49:48 +0100 Subject: [PATCH] [webpack.teacher.view] show all professors when (no filter|empty filter) --- .../api/module/professor/filterController.php | 26 +++++++++++-------- webpack/data/teacher.js | 7 ++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/build/api/module/professor/filterController.php b/build/api/module/professor/filterController.php index 43f2e98..7631cca 100644 --- a/build/api/module/professor/filterController.php +++ b/build/api/module/professor/filterController.php @@ -28,8 +28,8 @@ class filterController{ ---------------------------------------------------------*/ public static function post($args){ - $formations = null; - $ues = null; + $formations = []; + $ues = []; extract($args); /** @var ue $ue_repo */ @@ -38,18 +38,22 @@ class filterController{ /* (1) If no filter -> return error ---------------------------------------------------------*/ - /* (1) Exit if no filter */ - if( is_null($formations) && is_null($ues) ) + /* (1) Pre-process conditions */ + $no_ue = !is_array($ues) || count($ues) < 1; + $no_formation = !is_array($formations) || count($formations) < 1; + + /* (2) Exit if no filter */ + if( $no_ue && $no_formation ) return ['error' => new Error(Err::MissingParam, 'You must give at least 1 parameter')]; - /* (2) Init. result array (only keys used for unicity) */ + /* (3) Init. result array (only keys used for unicity) */ $matches_uniq = []; /* (2) Filter by formation ---------------------------------------------------------*/ - if( !is_null($formations) ){ + if( is_array($formations) ){ /** @var formation $form_repo */ $form_repo = Repo::getRepo('formation'); @@ -58,15 +62,15 @@ class filterController{ foreach($formations as $form_id){ // 1. Ignore if wrong format - if( !is_numeric($form_id) || intval($form_id) !== $form_id ) + if( !is_numeric($form_id) || !is_int($form_id) ) continue; // 2. Get from repo - $fetched_ids = $form_repo->getProfessors($form_id); + $fetched_ids = $form_repo->getProfessors( intval($form_id) ); // 3. Add in unique set foreach($fetched_ids as $prof_id) - $matches_uniq[ intval($prof_id["idProfesseur"]) ] = null; + $matches_uniq[ intval($prof_id['idProfesseur']) ] = null; } @@ -77,7 +81,7 @@ class filterController{ /* (3) Filter by ue ---------------------------------------------------------*/ - if( !is_null($ues) ){ + if( is_array($ues) ){ /** @var ue $ue_repo */ $ue_repo = Repo::getRepo('ue'); @@ -94,7 +98,7 @@ class filterController{ // 3. Add in unique set foreach($fetched_ids as $prof_id) - $matches_uniq[ intval($prof_id["idProfesseur"]) ] = null; + $matches_uniq[ intval($prof_id['idProfesseur']) ] = null; } diff --git a/webpack/data/teacher.js b/webpack/data/teacher.js index 2205720..a20c332 100644 --- a/webpack/data/teacher.js +++ b/webpack/data/teacher.js @@ -47,12 +47,13 @@ gstore.add('filter_handler', function(){ } - /* (3) Get professor id for matching filter */ api.call('POST professor/filter', request, function(rs){ - // 1. Abort on error - if( rs.error !== 0 ) return console.log('No filter result found, error: '+rs.error); + // 1. Display all on error + if( rs.error !== 0 ) + rs.matches = gstore.get.professors.map(function(prof,i){ return i; }); + console.log(rs); // 2. Fetch professor elements