diff --git a/build/api/core/Checker.php b/build/api/core/Checker.php index 47ca7c2..1c49345 100755 --- a/build/api/core/Checker.php +++ b/build/api/core/Checker.php @@ -106,7 +106,7 @@ break; case 'alphanumeric': - return $checker && is_string($value) && preg_match('/^[\w\.-]+$/ui', $value); + return $checker && is_string($value) && preg_match('/^[\w\. -]+$/ui', $value); break; case 'letters': diff --git a/build/api/module/professor/filterController.php b/build/api/module/professor/filterController.php index 20c5526..3fa8235 100644 --- a/build/api/module/professor/filterController.php +++ b/build/api/module/professor/filterController.php @@ -77,28 +77,28 @@ class filterController{ /* (3) Filter by ue ---------------------------------------------------------*/ - // if( !is_null($ues) ){ + if( !is_null($ues) ){ - // /** @var ue $ue_repo */ - // $ue_repo = Repo::getRepo('ue'); + /** @var ue $ue_repo */ + $ue_repo = Repo::getRepo('ue'); - // /* (1) For each ue -> get request */ - // foreach($ues as $ue_code){ + /* (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; + // 1. Ignore if wrong format + if( !is_string($ue_code) || strlen($ue_code) < 1 ) + continue; - // // 2. Get from repo - // $fetched_ids = $ue_repo->getProfessors($ue_code); + // 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; + // 3. Add in unique set + foreach($fetched_ids as $prof_id) + $matches_uniq[ intval($prof_id) ] = null; - // } + } - // } + } diff --git a/build/database/repo/ue.php b/build/database/repo/ue.php index 8e89c6f..2c0f82c 100644 --- a/build/database/repo/ue.php +++ b/build/database/repo/ue.php @@ -188,4 +188,44 @@ class ue extends Repo_i { return $fetched; } + + + /* (7) Gets all professors who teaches a UE by code + * + * @code The UE code + * + * @return professors The professors' UID matching the @code of the UE + * + ---------------------------------------------------------*/ + public function getProfessors(String $code) : array{ + + /* (1) Prepare statement */ + $st = $this->pdo->prepare("SELECT p.idProfesseur + FROM Professeur p, UE u + WHERE ( + p.idProfesseur IN ( SELECT p_cr.idProfesseur FROM Professeur p_cr, Cours c WHERE c.Professeur_idProfesseur = p_cr.idProfesseur AND c.UE_code = u.code ) + OR p.idProfesseur IN ( SELECT p_td.idProfesseur FROM Professeur p_td, TD t WHERE t.Professeur_idProfesseur = p_td.idProfesseur AND t.UE_code = u.code ) + OR p.idProfesseur IN ( SELECT p_tp.idProfesseur FROM Professeur p_tp, TP t WHERE t.Professeur_idProfesseur = p_tp.idProfesseur AND t.UE_code = u.code ) + ) + AND u.code = :ue_code;"); + + /* (2) Bind params and execute statement */ + if( is_bool($st) ) return []; + $success = $st->execute([ ':ue_code' => $code ]); + + /* (3) Manage error */ + if( !$success ) + return []; + + /* (4) Get data */ + $fetched = $st->fetchAll(); + + /* (5) Return [] on no result */ + if( $fetched === false ) + return []; + + /* (6) Return data */ + return $fetched; + + } } \ No newline at end of file diff --git a/webpack/data/teacher.js b/webpack/data/teacher.js index 4ee7bbf..2205720 100644 --- a/webpack/data/teacher.js +++ b/webpack/data/teacher.js @@ -69,7 +69,7 @@ gstore.add('filter_handler', function(){ element.remClass('filter-hidden'); // 3.2. Only hide if does not match filter - if( rs.professors.indexOf(local_ptr[e].idProfesseur) <= -1 ) + if( rs.matches.indexOf(local_ptr[e].idProfesseur) <= -1 ) element.addClass('filter-hidden'); }