objects_ids = $objects_ids; $this->facette_existing(); $this->nb_results_by_facette(); } protected function facette_existing(){ global $opac_view_filter_class; $this->facettes = array(); $query = "SELECT * FROM ".static::$table_name." WHERE facette_visible_gestion=1 ORDER BY facette_order, facette_name"; $result = pmb_mysql_query($query); while($row = pmb_mysql_fetch_object($result)){ if($opac_view_filter_class) { if(!$opac_view_filter_class->is_selected(static::$table_name, $row->id_facette+0)) continue; } $this->facettes[] = array( 'id'=> $row->id_facette+0, 'name'=> translation::get_text($row->id_facette, 'facettes', 'facette_name', $row->facette_name), 'id_critere'=>$row->facette_critere+0, 'id_ss_critere'=>$row->facette_ss_critere+0, 'nb_result'=>$row->facette_nb_result+0, 'limit_plus'=>$row->facette_limit_plus+0, 'type_sort'=>$row->facette_type_sort+0, 'order_sort'=>$row->facette_order_sort+0, 'datatype_sort'=>$row->facette_datatype_sort ); } } public function nb_results_by_facette(){ global $msg; $this->tab_facettes = array(); if($this->objects_ids != ""){ foreach ($this->facettes as $facette) { $query = $this->get_query_by_facette($facette['id_critere'], $facette['id_ss_critere']); if ($facette['type_sort']==0) { $query .= " nb_result"; } else { if ($facette['datatype_sort']== 'date') { $query .= " STR_TO_DATE(value,'".$msg['format_date']."')"; } else { $query .= " value"; } } if($facette['order_sort']==0){ $query .= " asc"; } else { $query .= " desc"; } if($facette['nb_result']>0){ $query .= " LIMIT"." ".$facette['nb_result']; } $result = pmb_mysql_query($query); $j=0; $array_tmp = array(); $array_value = array(); $array_nb_result = array(); if($result && pmb_mysql_num_rows($result)){ while($row = pmb_mysql_fetch_object($result)){ $array_tmp[$j] = $row->value." "."(".($row->nb_result+0).")"; $array_value[$j] = $row->value; $array_nb_result[$j] = ($row->nb_result+0); $j++; } $this->exists_with_results = true; } $this->tab_facettes[] = array( 'name' => $facette['name'], 'facette' => $array_tmp, 'code_champ' => $facette['id_critere'], 'code_ss_champ' => $facette['id_ss_critere'], 'value' => $array_value, 'nb_result' => $array_nb_result, 'size_to_display' => $facette['limit_plus'] ); } } } public static function see_more($json_facette_plus){ global $charset; $arrayRetour = array(); for($j=0; $j htmlentities($facette_libelle,ENT_QUOTES,$charset), 'facette_number' => htmlentities($json_facette_plus['nb_result'][$j],ENT_QUOTES,$charset), 'facette_id' => $facette_id, 'facette_value' => htmlentities($facette_value,ENT_QUOTES,$charset), 'facette_link' => static::get_link_not_clicked($json_facette_plus['name'], $json_facette_plus['value'][$j], $json_facette_plus['code_champ'], $json_facette_plus['code_ss_champ'], $facette_id, $json_facette_plus['nb_result'][$j]) ); } } return encoding_normalize::json_encode($arrayRetour); } public static function destroy_dom_node() { if($_SESSION["cms_build_activate"]) { return ""; } else { return " "; } } public static function get_nb_facettes() { $query = "SELECT count(id_facette) FROM ".static::$table_name." WHERE facette_visible_gestion=1"; $result = pmb_mysql_query($query); return pmb_mysql_result($result, 0); } public static function call_ajax_facettes() { global $base_path; $ajax_facettes = ""; if(static::get_nb_facettes()) { $ajax_facettes .= static::get_facette_wrapper(); $ajax_facettes .="
"; } return $ajax_facettes; } public static function make_facette($objects_ids){ $return = ""; $class_name = static::class; $facettes = new $class_name($objects_ids); if($facettes->exists_with_results) { $return .= static::get_facette_wrapper(); $return .= $facettes->create_ajax_table_facettes(); } else { $return .= self::destroy_dom_node(); } return $return; } public static function make_ajax_facette($objects_ids){ $class_name = static::class; $facettes = new $class_name($objects_ids); return array( 'exists_with_results' => (isset($_SESSION["cms_build_activate"]) && $_SESSION["cms_build_activate"] ? true : $facettes->exists_with_results), 'display' => $facettes->create_ajax_table_facettes() ); } public static function get_facette_wrapper(){ global $base_path; $script =" "; return $script; } public static function checked_facette_search(){ global $param_delete_facette; $session_values = static::get_session_values(); if (!is_array($session_values)){ $session_values = array(); } //Suppression facette if($param_delete_facette!=""){ //On évite le rafraichissement de la page static::delete_session_value($param_delete_facette); } else { $tmpArray = array(); $check_facette = static::get_checked(); foreach ($check_facette as $k=>$v) { $ajout=true; if (count($tmpArray)) { foreach ($tmpArray as $k2=>$v2) { if (($v2[2]==$v[2]) && ($v2[3]==$v[3])) { $tmpArray[$k2][1][] = $v[1]; $ajout=false; break; } } } if ($ajout) { $tmpItem = array(); $tmpItem[0] = $v[0]; $tmpItem[1] = array($v[1]); $tmpItem[2] = $v[2]; $tmpItem[3] = $v[3]; $tmpArray[] = $tmpItem; } } //ajout facette : on vérifie qu'elle n'est pas déjà en session (rafraichissement page) $trouve = false; if (count($session_values)) { foreach ($session_values as $k=>$v) { if ($tmpArray == $v) { $trouve = true; break; } } } if (!$trouve) { $session_values[] = $tmpArray; } static::set_session_values($session_values); } static::make_facette_search_env(); } public static function get_nb_result_groupby($facettes){ $nb_result=0; foreach($facettes as $facette){ $nb_result+=$facette['nb_result']; } return $nb_result; } public function get_clicked() { if(!isset($this->clicked)) { $session_values = static::get_session_values(); if(is_array($session_values)) { $this->clicked = $session_values; } else { $this->clicked = array(); } } return $this->clicked; } public function get_not_clicked() { $this->not_clicked = array(); $this->facette_plus = array(); foreach ($this->tab_facettes as $keyFacette=>$vTabFacette) { $affiche = true; foreach ($vTabFacette['value'] as $keyValue=>$vLibelle) { $clicked = false; foreach ($this->get_clicked() as $vSessionFacette) { foreach ($vSessionFacette as $vDetail) { if (($vDetail[2]==$vTabFacette['code_champ']) && ($vDetail[3]==$vTabFacette['code_ss_champ']) && (in_array($vLibelle,$vDetail[1]))) { $clicked = true; break; } } } if (!$clicked) { $key = $vTabFacette['name']."_".$this->facettes[$keyFacette]['id']; if ($vTabFacette['size_to_display'] == '-1') { $this->not_clicked[$key][]=array('see_more' => true); $affiche = false; } elseif ($vTabFacette['size_to_display']!='0') { if (isset($this->not_clicked[$key]) && count($this->not_clicked[$key])>=$vTabFacette['size_to_display']) { $this->not_clicked[$key][]=array('see_more' => true); $affiche = false; } } if ($affiche) { $this->not_clicked[$key][]=array( 'libelle' => $vLibelle, 'code_champ' => $vTabFacette['code_champ'], 'code_ss_champ' => $vTabFacette['code_ss_champ'], 'nb_result' => $vTabFacette['nb_result'][$keyValue] ); } else { $this->facette_plus[$this->facettes[$keyFacette]['id']]['facette'][]=$vLibelle." "."(".$vTabFacette['nb_result'][$keyValue].")"; $this->facette_plus[$this->facettes[$keyFacette]['id']]['value'][]=$vLibelle; $this->facette_plus[$this->facettes[$keyFacette]['id']]['nb_result'][]=$vTabFacette['nb_result'][$keyValue]; $this->facette_plus[$this->facettes[$keyFacette]['id']]['code_champ']=$vTabFacette['code_champ']; $this->facette_plus[$this->facettes[$keyFacette]['id']]['code_ss_champ']=$vTabFacette['code_ss_champ']; $this->facette_plus[$this->facettes[$keyFacette]['id']]['name']=$vTabFacette['name']; if(static::get_compare_notice_active()){ $id=facette_search_compare::gen_compare_id($vTabFacette['name'],$vLibelle,$vTabFacette['code_champ'],$vTabFacette['code_ss_champ'],$vTabFacette['nb_result'][$keyValue]); $facette_compare=$this->get_facette_search_compare(); if(isset($facette_compare->facette_compare[$id]) && $facette_compare->facette_compare[$id]){ $facette_compare->set_available_compare($id,true); } } } } } } return $this->not_clicked; } public function get_facette_plus() { return $this->facette_plus; } protected function get_display_clicked() { global $msg; $display_clicked = ""; $n = 0; foreach ($this->clicked as $k=>$v) { ($n % 2)?$pair_impair="odd":$pair_impair="even"; $n++; $display_clicked .= " "; } $display_clicked .= "
"; $tmp=0; foreach($v as $vDetail){ foreach($vDetail[1] as $vDetailLib){ if($tmp){ $display_clicked .= "
"; } $display_clicked .= $vDetail[0]." : ".static::get_formatted_value($vDetail[2], $vDetail[3], $vDetailLib); $tmp++; } } $display_clicked .= "
"; return $display_clicked; } protected function get_display_not_clicked() { global $charset; global $msg; $display_not_clicked = ''; if(is_array($this->not_clicked) && count($this->not_clicked)) { if(static::get_compare_notice_active()){ $facette_compare=$this->get_facette_search_compare(); } foreach ($this->not_clicked as $tmpName=>$facette) { $flagSeeMore = false; $tmpArray = explode("_",$tmpName); $idfacette = array_pop($tmpArray); $name = get_msg_to_display(implode("_",$tmpArray)); $currentFacette=current($facette); $idGroupBy=facette_search_compare::gen_groupby_id($name,$currentFacette['code_champ'],$currentFacette['code_ss_champ']); $groupBy=facette_search_compare::gen_groupby($name,$currentFacette['code_champ'],$currentFacette['code_ss_champ'],$idGroupBy); $display_not_clicked .= ""; $display_not_clicked .= ""; $display_not_clicked .= ""; if(static::get_compare_notice_active() && count($facette_compare->facette_compare)){ $display_not_clicked .= " "; $display_not_clicked.=facette_search_compare::get_groupby_row($facette_compare,$groupBy,$idGroupBy); if($facette_compare->facette_groupby[$idGroupBy]){ $facette_compare->set_available_groupby($idGroupBy,true); } }else{ $display_not_clicked .= " "; } $display_not_clicked .= ""; $display_not_clicked .= ""; $display_not_clicked .= ""; $j=0; foreach ($facette as $detailFacette) { if (!isset($detailFacette['see_more'])) { $id=facette_search_compare::gen_compare_id($name,$detailFacette['libelle'],$detailFacette['code_champ'],$detailFacette['code_ss_champ'],$detailFacette['nb_result']); $cacValue = encoding_normalize::json_encode(array($name,$detailFacette['libelle'],$detailFacette['code_champ'],$detailFacette['code_ss_champ'],$id,$detailFacette['nb_result'])); if(static::get_compare_notice_active()){ if (!isset($facette_compare->facette_compare[$id]) || empty($facette_compare->facette_compare[$id])) { $onclick='select_compare_facette(\''.htmlentities($cacValue,ENT_QUOTES,$charset).'\')'; $img='double_section_arrow_16.png'; }else{ $facette_compare->set_available_compare($id,true); $onclick=''; $img='vide.png'; } } $facette_libelle = static::get_formatted_value($detailFacette['code_champ'], $detailFacette['code_ss_champ'], $detailFacette['libelle']); if($facette_libelle) { $link = static::get_link_not_clicked($name, $detailFacette['libelle'], $detailFacette['code_champ'], $detailFacette['code_ss_champ'], $id, $detailFacette['nb_result']); $display_not_clicked .= " "; $j++; } } elseif(!$flagSeeMore) { $display_not_clicked .= " "; $flagSeeMore = true; } } $display_not_clicked .= ""; $display_not_clicked .="
".htmlentities($name,ENT_QUOTES,$charset)." ".htmlentities($name,ENT_QUOTES,$charset)."
".htmlentities($facette_libelle,ENT_QUOTES,$charset)." [".htmlentities($detailFacette['nb_result'],ENT_QUOTES,$charset)."]
".$msg["facette_plus_link"]."
"; } $display_not_clicked .= ""; $display_not_clicked .= ""; if(static::get_compare_notice_active()){ $display_not_clicked .= ""; } } return $display_not_clicked; } public function create_ajax_table_facettes(){ global $base_path; global $charset; global $mode; global $msg; if(static::get_compare_notice_active()){ $facette_compare=$this->get_facette_search_compare(); } $table = "
"; if(count($this->get_clicked())){ $table .= "

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

".$this->get_display_clicked()."
"; } if(static::get_compare_notice_active()){ //Le tableau des critères de comparaisons if(count($facette_compare->facette_compare)){ $table_compare=$facette_compare->gen_table_compare(); $table .= "

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

".$table_compare."

"; //Le tableau des critères de comparaisons if(count($facette_compare->facette_groupby)){ $table_groupby=$facette_compare->gen_table_groupby(); } $table .= "

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

".$table_groupby."

"; } //le bouton de retour if(isset($_SESSION['filtre_compare']) && $_SESSION['filtre_compare']=='compare'){ $table .= "

"; }elseif((!isset($_SESSION['filtre_compare']) || $_SESSION['filtre_compare']!='compare') && count($facette_compare->facette_compare)){ $table .= "

"; } } if(count($this->get_not_clicked())){ if(static::get_compare_notice_active()){ $table .= "
"; $table .= "

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

".$this->get_display_not_clicked()."
"; }else{ $table .= "

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

".$this->get_display_not_clicked()."
"; } } $table .= "
"; return $table; } public static function session_filtre_compare(){ global $filtre_compare; $_SESSION['filtre_compare']=$filtre_compare; } public static function get_checked() { global $charset; global $name; global $value; global $champ; global $ss_champ; global $check_facette; //si rien en multi-sélection, il n'y a qu'une seule facette de cliquée //on l'ajoute au tableau pour avoir un traitement unique après if(!isset($check_facette) || !count($check_facette)){ $check_facette = array(); $check_facette[] = array(stripslashes($name),stripslashes($value),$champ,$ss_champ); }else{ //le tableau est addslashé automatiquement foreach($check_facette as $k=>$v){ $check_facette[$k]=json_decode(stripslashes($v)); //json_encode/decode ne fonctionne qu'avec des données utf-8 if ($charset!='utf-8') { foreach($check_facette[$k] as $key=>$value){ $check_facette[$k][$key]=utf8_decode($check_facette[$k][$key]); } } } } return $check_facette; } public function get_facette_search_compare() { if(!isset($this->facette_search_compare)) { $this->facette_search_compare = new facette_search_compare(); } return $this->facette_search_compare; } public function get_json_datas() { $datas = array( 'clicked' => $this->get_clicked(), 'not_clicked' => $this->get_not_clicked(), 'facette_plus' => $this->get_facette_plus() ); return encoding_normalize::json_encode($datas); } public static function get_compare_notice_active() { if(!isset(static::$compare_notice_active)) { global $opac_compare_notice_active; static::$compare_notice_active = $opac_compare_notice_active*1; } return static::$compare_notice_active; } public static function set_url_base($url_base) { static::$url_base = $url_base; } public static function format_url($url) { global $base_path; if(!isset(static::$url_base)) { static::$url_base = $base_path.'/index.php?'; } if(strpos(static::$url_base, "lvl=search_segment")) { return static::$url_base.str_replace('lvl', '&action', $url); } else { return static::$url_base.$url; } } /** * Liste des facettes (tableau ordonné) * * @return array */ public static function get_list($type='notices') { $q = "select * from ".static::$table_name." where facette_type='".addslashes($type)."' order by facette_name"; $r = pmb_mysql_query($q); if(0 === pmb_mysql_num_rows($r)) { return []; } $list = []; while( $row=pmb_mysql_fetch_assoc($r) ) { $list[$row['id_facette']] = $row; } return $list; } }// end class