";
$i++;
}
$search_segment_sort_form = str_replace('!!segment_sort_select_fields!!', $select_fields, $search_segment_sort_form);
$search_segment_sort_form = str_replace('!!segment_sort_fields_javascript!!', $this->get_sort_fields_javascript(), $search_segment_sort_form);
return $search_segment_sort_form;
}
public function set_properties_from_form(){
$this->get_sort_fields();
$this->sort = encoding_normalize::json_encode($this->sort_fields->format_fields());
$this->human_query = $this->get_human_query();
}
public function get_sort_from_form() {
global $segment_sort_name, $segment_sort_direction, $segment_sort_fields;
$sort = '';
for ($i = 0; $i < count($segment_sort_name); $i++) {
if ($segment_sort_name[$i] === "segment_sort_name_default") {
continue;
}
if (!empty($segment_sort_name[$i])) {
if (!empty($sort)) {
$sort .= ' || ';
}
$sort .= $segment_sort_direction[$i] . '_' . $segment_sort_fields[$i] . ' | ' . $segment_sort_name[$i];
}
}
// Si on a pas de tri renseigne on enregistre un tri par default
// Si tous les champs on ete vide du coup on applique un tri par defaut decroissant sur la pert
// On test quel type on a car la pert n'est pas defini pareil dans le xml
if (empty($sort)) {
if (TYPE_NOTICE == $this->type) {
$sort = 'd_num_6 | segment_sort_name_default';
} elseif (TYPE_EXTERNAL == $this->type){
$sort = '';
} else {
$sort = 'd_num_1 | segment_sort_name_default';
}
}
return $sort;
}
public function update() {
if (!$this->num_segment ) {
return false;
}
$query = '
UPDATE search_segments
SET search_segment_sort = "'.addslashes($this->sort).'"
WHERE id_search_segment = "'.$this->num_segment.'"';
return pmb_mysql_query($query);
}
public function delete_sort(){
$this->sort = "";
$this->human_query = "";
}
private function get_sort_fields() {
if (!isset($this->sort_fields)) {
$this->sort_fields = new sort_fields($this->get_indexation_type(), $this->get_indexation_path());
}
return $this->sort_fields;
}
private function get_indexation_path() {
global $include_path;
$string_type = entities::get_string_from_const_type($this->type);
switch ($string_type) {
case 'ontology' :
break;
case 'notices' :
return $include_path."/indexation/notices/champs_base.xml";
default :
return $include_path."/indexation/authorities/$string_type/champs_base.xml";
}
}
private function get_indexation_type() {
switch ($this->type) {
case TYPE_NOTICE :
return "notices";
default :
return "authorities";
}
}
private function get_sub_type() {
return entities::get_aut_table_from_type($this->type);
}
public function sort_data($data, $offset = 0, $limit = 0, $query_searcher) {
$query = $this->appliquer_tri($this->num_segment,$query_searcher,$this->params['REFERENCEKEY'],$offset,$limit);
$res = pmb_mysql_query($query);
if($res && pmb_mysql_num_rows($res)){
$this->result=array();
while($row = pmb_mysql_fetch_object($res)){
$this->result[] = $row->{ $this->params["REFERENCEKEY"] };
}
}
return $this->result;
}
public function add_session_currentSegment($id){
$_SESSION['sort_segment_'.$this->num_segment.'currentSort'] = $id;
return true;
}
public function show_tris_selector_segment() {
global $search_index, $msg;
if (!empty($_SESSION['sort_segment_'.$this->num_segment.'currentSort'])){
$sort_seg = $_SESSION['sort_segment_'.$this->num_segment.'currentSort'];
} else {
$sort_seg = 0;
}
$sorts = array();
$sorts = explode('||',$this->sort);
$html = '
";
return $html;
}
/**
* Ajoute les tris par défaut éventuellement saisis en paramètre
*/
public function add_default_sort(){
if ($this->sort) {
if (empty($_SESSION['sort_segment_'.$this->num_segment.'_list']) || $_SESSION['sort_segment_'.$this->num_segment.'_list'] != $this->sort) {
$_SESSION['sort_segment_'.$this->num_segment.'_list'] = $this->sort;
$_SESSION['sort_segment_'.$this->num_segment.'flag'] = 0;
}
//on vérifie l'existence d'un flag : que la recherche par défaut ne revienne pas si l'utilisateur l'a supprimée par le formulaire
if(empty($_SESSION['sort_segment_'.$this->num_segment.'flag'])){
$tmpArray = explode("||",$this->sort);
foreach($tmpArray as $tmpElement){
if(trim($tmpElement)){
if (strstr($tmpElement,'|')) {
$tmpSort=explode("|",$tmpElement);
$this->add_session_sort($tmpSort[0],$tmpSort[1]);
} else {
$this->add_session_sort($tmpElement);
}
}
}
$_SESSION['sort_segment_'.$this->num_segment.'flag']=1;
}
}
}
private function add_session_sort($sortDes, $sortName =''){
global $charset;
$_SESSION["sort_segment_".$this->num_segment][]= [
"name" => htmlentities($sortName,ENT_QUOTES,$charset),
"des" => htmlentities($sortDes,ENT_QUOTES,$charset)
];
}
public function get_select_fields_sort($sort, $i) {
global $msg, $charset;
$sort_principal_fields = '';
$sort_pperso = '';
$field_id = 0;
if (isset(explode('_', $sort)[2])) {
$field_id = clean_string(explode('_', $sort)[2]);
}
$type = $this->type;
if ($this->type > 1000) {
$type = TYPE_AUTHPERSO;
}
$this->get_principal_fields(entities::get_string_from_const_type($type));
if (!empty($this->principal_fields)) {
$sort_principal_fields .= "";
}
$this->get_pperso_fields(parametres_perso::get_pperso_prefix_from_type($type));
if (!empty($this->pperso_fields->t_fields)) {
$options = '';
foreach ($this->pperso_fields->t_fields as $id => $field) {
if (!empty($field['OPAC_SORT'])) {
$selected = ("cp$id" == $field_id ? 'selected' : '');
$value = $field['OPTIONS'][0]['FOR'] . "_cp$id";
if ($field['OPTIONS'][0]['FOR'] == 'date_box') {
$value = "date_cp$id";
}
$options .= "";
}
}
if (!empty($options)) {
$sort_pperso .= "";
}
}
return "";
}
public function get_select_direction_sort($sort, $i) {
global $msg;
$direction_sort = clean_string(explode('_', $sort)[0]);
return "";
}
public function get_principal_fields($type) {
global $include_path;
if (isset($this->principal_fields)) {
return;
}
$nomfichier = "$include_path/sort/$type/sort.xml";
if (file_exists("$include_path/sort/$type/sort_subst.xml")) {
$nomfichier = "$include_path/sort/$type/sort_subst.xml";
$fp = fopen($nomfichier, "r");
} elseif (file_exists($nomfichier)) {
$fp = fopen($nomfichier, "r");
}
if ($fp) {
$xml = fread($fp, filesize($nomfichier));
fclose($fp);
$params = _parser_text_no_function_($xml, "SORT", $nomfichier);
$this->principal_fields = $params;
}
return $this->principal_fields;
}
public function get_pperso_fields($type) {
if (!isset($this->pperso_fields)) {
$this->pperso_fields = new parametres_perso($type);
}
return $this->pperso_fields;
}
public function get_sort_fields_javascript() {
return "
";
}
private function get_segment_sort_default() {
global $msg;
// On test quel type on a car la pert n'est pas defini pareil dans le xml
// Par defaut on met une pert DESC
$sort = 'd_num_1';
$message = $msg['segment_sort_label_default'];
if (TYPE_NOTICE == $this->type) {
$sort = 'd_num_6';
}
if (TYPE_EXTERNAL == $this->type){
$sort = '';
$message = $msg['segment_sort_label_no_default'];
}
return "