object_index_key = "id_authority"; $this->object_words_table = "authorities_words_global_index"; $this->object_fields_table = "authorities_fields_global_index"; $this->object_key = 'id_authority'; if ($this->authority_type) { $this->field_restrict[]= array( 'field' => "type", 'values' => array($this->authority_type), 'op' => "and", 'not' => false ); } } public function _get_search_type(){ return "authorites"; } protected function get_full_results_query(){ if ($this->object_table) { return 'select id_authority from authorities join '.$this->object_table.' on authorities.num_object = '.$this->object_table_key; } return 'select id_authority from authorities'; } protected function _get_authorities_filters(){ global $authority_statut, $no_display; $filters = array(); if ($this->authority_type) { $filters[] = 'authorities.type_object = '.$this->authority_type; } if ($authority_statut) { $filters[] = 'authorities.num_statut = "'.$authority_statut.'"'; } if ($no_display) { $filters[] = 'authorities.num_object != "'.$no_display.'"'; } return $filters; } protected function _get_search_query(){ $query = parent::_get_search_query(); if($this->authority_type && $this->object_table) { $filters = $this->_get_authorities_filters(); $filters[] = 'id_authority in ('.$query.')'; if ($this->user_query != "*") { $query = 'select id_authority from authorities join '.$this->object_table.' on authorities.num_object = '.$this->object_table_key; } if (count($filters)) { $query .= ' where '.implode(' and ', $filters); } }else if(get_class($this) == get_class()) { if($this->user_query != "*"){ // Si cette classe est appelée directement, on cherche dans toutes les autorités donc on va chercher les concepts $searcher_authorities_concepts = new searcher_authorities_concepts($this->user_query); $query = 'select id_authority from (('.$query.') union ('.$searcher_authorities_concepts->get_raw_query().')) as search_query_concepts'; } $filters = $this->_get_authorities_filters(); $filters[] = 'id_authority in ('.$query.')'; if (count($filters)) { $query = 'select id_authority from authorities where '.implode(' and ', $filters); } } return $query; } protected function _get_sign_elements($sorted=false) { global $authority_statut; $str_to_hash = parent::_get_sign_elements($sorted); $str_to_hash .= "&authority_statut=".$authority_statut; return $str_to_hash; } // à réécrire au besoin... protected function _sort($start,$number){ global $dbh; global $last_param, $tri_param, $limit_param; if($this->table_tempo != ""){ $query = "select * from ".$this->table_tempo." order by pert desc limit ".$start.",".$number; $res = pmb_mysql_query($query,$dbh); if($res && pmb_mysql_num_rows($res)){ $this->result=array(); while($row = pmb_mysql_fetch_object($res)){ $this->result[] = $row->{$this->object_key}; } } } else { if ($last_param) { $query = $this->_get_search_query().' '.$tri_param.' '.$limit_param; } else { $query = $this->_get_search_query().' '.$this->get_authority_tri().' limit '.$start.', '.$number; } $res = pmb_mysql_query($query,$dbh); if($res && pmb_mysql_num_rows($res)){ $this->result=array(); while($row = pmb_mysql_fetch_object($res)){ $this->result[] = $row->id_authority; } } } } public function get_authority_tri() { // à surcharger si besoin return ''; } protected function _sort_result($start,$number){ if ($this->user_query != '*') { $this->_get_pert(); } $this->_sort($start,$number); } public function get_raw_query() { $this->_analyse(); return $this->_get_search_query(); } public function get_pert_result($query = false) { $pert = ''; if ($this->get_result() && ($this->user_query != '*')) { $pert = $this->_get_pert($query); } if ($query) { return $pert; } return $this->table_tempo; } protected function _get_pert($return_query = false) { $query = parent::_get_pert(true); if (get_class($this) == get_class()) { // Si cette classe est appelée directement, on cherche dans toutes les autorités donc on va chercher les concepts $searcher_authorities_concepts = new searcher_authorities_concepts($this->user_query); $concepts_pert_result = $searcher_authorities_concepts->get_pert_result(true); if ($concepts_pert_result) { $query = 'select '.$this->object_key.', sum(pert) as pert from (('.$query.') union all ('.$concepts_pert_result.')) as search_query_concepts group by '.$this->object_key; } } if ($return_query) { return $query; } $this->table_tempo = 'search_result'.md5(microtime(true)); $rqt = 'create temporary table '.$this->table_tempo.' '.$query; $res = pmb_mysql_query($rqt,$dbh); pmb_mysql_query('alter table '.$this->table_tempo.' add index i_id('.$this->object_key.')',$dbh); } public function get_results_list_from_search($label, $user_input, $list, $navbar) { $template = "

".$this->get_nb_results()." ".$label." ".$user_input."

".$list."
".$navbar."
"; return $template; } public static function has_authorities_sources($authority_type) { $authorities_sources = false; $query = "SELECT id_authority_source FROM authorities_sources WHERE authority_type='".$authority_type."' AND TRIM(authority_number) !='' LIMIT 1"; $result = pmb_mysql_query($query); if($result && pmb_mysql_num_rows($result)){ $authorities_sources = true; } return $authorities_sources; } public static function get_display_authorities_sources($num_authority, $authority_type) { global $charset; $display = ''; $query = "SELECT authority_number,origin_authorities_name, origin_authorities_country FROM authorities_sources JOIN origin_authorities ON num_origin_authority=id_origin_authorities WHERE authority_type='".$authority_type."' AND num_authority='".$num_authority."' AND TRIM(authority_number) !='' GROUP BY authority_number,origin_authorities_name,origin_authorities_country ORDER BY authority_favorite DESC, origin_authorities_name"; $result = pmb_mysql_query($query); if($result && pmb_mysql_num_rows($result)){ $first=true; while ($row = pmb_mysql_fetch_object($result)) { if(!$first)$display .=", "; $display .=htmlentities($row->authority_number,ENT_QUOTES,$charset); if($tmp=trim($row->origin_authorities_name)){ $display .=htmlentities(" (".$row->origin_authorities_name.")",ENT_QUOTES,$charset); } $first=false; } } return $display; } }