page = intval($page); if($this->page>=1) $this->page-=1; $this->nb_questions_by_page = ($nb_questions_by_page ? $nb_questions_by_page : $opac_search_results_per_page); $this->themes = array_filter((isset($filters['themes']) && $filters['themes'] ? $filters['themes'] : array())); $this->types = array_filter((isset($filters['types']) && $filters['types'] ? $filters['types'] : array())); $this->descriptors = array_filter((isset($filters['descriptors']) && $filters['descriptors'] ? $filters['descriptors'] : array())); $this->years = array_filter((isset($filters['years']) && $filters['years'] ? $filters['years'] : array()),function($var){return ($var!=="");}); $this->user_query = (isset($filters['user_query']) ? trim($filters['user_query']) : ''); $this->fetch_datas(); } protected function fetch_datas(){ global $dbh; $query = "select id_faq_question from faq_questions !!join!!!!where!! order by faq_question_question_date desc, faq_question_answer_date desc, faq_question_question asc"; $join = $where= array(); $where[] = ($_SESSION["id_empr_session"] ? "faq_question_statut in (2,3)" : "faq_question_statut = 2"); if(count($this->themes)){ $where[] = "faq_question_num_theme in (".implode(",",$this->themes).")"; } if(count($this->types)){ $where[] = "faq_question_num_type in (".implode(",",$this->types).")"; } if(count($this->descriptors)){ $join[] = "join faq_questions_categories on id_faq_question=num_faq_question "; $where[] = "num_categ in (".implode(",",$this->descriptors).")"; } if(count($this->years)){ $where[] = "year(faq_question_answer_date) in (".implode(",",$this->years).")"; } $query = str_replace("!!join!!",implode(" ",$join),$query); if(count($where)){ $where = implode(" and ",$where); $query = str_replace("!!where!!","where ".$where,$query); }else $query = str_replace("!!where!!","",$query); $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)){ $this->questions_ids = array(); while($row = pmb_mysql_fetch_object($result)){ $this->questions_ids[] = $row->id_faq_question; } } if($this->user_query){ $aq = new analyse_query($this->user_query); $query = $aq->get_query_mot("id_faq_question", "faq_questions_words_global_index", "word","faq_questions_fields_global_index", "value"); $query.= " where id_faq_question in(".implode(",",$this->questions_ids).")"; $this->questions_ids = array(); $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)){ while($row = pmb_mysql_fetch_object($result)){ $this->questions_ids[] = $row->id_faq_question; } } } } protected function get_page_title(){ global $msg,$charset; $title = sprintf($msg['faq_question_page_title'],count($this->questions_ids)); return $title; } public function show(){ global $include_path; $html="

".$this->get_page_title()."

 
"; $start = $this->page * $this->nb_questions_by_page; $end =$start+$this->nb_questions_by_page; for($i=$start ; $i<$end ; $i++){ if(isset($this->questions_ids[$i])){ $this->question[$this->questions_ids[$i]] = new faq_question($this->questions_ids[$i]); $html.=$this->question[$this->questions_ids[$i]]->get_listview(); } } $html.="
".$this->get_navigator()."
"; return $html; } protected function get_navigator(){ if(count($this->questions_ids)){ $url_page = "javascript:document.faq_filters.faq_page.value=!!page!!;document.faq_filters.submit()"; $nb_per_page_custom_url = "javascript:document.faq_filters.nb_per_page_custom.value=!!nb_per_page_custom!!"; $action = "javascript:document.faq_filters.faq_page.value=document.form.page.value;document.faq_filters.submit()"; return " "; } } protected function init_filters_infos(){ global $dbh,$msg; //thèmes $themes = $this->get_facette_informations(3,1); if(count($themes)) $this->filters['themes'] = $themes; //types $types = $this->get_facette_informations(4,1); if(count($types)) $this->filters['types'] = $types; //descripteurs $descriptors = $this->get_facette_informations(6,1); if(count($descriptors)) $this->filters['descriptors'] = $descriptors; //descripteurs $years = $this->get_facette_informations(9,0); if(count($years)){ foreach($years as $key =>$values){ if($years[$key]['label'] == 0){ $years[$key]['label'] = $msg['faq_facette_no_date']; } } $this->filters['years'] = $years; } } protected function get_facette_informations($code_champ,$code_ss_champ=0){ global $dbh, $msg, $charset,$lang; $informations = array(); $query = "select distinct value as label ,authority_num as id,lang,count(id_faq_question) as nb_questions from faq_questions_fields_global_index where id_faq_question in (".implode(",",$this->questions_ids).") and code_champ = '".$code_champ."'"; if($code_ss_champ){ $query.= " and code_ss_champ = '".$code_ss_champ."'"; } $query.= " and lang in ('','".$lang."') group by label order by nb_questions desc"; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)>0){ while ($row = pmb_mysql_fetch_object($result)){ if(!$row->id){ $row->id = $row->label; } $informations[$row->id] = array( 'id' => $row->id, 'label' => $row->label, 'nb_questions' => $row->nb_questions ); } } return $informations; } protected function get_actives_facettes(){ global $dbh,$msg,$charset; $filter_actives = $facettes_filter = ""; //thèmes if(count($this->themes)){ $themes=new faq_themes("faq_themes", "id_theme", "libelle_theme"); foreach($this->themes as $theme){ $facettes_filter.=" "; $link="javascript:document.getElementById('faq_filters_themes').value='';document.faq_filters.faq_page.value=1;document.faq_filters.submit();"; $filter_actives.=" ".htmlentities($msg['faq_filter_themes'].": ".$themes->getLabel($theme),ENT_QUOTES,$charset)." ".$msg[ "; } }else{ $facettes_filter.=" "; } //Types if(count($this->types)){ $types=new faq_themes("faq_types", "id_type", "libelle_type"); foreach($this->types as $type){ $facettes_filter.=" "; $link="javascript:document.getElementById('faq_filters_types').value='';document.faq_filters.faq_page.value=1;document.faq_filters.submit();"; $filter_actives.=" ".htmlentities($msg['faq_filter_types'].": ".$types->getLabel($type),ENT_QUOTES,$charset)." ".$msg[ "; } }else{ $facettes_filter.=" "; } //descripteurs if(count($this->descriptors)){ foreach($this->descriptors as $descriptor){ $facettes_filter.=" "; $link="javascript:document.getElementById('faq_filters_descriptors').value='';document.faq_filters.faq_page.value=1;document.faq_filters.submit();"; $filter_actives.=" ".htmlentities($msg['faq_filter_descriptors'].": ".$this->filters['descriptors'][$descriptor]['label'],ENT_QUOTES,$charset)." ".$msg[ "; } }else{ $facettes_filter.=" "; } if(count($this->years)){ foreach($this->years as $year){ $facettes_filter.=" "; $link="javascript:document.getElementById('faq_filters_years').value='';document.faq_filters.faq_page.value=1;document.faq_filters.submit();"; $filter_actives.=" ".htmlentities($msg['faq_filter_years'].": ".$this->filters['years'][$year]['label'],ENT_QUOTES,$charset)." ".$msg[ "; } }else{ $facettes_filter.=" "; } if($filter_actives){ $facettes_filter.="

