added settings for advanced search vocabulary choice and hidden terms

This commit is contained in:
Bachir Soussi Chiadmi 2017-10-31 12:47:28 +01:00
parent e9146c29ce
commit 1e1a762b9b
2 changed files with 348 additions and 267 deletions

View File

@ -12,6 +12,10 @@ function materio_search_api_settings(){
$languages = locale_language_list();
// dsm($languages, 'languages');
$form = array();
// Solr indexes by language
foreach ($languages as $lcode => $name) {
$form['fulltextsearchindex_'.$lcode] = array(
'#type'=>'select',
@ -44,6 +48,7 @@ function materio_search_api_settings(){
}
// view modes
// TODO: select the activated viewmodes for change view mode and selected view mode
$entity_infos = entity_get_info();
// dsm($entity_infos, 'entity_infos');
@ -66,7 +71,7 @@ function materio_search_api_settings(){
'#title' => t('Defalut View mode'),
);
// limits by view mode
foreach (variable_get('availableviewmodes', array()) as $viewmode => $value) {
$form[$viewmode.'_limite'] = array(
'#type'=>'textfield',
@ -76,5 +81,74 @@ function materio_search_api_settings(){
);
}
// advanced search vocabulary
$vocs = taxonomy_get_vocabularies();
// dsm($vocs, 'vocs');
$vocs_options = array();
foreach ($vocs as $vid => $voc) {
$vocs_options[$vid] = $voc->name;
}
$form['msa-advancedsearchvocabulary'] = array(
'#type' => 'select',
'#options' => $vocs_options,
'#default' => variable_get('msa-advancedsearchvocabulary', null),
'#title' => t('advanced search vocabulary'),
'#description' => 'Choose which vocabulary will be used for advanced search form',
);
// advanced search hide some taxonomy terms
if($vid = variable_get('msa-advancedsearchvocabulary', null)){
$tree = msa_taxonomy_get_nested_tree(taxonomy_get_tree($vid));
// dsm($tree, "tree");
$tree_options = array();
msa_get_nested_tree_options($tree, $tree_options);
// dsm($tree_options, 'tree_options');
$form['msa-hiddentaxoterms'] = array(
'#type' => 'select',
'#options' => $tree_options,
'#default_value' => variable_get('msa-hiddentaxoterms', array()),
'#multiple' => TRUE,
'#title' => t('Hidden taxonomy terms'),
'#description' => t('Select terms which will be hidden from advanced search form')
);
}
return system_settings_form($form);
}
function msa_taxonomy_get_nested_tree($terms = array(), $max_depth = NULL, $parent = 0, $parents_index = array(), $depth = 0) {
if (is_int($terms)) {
$terms = taxonomy_get_tree($terms);
}
foreach($terms as $term) {
foreach($term->parents as $term_parent) {
if ($term_parent == $parent) {
$return[$term->tid] = $term;
}
else {
$parents_index[$term_parent][$term->tid] = $term;
}
}
}
foreach($return as &$term) {
if (isset($parents_index[$term->tid]) && (is_null($max_depth) || $depth < $max_depth)) {
$term->children = msa_taxonomy_get_nested_tree($parents_index[$term->tid], $max_depth, $term->tid, $parents_index, $depth + 1);
}
}
return $return;
}
function msa_get_nested_tree_options($tree, &$options, $prefix = ""){
foreach ($tree as $tid => $term) {
$options[$tid] = $prefix . $term->name;
if(isset($term->children)){
msa_get_nested_tree_options($term->children, $options, $prefix."$term->name - ");
}
}
}

View File

@ -751,11 +751,16 @@ function materio_search_api_advanced_search_form($form, &$form_state){
// $form = array();
// TODO: get vid from settings
$vid = 15; // onthologie
$vid = variable_get('msa-advancedsearchvocabulary', null);
if($vid){
$voc = taxonomy_vocabulary_load($vid);
$voc_machinename = $voc->machine_name;
// dsm($voc, "voc");
$hidden_terms = variable_get('msa-hiddentaxoterms', array());
// dsm($hidden_terms, 'hidden_terms');
$values = isset($form_state['values']) ? $form_state['values'] : null;
// dsm($values, "values");
@ -841,8 +846,10 @@ function materio_search_api_advanced_search_form($form, &$form_state){
$taxotree = taxonomy_get_tree($vid, 0, 1, false);
foreach ($taxotree as $index => $term) {
// TODO: get translated tag name
if(!in_array($term->tid, $hidden_terms)){
$level_0_ops[$term->tid] = t($term->name);
}
}
// build filters lines (ajax enabled)
for ($l=0; $l < $form_state['filterlines']; $l++) {
@ -1036,6 +1043,11 @@ function materio_search_api_advanced_search_form($form, &$form_state){
'#return_value' => "search",
);
}else{
$form['novoc'] = array(
'#markup' => "Please choose a vocabulary to search from in materio search api settings"
);
}
// dsm($form, 'form');
return $form;
}
@ -1391,11 +1403,6 @@ function template_preprocess_materio_search_api_actuality(&$vars){
// $vars['actualities_infos'] = t('Actualities by materiO\'');
$vars['actualities_infos'] = t('');
}
//
// function template_preprocess_materio_search_api_advanced_search_block(&$vars){
// // dsm($vars, "vars");
// $vars['searchform'] = drupal_get_form("materio_search_api_advanced_search_form");
// }
function theme_materio_search_api_form_element($variables) {
// dsm($variables, 'variables');