Esempio n. 1
0
 public function maj($object_id, $object_uri = "", $datatype = "all")
 {
     if ($object_id == 0 && $object_uri != "") {
         $object_id = onto_common_uri::get_id($object_uri);
     }
     if ($object_id != 0 && !$object_uri) {
         $object_uri = onto_common_uri::get_uri($object_id);
     }
     if (!count($this->tab_code_champ)) {
         $this->init();
     }
     $tab_words_insert = $tab_fields_insert = array();
     $this->get_sparql_result($object_uri);
     $this->delete_index($object_id, $datatype);
     //on a un tableau de résultat, on peut le travailler...
     foreach ($this->tab_code_champ as $field_id => $element) {
         foreach ($element as $column => $infos) {
             if (isset($this->sparql_result[$column])) {
                 $field_order = 1;
                 foreach ($this->sparql_result[$column] as $key => $values) {
                     foreach ($values as $key2 => $value) {
                         if (is_string($value)) {
                             $language = $key;
                             //fields (contenu brut)
                             $tab_fields_insert[] = "('" . $object_id . "','" . $infos['champ'] . "','" . $infos['ss_champ'] . "','" . $field_order . "','" . addslashes($value) . "','" . $language . "','" . $infos['pond'] . "','" . $autority_num . "')";
                             //words (contenu éclaté)
                             $tab_tmp = explode(' ', strip_empty_words($value));
                             $word_position = 1;
                             foreach ($tab_tmp as $word) {
                                 $num_word = indexation::add_word($word, $language);
                                 $tab_words_insert[] = "(" . $object_id . "," . $infos["champ"] . "," . $infos["ss_champ"] . "," . $num_word . "," . $infos["pond"] . ",{$field_order},{$word_position})";
                                 $word_position++;
                             }
                         } else {
                             $language = $key2;
                             $autority_num = onto_common_uri::get_id($key);
                             foreach ($value as $val) {
                                 //fields (contenu brut)
                                 $tab_fields_insert[] = "('" . $object_id . "','" . $infos['champ'] . "','" . $infos['ss_champ'] . "','" . $field_order . "','" . addslashes($val) . "','" . $language . "','" . $infos['pond'] . "','" . $autority_num . "')";
                                 //words (contenu éclaté)
                                 $tab_tmp = explode(' ', strip_empty_words($val));
                                 $word_position = 1;
                                 foreach ($tab_tmp as $word) {
                                     $num_word = indexation::add_word($word, $language);
                                     $tab_words_insert[] = "(" . $object_id . "," . $infos["champ"] . "," . $infos["ss_champ"] . "," . $num_word . "," . $infos["pond"] . ",{$field_order},{$word_position})";
                                     $word_position++;
                                 }
                             }
                         }
                         $field_order++;
                     }
                 }
             } else {
                 continue;
             }
         }
     }
     $this->save_elements($tab_words_insert, $tab_fields_insert);
     return true;
 }
