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();
if ($query){
$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 $last_param, $tri_param, $limit_param;
global $pmb_nb_max_tri;
$sort_index = "";
$entity_type = $this->get_sort_entity_type();
if (!empty($entity_type)) {
$sort_index = "tri_".$entity_type;
}
$apply_sort = false;
if (!empty($sort_index) && !empty($_SESSION[$sort_index])) {
// On vérifie si on peut appliquer le tri selon le paramètre $pmb_nb_max_tri
$apply_sort = false;
$query = "SELECT COUNT(id_authority) as nb_results FROM authorities WHERE id_authority in (".$this->_get_search_query().")";
if ($this->table_tempo != "") {
$query = "SELECT count(id_authority) as nb_results FROM " . $this->table_tempo;
}
$res = pmb_mysql_query($query);
if(pmb_mysql_num_rows($res)){
$row = pmb_mysql_fetch_object($res);
}
if ($row->nb_results <= $pmb_nb_max_tri) {
$apply_sort = true;
if (!empty($entity_type)) {
$sort = new sort($entity_type, 'base');
}
}
}
if($this->table_tempo != ""){
if ($apply_sort) {
$query = $sort->appliquer_tri($_SESSION[$sort_index], "SELECT * FROM " . $this->table_tempo, 'id_authority', $start, $number);
} else {
$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 by pert desc'.($authority_tri ? ', '.$authority_tri : '').', '.$this->table_tempo.'.'.$this->object_key.' asc limit '.$start.','.$number;
}
} else {
if ($apply_sort) {
$query = $sort->appliquer_tri($_SESSION[$sort_index], $this->_get_search_query(), 'id_authority', $start, $number);
} else {
if ($last_param) {
$query = $this->_get_search_query().' '.$tri_param.' '.$limit_param;
} else {
$authority_tri = $this->get_authority_tri();
$query = $this->_get_search_query().($authority_tri ? ' order by '.$authority_tri : '').' limit '.$start.', '.$number;
}
}
}
if (!empty($query)) {
$res = pmb_mysql_query($query);
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
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()) {
$pert = $this->_get_pert($query);
}else{
$this->table_tempo = $this->get_temporary_table_name();
$pert = $this->get_full_query();
pmb_mysql_query("create temporary table {$this->table_tempo} {$pert}");
}
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) {
return "