".htmlentities($msg['faq_facettes_actives'],ENT_QUOTES,$charset)."

".$filter_actives."
 
"; } return $facettes_filter; } protected function get_allowed_facettes(){ global $msg,$charset; $facettes_filter = $allowed_facettes= ""; if(count($this->filters)){ foreach($this->filters as $filter => $filter_values){ if(count($filter_values)>1){ $allowed_facettes.=" "; foreach($filter_values as $infos){ $link="javascript:document.getElementById(\"faq_filters_".$filter."\").value=\"".$infos['id']."\";document.faq_filters.faq_page.value=1;document.faq_filters.submit();"; $allowed_facettes.=" "; } $allowed_facettes.="
".htmlentities($msg['faq_filter_'.$filter],ENT_QUOTES,$charset)."
".htmlentities($infos['label']." (".$infos['nb_questions'].")",ENT_QUOTES,$charset)."
"; } } } if($allowed_facettes){ $facettes_filter.="

".htmlentities($msg['facette_list'],ENT_QUOTES,$charset)."

".$allowed_facettes."
"; } return $facettes_filter; } protected function get_search_filter(){ global $msg,$charset; $facettes_filter = "

".htmlentities($msg['faq_filter_user_query'],ENT_QUOTES,$charset)."

 
"; return $facettes_filter; } public function get_facettes_filter(){ global $msg,$charset; global $nb_per_page_custom; $this->init_filters_infos(); $facettes_filter = "
"; $facettes_filter.= $this->get_search_filter(); $facettes_filter.= $this->get_actives_facettes(); $facettes_filter.= $this->get_allowed_facettes(); $facettes_filter.= "
"; return $facettes_filter; } }