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[] = $this->object_key.' 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;
$order = "";
$limit = ' LIMIT '.$start.','.$number;
if($this->table_tempo != ""){
$authority_tri = $this->get_authority_tri();
$join = '';
if($this->authority_type && $this->object_table && $authority_tri) {
$join = ' join authorities on '.$this->table_tempo.'.'.$this->object_key.' = authorities.id_authority
join '.$this->object_table.' on authorities.num_object = '.$this->object_table_key.' and authorities.type_object = '.$this->authority_type;
}
$query = 'select * from '.$this->table_tempo.$join;
$order = ' order by pert desc'.($authority_tri ? ', '.$authority_tri : '').', '.$this->table_tempo.'.'.$this->object_key.' asc';
} else {
if (!empty($last_param)) {
$query = $this->_get_search_query();
$order = ' '.$tri_param;
$limit = ' '.$limit_param;
} else {
$query = $this->_get_search_query().$this->get_authority_join();
$authority_tri = $this->get_authority_tri();
$order = ($authority_tri ? ' ORDER BY '.$authority_tri : '');
}
}
if ($this->filtered_result) {
$query .= " AND authorities.id_authority IN ($this->objects_ids)";
}
$res = pmb_mysql_query($query.$order.$limit);
if(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
if (!empty($this->table_tempo)) {
return ' '.$this->table_tempo.'.id_authority desc ';
}
return ' id_authority desc ';
}
protected function _sort_result($start,$number){
if ($this->user_query != '*' && $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;
}
if(!$query) return; // Pas de résultat en recherche
$this->table_tempo = 'search_result'.md5(microtime(true));
$rqt = 'create temporary table '.$this->table_tempo.' '.$query;
$res = pmb_mysql_query($rqt);
pmb_mysql_query('alter table '.$this->table_tempo.' add index i_id('.$this->object_key.')');
}
public function get_results_list_from_search($label, $user_input, $list, $navbar) {
$template = "