Esempio n. 2
0
 public function maj($object_id, $datatype = 'all')
 {
     global $dbh, $lang;
     // 		global $indexation_lang; spécificité des notices (langue d'indexation)
     //on s'assure qu'on a lu le XML et initialisé ce qu'il faut...
     if (!$this->initialized) {
         $this->init();
     }
     //on réinitialise les tableaux d'injection
     $tab_insert = array();
     $tab_field_insert = array();
     //on a des éléments à indexer...
     if ($this->champ_trouve) {
         //Recherche des champs directs
         if ($datatype == 'all') {
             $this->queries[0]["rqt"] = "select " . implode(',', $this->temp_not['f'][0]) . " from " . $this->reference_table;
             $this->queries[0]["rqt"] .= " where " . $this->reference_key . "='" . $object_id . "'";
             $this->queries[0]["table"] = $this->reference_table;
         }
         //qu'est-ce qu'on efface?
         if ($datatype == 'all') {
             $req_del = "delete from " . $this->table_prefix . "_words_global_index where " . $this->reference_key . "='" . $object_id . "' ";
             pmb_mysql_query($req_del, $dbh);
             //la table pour les recherche exacte
             $req_del = "delete from " . $this->table_prefix . "_fields_global_index where " . $this->reference_key . "='" . $object_id . "' ";
             pmb_mysql_query($req_del, $dbh);
             //Les champs perso
             if (count($this->tab_pp)) {
                 foreach ($this->tab_pp as $id) {
                     $req_del = "delete from " . $this->table_prefix . "_words_global_index where " . $this->reference_key . "='" . $object_id . "' and code_champ=100 and code_ss_champ='" . $id . "' ";
                     pmb_mysql_query($req_del, $dbh);
                     //la table pour les recherche exacte
                     $req_del = "delete from " . $this->table_prefix . "_fields_global_index where " . $this->reference_key . "='" . $object_id . "' and code_champ=100 and code_ss_champ='" . $id . "' ";
                     pmb_mysql_query($req_del, $dbh);
                 }
             }
         } else {
             foreach ($this->datatypes as $xml_datatype => $codes) {
                 if ($xml_datatype == $datatype) {
                     foreach ($codes as $code_champ) {
                         foreach ($subfields as $subfield) {
                             $req_del = "delete from " . $this->table_prefix . "_words_global_index where " . $this->reference_key . "='" . $object_id . "' and code_champ='" . $code_champ . "'";
                             pmb_mysql_query($req_del, $dbh);
                             //la table pour les recherche exacte
                             $req_del = "delete from " . $this->table_prefix . "_fields_global_index where " . $this->reference_key . "='" . $object_id . "' and code_champ='" . $code_champ . "'";
                             pmb_mysql_query($req_del, $dbh);
                             break;
                         }
                     }
                 }
             }
         }
         //qu'est-ce qu'on met a jour ?
         $tab_insert = array();
         $tab_field_insert = array();
         foreach ($this->datatypes as $xml_datatype => $code_champ) {
             if ($datatype == "all" || $xml_datatype == $datatype) {
             }
         }
         foreach ($this->queries as $k => $v) {
             if ($datatype == 'all' || in_array($k, $this->datatypes[$datatype])) {
                 $v['rqt'] = str_replace("!!object_id!!", $object_id, $v['rqt']);
                 $r = pmb_mysql_query($v["rqt"], $dbh) or die("Requete echouee.");
                 $tab_mots = array();
                 $tab_fields = array();
                 if (pmb_mysql_num_rows($r)) {
                     while ($tab_row = pmb_mysql_fetch_array($r, MYSQL_ASSOC)) {
                         $langage = "";
                         if (isset($tab_row[$this->tab_languages[$k]])) {
                             $langage = $tab_row[$this->tab_languages[$k]];
                             unset($tab_row[$this->tab_languages[$k]]);
                         }
                         foreach ($tab_row as $nom_champ => $liste_mots) {
                             if (substr($nom_champ, 0, 10) == 'subst_for_') {
                                 continue;
                             }
                             if ($this->tab_code_champ[$k][$nom_champ]['internal']) {
                                 $langage = $indexation_lang;
                             }
                             if ($this->tab_code_champ[$k][$nom_champ]['marctype']) {
                                 //on veut toutes les langues, pas seulement celle de l'interface...
                                 $saved_lang = $lang;
                                 $code = $liste_mots;
                                 $dir = opendir($include_path . "/marc_tables");
                                 while ($dir_lang = readdir($dir)) {
                                     if ($dir_lang != "." && $dir_lang != ".." && $dir_lang != "CVS" && $dir_lang != ".svn" && is_dir($include_path . "/marc_tables/" . $dir_lang)) {
                                         $lang = $dir_lang;
                                         $marclist = new marc_list($this->tab_code_champ[$k][$nom_champ]['marctype']);
                                         $liste_mots = $marclist->table[$code];
                                         $tab_fields[$nom_champ][] = array('value' => trim($liste_mots), 'lang' => $lang, 'autorite' => $tab_row["subst_for_marc_" . $this->tab_code_champ[$k][$nom_champ]['marctype']]);
                                     }
                                 }
                                 $lang = $saved_lang;
                                 $liste_mots = "";
                             }
                             if ($liste_mots != '') {
                                 $liste_mots = strip_tags($liste_mots);
                                 $tab_tmp = array();
                                 if (!in_array($k, $this->tab_keep_empty)) {
                                     $tab_tmp = explode(' ', strip_empty_words($liste_mots));
                                 } else {
                                     $tab_tmp = explode(' ', strip_empty_chars(clean_string($liste_mots)));
                                 }
                                 //	if($lang!="") $tab_tmp[]=$lang;
                                 //la table pour les recherche exacte
                                 if (!$tab_fields[$nom_champ]) {
                                     $tab_fields[$nom_champ] = array();
                                 }
                                 $tab_fields[$nom_champ][] = array('value' => trim($liste_mots), 'lang' => $langage, 'autorite' => $tab_row["subst_for_autorite_" . $this->tab_code_champ[$k][$nom_champ]['autorite']]);
                                 if (!$this->tab_code_champ[$k][$nom_champ]['no_words']) {
                                     foreach ($tab_tmp as $mot) {
                                         if (trim($mot)) {
                                             $tab_mots[$nom_champ][$mot] = $langage;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 foreach ($tab_mots as $nom_champ => $tab) {
                     $memo_ss_champ = "";
                     $order_fields = 1;
                     $pos = 1;
                     foreach ($tab as $mot => $langage) {
                         $num_word = indexation::add_word($mot, $langage);
                         if ($num_word != 0) {
                             $tab_insert[] = "(" . $object_id . "," . $this->tab_code_champ[$k][$nom_champ]['champ'] . "," . $this->tab_code_champ[$k][$nom_champ]['ss_champ'] . "," . $num_word . "," . $this->tab_code_champ[$k][$nom_champ]['pond'] . ",{$order_fields},{$pos})";
                             $pos++;
                             if ($this->tab_code_champ[$k][$nom_champ]['ss_champ'] != $memo_ss_champ) {
                                 $order_fields++;
                             }
                             $memo_ss_champ = $this->tab_code_champ[$k][$nom_champ]['ss_champ'];
                         }
                     }
                 }
                 //la table pour les recherche exacte
                 foreach ($tab_fields as $nom_champ => $tab) {
                     foreach ($tab as $order => $values) {
                         $tab_field_insert[] = "(" . $object_id . "," . $this->tab_code_champ[$k][$nom_champ]['champ'] . "," . $this->tab_code_champ[$k][$nom_champ]['ss_champ'] . "," . ($order + 1) . ",'" . addslashes($values['value']) . "','" . addslashes($values['lang']) . "'," . $this->tab_code_champ[$k][$nom_champ]['pond'] . ",'" . addslashes($values['autorite']) . "')";
                     }
                 }
             }
             // 			//Les champs perso
             // 			if(count($this->tab_pp)){
             // 				foreach ( $this->tab_pp as $code_champ => $table ) {
             // 					$p_perso=new parametres_perso($table);
             // 					//on doit retrouver l'id des eléments...
             // 					switch($table){
             // 						case "expl" :
             // 							$rqt = "select expl_id from notices join exemplaires on expl_notice = notice_id and expl_notice!=0 where notice_id = $notice union select expl_id from notices join bulletins on num_notice = notice_id join exemplaires on expl_bulletin = bulletin_id and expl_bulletin != 0 where notice_id = $notice";
             // 							$res = pmb_mysql_query($rqt);
             // 							if(pmb_mysql_num_rows($res)) {
             // 								$ids = array();
             // 								while($row= pmb_mysql_fetch_object($res)){
             // 									$ids[] =$row->expl_id;
             // 								}
             // 							}
             // 							break;
             // 						case "collstate" :
             // 							break;
             // 						default :
             // 							$ids = array($notice);
             // 					}
             // 					if(count($ids)){
             // 						for($i=0 ; $i<count($ids) ; $i++) {
             // 							$data=$p_perso->get_fields_recherche_mot_array($ids[$i]);
             // 							$j=0;
             // 							$order_fields=1;
             // 							foreach ( $data as $code_ss_champ => $value ) {
             // 								$tab_mots=array();
             // 								foreach($value as $val) {
             // 									$tab_tmp=explode(' ',strip_empty_words($val));
             // 									//la table pour les recherche exacte
             // 									$tab_field_insert[]="(".$notice.",".$code_champ.",".$code_ss_champ.",".$j.",'".addslashes(trim($val))."','',".$p_perso->get_pond($code_ss_champ).",0)";
             // 									$j++;
             // 									foreach($tab_tmp as $mot) {
             // 										if(trim($mot)){
             // 											$tab_mots[$mot]= "";
             // 										}
             // 									}
             // 								}
             // 								$pos=1;
             // 								foreach ( $tab_mots as $mot => $langage ) {
             // 									//on cherche le mot dans la table de mot...
             // 									$query = "select id_word from words where word = '".$mot."' and lang = '".$langage."'";
             // 									$result = pmb_mysql_query($query);
             // 									if(pmb_mysql_num_rows($result)){
             // 										$num_word = pmb_mysql_result($result,0,0);
             // 									}else{
             // 										$dmeta = new DoubleMetaPhone($mot);
             // 										$stemming = new stemming($mot);
             // 										$element_to_update = "";
             // 										if($dmeta->primary || $dmeta->secondary){
             // 											$element_to_update.="
             // 												double_metaphone = '".$dmeta->primary." ".$dmeta->secondary."'";
             // 										}
             // 										if($element_to_update) $element_to_update.=",";
             // 										$element_to_update.="stem = '".$stemming->stem."'";
             // 										$query = "insert into words set word = '".$mot."', lang = '".$langage."'".($element_to_update ? ", ".$element_to_update : "");
             // 										pmb_mysql_query($query);
             // 										$num_word = pmb_mysql_insert_id();
             // 									}
             // 									$tab_insert[]="(".$notice.",".$code_champ.",".$code_ss_champ.",".$num_word.",".$p_perso->get_pond($code_ss_champ).",$order_fields,$pos)";
             // 									$pos++;
             // 								}
             // 								$order_fields++;
             // 							}
             // 						}
             // 					}
             // 				}
             // 			}
         }
         if (count($this->isbd_ask_list)) {
             // Les isbd d'autorités
             foreach ($this->isbd_ask_list as $k => $infos) {
                 $isbd_s = array();
                 // cumul des isbd
                 if ($datatype == "all" || in_array($k, $this->datatypes[$datatype])) {
                     $query = str_replace("!!object_id!!", $object_id, $infos["req"]);
                     $res = pmb_mysql_query($query) or die($query);
                     if (pmb_mysql_num_rows($res)) {
                         switch ($infos["class_name"]) {
                             case 'author':
                                 while ($row = pmb_mysql_fetch_object($res)) {
                                     $aut = new auteur($row->id_aut_for_isbd);
                                     $isbd_s[] = $aut->isbd_entry;
                                 }
                                 break;
                             case 'editeur':
                                 while ($row = pmb_mysql_fetch_object($res)) {
                                     $aut = new editeur($row->id_aut_for_isbd);
                                     $isbd_s[] = $aut->isbd_entry;
                                 }
                                 break;
                             case 'indexint':
                                 while ($row = pmb_mysql_fetch_object($res)) {
                                     $aut = new indexint($row->id_aut_for_isbd);
                                     $isbd_s[] = $aut->display;
                                 }
                                 break;
                             case 'collection':
                                 while ($row = pmb_mysql_fetch_object($res)) {
                                     $aut = new collection($row->id_aut_for_isbd);
                                     $isbd_s[] = $aut->isbd_entry;
                                 }
                                 break;
                             case 'subcollection':
                                 while ($row = pmb_mysql_fetch_object($res)) {
                                     $aut = new subcollection($row->id_aut_for_isbd);
                                     $isbd_s[] = $aut->isbd_entry;
                                 }
                                 break;
                             case 'serie':
                                 while ($row = pmb_mysql_fetch_object($res)) {
                                     $aut = new serie($row->id_aut_for_isbd);
                                     $isbd_s[] = $aut->name;
                                 }
                                 break;
                             case 'categories':
                                 while ($row = pmb_mysql_fetch_object($res)) {
                                     $aut = new categories($row->id_aut_for_isbd, $lang);
                                     $isbd_s[] = $aut->libelle_categorie;
                                 }
                                 break;
                             case 'titre_uniforme':
                                 while ($row = pmb_mysql_fetch_object($res)) {
                                     $aut = new titre_uniforme($row->id_aut_for_isbd);
                                     $isbd_s[] = $aut->libelle;
                                 }
                                 break;
                         }
                     }
                 }
                 $order_fields = 1;
                 for ($i = 0; $i < count($isbd_s); $i++) {
                     $tab_mots = array();
                     $tab_field_insert[] = "(" . $object_id . "," . $infos["champ"] . "," . $infos["ss_champ"] . "," . $order_fields . ",'" . addslashes(trim($isbd_s[$i])) . "',''," . $infos["pond"] . ",0)";
                     $tab_tmp = explode(' ', strip_empty_words($isbd_s[$i]));
                     foreach ($tab_tmp as $mot) {
                         if (trim($mot)) {
                             $tab_mots[$mot] = "";
                         }
                     }
                     $pos = 1;
                     foreach ($tab_mots as $mot => $langage) {
                         $num_word = indexation::add_word($mot, $langage);
                         $tab_insert[] = "(" . $object_id . "," . $infos["champ"] . "," . $infos["ss_champ"] . "," . $num_word . "," . $infos["pond"] . ",{$order_fields},{$pos})";
                         $pos++;
                     }
                     $order_fields++;
                 }
             }
         }
         $this->save_elements($tab_insert, $tab_field_insert);
     }
 }