objects_ids = $objects_ids; $this->facette_existing(); $this->nb_results_by_facette(); } protected function get_query() { $query = "SELECT * FROM ".static::$table_name." WHERE facette_visible=1"; if (!empty(static::$facet_type)) { $query .= " AND facette_type = '".static::$facet_type."'"; } $query .= " ORDER BY facette_order, facette_name"; return $query; } protected function facette_existing(){ global $opac_view_filter_class; $this->facettes = array(); $query = $this->get_query(); $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, 'type'=> $row->facette_type, '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'], $facette['type']); 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=1"; if (!empty(static::$facet_type)) { $query .= " AND facette_type = '".static::$facet_type."'"; } $result = pmb_mysql_query($query); return pmb_mysql_result($result, 0); } protected static function get_ajax_url() { global $base_path; return $base_path."/ajax.php?module=ajax&categ=".static::$table_name."&sub=get_data&facet_type=".static::$facet_type; } public static function call_ajax_facettes($additional_content = "") { $ajax_facettes = $additional_content; if(static::get_nb_facettes()) { $ajax_facettes .= static::get_facette_wrapper(); $ajax_facettes .="
"; } return $ajax_facettes; } public static function make_facette($objects_ids) { global $opac_facettes_ajax, $opac_map_activate; $return = ""; $class_name = static::class; $facettes = new $class_name($objects_ids); if (!$opac_facettes_ajax && ($opac_map_activate == 1 || $opac_map_activate == 3)) { $return .= ""; } if ($facettes->exists_with_results || count($facettes->get_clicked())) { $return .= static::get_facette_wrapper(); $return .= $facettes->create_ajax_table_facettes(); } else { $return .= self::destroy_dom_node(); } return $return; } public function get_expls_location($notices_ids) { global $opac_show_exemplaires; if(!$notices_ids) { return array(); } if($opac_show_exemplaires){ $query = "SELECT DISTINCT id_location, id_notice from ( " . $this->get_query_expl($notices_ids) . " UNION " . $this->get_query_explnum($notices_ids) . " ) as sub"; } else { $query = $this->get_query_explnum($notices_ids); } $expls_location = array( 'ids' => array(), 'notices_number' => array() ); $result = pmb_mysql_query($query); if ($result && pmb_mysql_num_rows($result)) { while ($row = pmb_mysql_fetch_object($result)) { $expls_location['ids'][] = $row->id_location; if(!isset($expls_location['notices_number'][$row->id_location])) { $expls_location['notices_number'][$row->id_location] = 0; } $expls_location['notices_number'][$row->id_location] ++; } $expls_location['ids'] = array_unique($expls_location['ids']); } return $expls_location; } public function get_map_location() { global $opac_url_base,$opac_map_activate; global $opac_sur_location_activate; global $msg; if(!$opac_map_activate || $opac_map_activate==2 || !strlen($_SESSION["tab_result"])) { return ''; } $expls_location = $this->get_expls_location($_SESSION["tab_result"]); if (count($expls_location['ids']) > 1) { $surlocations_ids = array(); $query = "SELECT DISTINCT idlocation, location_libelle, surloc_num, surloc_libelle FROM docs_location LEFT JOIN sur_location on surloc_id=surloc_num WHERE idlocation IN ( \"" . implode('","',$expls_location['ids']) . "\")"; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { $tab_locations = array(); $tab_surlocations = array(); $location_ids = array(); $i = 0; while ($row = pmb_mysql_fetch_object($result)) { $location_ids[] = $row->idlocation; $tab_locations[$i]["id"] = $row->idlocation; $tab_locations[$i]['libelle'] = $row->location_libelle; $tab_locations[$i]['name'] = $msg['extexpl_location']; $tab_locations[$i]['notices_number'] = $expls_location['notices_number'][$row->idlocation]; $tab_locations[$i]['surloc_num'] = $row->surloc_num; $tab_locations[$i]['code_champ'] = 90; $tab_locations[$i]['code_ss_champ'] = 4; $tab_locations[$i]['url'] = static::format_url('lvl=more_results&mode=extended&facette_test=1'); $tab_locations[$i]['param'] = '&check_facette[]=["' . $tab_locations[$i]['name'] . '","' . $tab_locations[$i]['libelle'] . '",90,4,"",0]'; $i++; if($row->surloc_num && !array_key_exists($row->surloc_num,$tab_surlocations) && $opac_sur_location_activate) { $surlocations_ids[] = $row->surloc_num; $tab_surlocations[$row->surloc_num]["id"] = $row->surloc_num; $tab_surlocations[$row->surloc_num]['libelle'] = $row->surloc_libelle; $tab_surlocations[$row->surloc_num]['name'] = $msg['extexpl_surlocation']; $tab_surlocations[$row->surloc_num]['code_champ'] = 90; $tab_surlocations[$row->surloc_num]['code_ss_champ'] = 9; $tab_surlocations[$row->surloc_num]['url'] = static::format_url('lvl=more_results&mode=extended&facette_test=1'); $tab_surlocations[$row->surloc_num]['param'] = '&check_facette[]=["' . $tab_surlocations[$row->surloc_num]['name'] . '","' . $tab_surlocations[$row->surloc_num]['libelle'] . '",90,9,"",0]'; } if($row->surloc_num && $opac_sur_location_activate) { if (!isset($tab_surlocations[$row->surloc_num]['notices_number'])) $tab_surlocations[$row->surloc_num]['notices_number'] = 0; $tab_surlocations[$row->surloc_num]['notices_number'] += $expls_location['notices_number'][$row->idlocation]; } } if (count($surlocations_ids) <= 1) { return map_facette_controler::get_map_facette_location($location_ids,$tab_locations, array(),array()); } else { $tab_locations_without_surloc = array(); $ids_loc_without_surloc = array(); foreach ($tab_locations as $location) { if (!$location['surloc_num']) { $ids_loc_without_surloc[] = $location["id"]; $tab_locations_without_surloc[] = $location; } } return map_facette_controler::get_map_facette_location($ids_loc_without_surloc,$tab_locations_without_surloc, $surlocations_ids, $tab_surlocations); } } } else { return ''; } } public static function make_ajax_facette($objects_ids){ $class_name = static::class; $facettes = new $class_name($objects_ids); $facettes_exists_with_or_without_results = false; if($facettes->exists_with_results || count($facettes->get_clicked())){ $facettes_exists_with_or_without_results = true; } return array( 'exists_with_results' => ($_SESSION["cms_build_activate"] ? true : $facettes_exists_with_or_without_results), 'display' => $facettes->create_ajax_table_facettes(), 'map_location' => $facettes->get_map_location() ); } protected static function get_ajax_see_more_url() { global $base_path; return $base_path."/ajax.php?module=ajax&categ=".static::$table_name."&sub=see_more"; } public static function get_facette_wrapper() { global $msg, $base_path; $script = " "; return $script; } public static function checked_facette_search(){ global $param_delete_facette; global $opac_facettes_operator; $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 $key => $facet_values) { $ajout=true; if (count($tmpArray)) { foreach ($tmpArray as $prev_key => $prev_values) { //On test le champ et le sous champ if (($prev_values[2] == $facet_values[2]) && ($prev_values[3] == $facet_values[3])) { $tmpArray[$prev_key][1][] = $facet_values[1]; $ajout=false; break; } } } if ($ajout) { $tmpItem = array(); $tmpItem[0] = $facet_values[0]; $tmpItem[1] = array($facet_values[1]); $tmpItem[2] = $facet_values[2]; $tmpItem[3] = $facet_values[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; } elseif($opac_facettes_operator == 'or') { if($tmpArray[0][2] == $v[0][2]) { $session_values[$k][0][1] = array_merge($tmpArray[0][1], $v[0][1]); $trouve = true; break; } } } } if (!$trouve && count($tmpArray)) { $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, $charset; $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 .= htmlentities($vDetail[0]." : ".static::get_formatted_value($vDetail[2], $vDetail[3], $vDetailLib),ENT_QUOTES,$charset); $tmp++; } } $display_clicked .= "
".$msg["facette_delete_one"]."
".$msg['reset']."
"; 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(); } $display_not_clicked .= "get_filter_button_action().">"; 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]) || !sizeof($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)."
on_facet_click($link)." style='cursor:pointer' rel='nofollow' class='facet-link'> ".htmlentities($facette_libelle,ENT_QUOTES,$charset)." [".htmlentities($detailFacette['nb_result'],ENT_QUOTES,$charset)."]
".$msg["facette_plus_link"]."
"; } $display_not_clicked .= ""; $display_not_clicked .= "get_filter_button_action().">"; if(static::get_compare_notice_active()){ $display_not_clicked .= ""; } } return $display_not_clicked; } protected function get_filter_button_action() { return "onClick='valid_facettes_multi()'"; } protected function on_facet_click($link = '') { return "onclick='".$link."'"; } 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; } protected function get_action_form() { return static::format_url("lvl=more_results&mode=".$this->mode."&facette_test=1"); } 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(); if (!empty($name) && isset($value)) { $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; } protected 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; } } public static function set_facet_type($type) { static::$facet_type = $type; } }// end class