id=$id+0;
$this->fetch_data();
}
function fetch_data() {
global $msg,$dbh,$charset;
$this->facettes=array();
$req="select bannette_facettes.*,bannettes.display_notice_in_every_group,bannettes.document_group from bannette_facettes
JOIN bannettes ON id_bannette=num_ban_facette
where num_ban_facette=". $this->id." order by ban_facette_order";
$res = pmb_mysql_query($req,$dbh);
$i=0;
if (pmb_mysql_num_rows($res)) {
while($r=pmb_mysql_fetch_object($res)){
$this->facettes[$i] = new stdClass();
$this->facettes[$i]->critere=$r->ban_facette_critere;
$this->facettes[$i]->ss_critere= $r->ban_facette_ss_critere;
$this->facettes[$i]->order_sort= $r->ban_facette_order;
if(!$this->bannette_display_notice_in_every_group){
$this->bannette_display_notice_in_every_group=$r->display_notice_in_every_group;
}
if(!$this->bannette_document_group){
$this->bannette_document_group=$r->document_group;
}
$i++;
}
}
}
function build_notice($notice_id){
global $deflt2docs_location,$url_base_opac;
global $use_opac_url_base; $use_opac_url_base=1;
global $use_dsi_diff_mode; $use_dsi_diff_mode=1;
global $opac_notice_affichage_class;
if($this->noti_tpl_document) {
$tpl_document=$this->noti_tpl_document->build_notice($notice_id,$deflt2docs_location);
}
if(!$tpl_document) {
if (!$opac_notice_affichage_class) $opac_notice_affichage_class="notice_affichage";
$current = new $opac_notice_affichage_class($notice_id);
$current->do_isbd();
$tpl_document.=$current->notice_isbd;
}
return $tpl_document."\r\n";
}
function filter_facettes_search($facettes_list,$notice_ids){
global $dbh;
global $lang;
global $msg;
global $dsi_bannette_notices_order ;
$notices=implode(",",$notice_ids);
$res_notice_ids=array();
$res_notice_ids["values"]=array();
$res_notice_ids["notfound"]=array();
$critere= $facettes_list[0]->critere;
$ss_critere= $facettes_list[0]->ss_critere;
if ($dsi_bannette_notices_order) {
$req = "SELECT * FROM notices_fields_global_index LEFT JOIN notices on (id_notice=notice_id)
WHERE id_notice IN (".$notices.")
AND code_champ = ".$critere." AND code_ss_champ = ".$ss_critere." AND lang in ('','".$lang."') order by value,".$dsi_bannette_notices_order;
} else {
$req = "SELECT * FROM notices_fields_global_index
WHERE id_notice IN (".$notices.")
AND code_champ = ".$critere." AND code_ss_champ = ".$ss_critere." AND lang in ('','".$lang."') order by value ";
}
// print $req."
";
$res = pmb_mysql_query($req,$dbh);
if (pmb_mysql_num_rows($res)) {
while($r=pmb_mysql_fetch_object($res)){
$res_notice_ids["folder"][$r->value]["values"][]= $r->id_notice;
$res_notice_ids["memo"][]= $r->id_notice;
}
foreach($notice_ids as $id_notice ){
if(!in_array($id_notice,$res_notice_ids["memo"])) $res_notice_ids["notfound"][]=$id_notice;
}
// Si encore une facette d'affinage, on fait du récursif
if(count($facettes_list)>1){
array_splice($facettes_list, 0,1);
foreach($res_notice_ids["folder"] as $folder => $contens){
//printr($contens["values"]);
$res_notice_ids["folder"][$folder]= $this->filter_facettes_search($facettes_list, $contens["values"]);
//printr($res_notice_ids["folder"][$folder]);
$res_notice_ids["folder"][$folder]["notfound_cumul"]=array();
foreach($res_notice_ids["folder"][$folder]["values"] as $value){
if(is_array($value["notfound"]))
$res_notice_ids["folder"][$folder]["notfound_cumul"]=array_merge($res_notice_ids["folder"][$folder]["notfound_cumul"],$value["notfound"]);
}
}
}
}else{
$res_notice_ids["notfound"]=$notice_ids;
}
return $res_notice_ids;
}
function filter_facettes_print($res_notice_ids, $rang=1,$notfound=array(),$gen_document=0,&$already_printed=array()){
global $dbh, $msg, $charset;
global $lang;
if(count($res_notice_ids["notfound"])){
$tpl.="
";
foreach($res_notice_ids["notfound"] as $notice_id){
if( !in_array($notice_id, $notfound) )
$tpl.="".$this->build_notice($notice_id)."
" ;
$notfound[]=$notice_id;
}
$tpl.="
";
}
if(is_array($res_notice_ids["folder"])){
foreach($res_notice_ids["folder"] as $folder => $contens){
if((!$gen_document && $this->bannette_display_notice_in_every_group) || ($gen_document && $this->bannette_display_notice_in_every_group && $this->bannette_document_group)){
//on vide $already_printed pour afficher systèmatiquement la notice dans chaque groupe
$already_printed=array();
}
if(!sizeof($already_printed) || sizeof(array_diff($contens["values"],$already_printed))){
if($this->gen_summary && $rang==1){
$this->index++;
$this->summary.="".htmlentities($this->index." - ".$folder,ENT_QUOTES,$charset)."
";
if(!$gen_document || ($gen_document && $this->bannette_document_group)){
$tpl.="".htmlentities($folder,ENT_QUOTES,$charset)."";
}
}else{
if(!$gen_document || ($gen_document && $this->bannette_document_group)){
$tpl.="".htmlentities($folder,ENT_QUOTES,$charset)."";
}
}
$tpl.="
";
foreach($contens["values"] as $notice_id){
if(!in_array($notice_id,$already_printed)){
$tpl.=$this->build_notice($notice_id)."
" ;
if($gen_document && !$this->bannette_document_group){
$tpl.="
\r\n";
}
$already_printed[]=$notice_id;
}
}
if(count($contens["notfound"])){
foreach($contens["notfound"] as $notice_id){
if( !in_array($notice_id, $notfound) )
$tpl.=$this->build_notice($notice_id)."
" ;
$notfound[]=$notice_id;
}
}
$tpl.="";
//printr($contens["folder"]);
if(count($contens["folder"])){
$rang++;
// c'est une arborescence. Construction du titre
$tpl.=$this->filter_facettes_print($contens,$rang,$notfound,$gen_document,$already_printed);
$rang--;
}
}elseif(count($contens["folder"])){
foreach($contens['folder'] as $folder2=>$values2){
if(!sizeof($already_printed) || sizeof(array_diff($values2["values"],$already_printed))){
if($this->gen_summary && $rang==1){
$this->index++;
$this->summary.="".htmlentities($this->index." - ".$folder,ENT_QUOTES,$charset)."
";
if(!$gen_document || ($gen_document && $this->bannette_document_group)){
$tpl.="".htmlentities($folder,ENT_QUOTES,$charset)."";
}
}else{
if(!$gen_document || ($gen_document && $this->bannette_document_group)){
$tpl.="".htmlentities($folder,ENT_QUOTES,$charset)."";
}
}
break;
}
}
$rang++;
// c'est une arborescence. Construction du titre
$tpl.=$this->filter_facettes_print($contens,$rang,$notfound,$gen_document,$already_printed);
$rang--;
}
}
}
return $tpl;
}
function build_document_data($notice_ids,$notice_tpl=""){
$this->sommaires=array();
if($notice_tpl){
$this->noti_tpl_document=new notice_tpl_gen($notice_tpl);
} else $this->noti_tpl_document="";
// paramétrage :
$this->environement["short"] = 6 ;
$this->environement["ex"] = 0 ;
$this->environement["exnum"] = 1 ;
$facettes_list=$this->facettes;
$this->index=0;
$res_notice_ids=$this->filter_facettes_search($facettes_list,$notice_ids);
$resultat_aff=$this->filter_facettes_data($res_notice_ids,1,array());
return $this->sommaires;
}
function filter_facettes_data($res_notice_ids, $rang=1,$notfound=array(),$gen_document=0,&$already_printed=array()){
global $dbh, $msg, $charset;
global $lang;
if(count($res_notice_ids["notfound"])){
$this->sommaires[$this->index]['level']=$rang;
foreach($res_notice_ids["notfound"] as $notice_id){
if( !in_array($notice_id, $notfound) )
$this->sommaires[$this->index]['records'][]['render']=$charset!= "utf-8" ? utf8_encode($this->build_notice($notice_id)) : $this->build_notice($notice_id);
$notfound[]=$notice_id;
}
}
if(is_array($res_notice_ids["folder"])){
foreach($res_notice_ids["folder"] as $folder => $contens){
if((!$gen_document && $this->bannette_display_notice_in_every_group) || ($gen_document && $this->bannette_display_notice_in_every_group && $this->bannette_document_group)){
//on vide $already_printed pour afficher systèmatiquement la notice dans chaque groupe
$already_printed=array();
}
if(!sizeof($already_printed) || sizeof(array_diff($contens["values"],$already_printed))){
$this->index++;
$this->sommaires[$this->index]['title']=$charset!= "utf-8" ? utf8_encode($folder) : $folder;
$this->sommaires[$this->index]['level']=$rang;
foreach($contens["values"] as $notice_id){
if(!in_array($notice_id,$already_printed)){
$this->sommaires[$this->index]['records'][]['render']=$charset!= "utf-8" ? utf8_encode($this->build_notice($notice_id)) : $this->build_notice($notice_id);
$already_printed[]=$notice_id;
}
}
if(count($contens["notfound"])){
foreach($contens["notfound"] as $notice_id){
if( !in_array($notice_id, $notfound) )
$this->sommaires[$this->index]['records'][]['render']=$charset!= "utf-8" ? utf8_encode($this->build_notice($notice_id)) : $this->build_notice($notice_id);
$notfound[]=$notice_id;
}
}
//printr($contens["folder"]);
if(count($contens["folder"])){
$rang++;
// c'est une arborescence. Construction du titre
$this->filter_facettes_data($contens,$rang,$notfound,$gen_document,$already_printed);
$rang--;
}
}elseif(count($contens["folder"])){
foreach($contens['folder'] as $folder2=>$values2){
if(!sizeof($already_printed) || sizeof(array_diff($values2["values"],$already_printed))){
$this->index++;
$this->sommaires[$this->index]['title']=$charset!= "utf-8" ? utf8_encode($folder) : $folder;
$this->sommaires[$this->index]['level']=$rang;
break;
}
}
$rang++;
// c'est une arborescence. Construction du titre
$this->filter_facettes_data($contens,$rang,$notfound,$gen_document,$already_printed);
$rang--;
}
}
}
return 0;
}
}// end class