[webpack.teacher.view] filters now works

This commit is contained in:
xdrm-brackets 2018-03-05 19:51:28 +01:00
parent 443e401d66
commit 565f9d8d11
4 changed files with 57 additions and 17 deletions

View File

@ -77,28 +77,28 @@ class filterController{
/* (3) Filter by ue /* (3) Filter by ue
---------------------------------------------------------*/ ---------------------------------------------------------*/
// if( !is_null($ues) ){ if( !is_null($ues) ){
// /** @var ue $ue_repo */ /** @var ue $ue_repo */
// $ue_repo = Repo::getRepo('ue'); $ue_repo = Repo::getRepo('ue');
// /* (1) For each ue -> get request */ /* (1) For each ue -> get request */
// foreach($ues as $ue_code){ foreach($ues as $ue_code){
// // 1. Ignore if wrong format // 1. Ignore if wrong format
// if( !is_numeric($ue_code) || intval($ue_code) !== $ue_code ) if( !is_string($ue_code) || strlen($ue_code) < 1 )
// continue; continue;
// // 2. Get from repo // 2. Get from repo
// $fetched_ids = $ue_repo->getProfessors($ue_code); $fetched_ids = $ue_repo->getProfessors($ue_code);
// // 3. Add in unique set // 3. Add in unique set
// foreach($fetched_ids as $prof_id) foreach($fetched_ids as $prof_id)
// $matches_uniq[ intval($prof_id) ] = null; $matches_uniq[ intval($prof_id) ] = null;
// } }
// } }

View File

@ -188,4 +188,44 @@ class ue extends Repo_i {
return $fetched; return $fetched;
} }
/* (7) Gets all professors who teaches a UE by code
*
* @code<String> The UE code
*
* @return professors<array> 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;
}
} }

View File

@ -69,7 +69,7 @@ gstore.add('filter_handler', function(){
element.remClass('filter-hidden'); element.remClass('filter-hidden');
// 3.2. Only hide if does not match filter // 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'); element.addClass('filter-hidden');
} }