added settings for advanced search vocabulary choice and hidden terms
This commit is contained in:
parent
e9146c29ce
commit
1e1a762b9b
@ -12,6 +12,10 @@ function materio_search_api_settings(){
|
|||||||
$languages = locale_language_list();
|
$languages = locale_language_list();
|
||||||
// dsm($languages, 'languages');
|
// dsm($languages, 'languages');
|
||||||
|
|
||||||
|
$form = array();
|
||||||
|
|
||||||
|
|
||||||
|
// Solr indexes by language
|
||||||
foreach ($languages as $lcode => $name) {
|
foreach ($languages as $lcode => $name) {
|
||||||
$form['fulltextsearchindex_'.$lcode] = array(
|
$form['fulltextsearchindex_'.$lcode] = array(
|
||||||
'#type'=>'select',
|
'#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
|
// TODO: select the activated viewmodes for change view mode and selected view mode
|
||||||
$entity_infos = entity_get_info();
|
$entity_infos = entity_get_info();
|
||||||
// dsm($entity_infos, 'entity_infos');
|
// dsm($entity_infos, 'entity_infos');
|
||||||
@ -66,7 +71,7 @@ function materio_search_api_settings(){
|
|||||||
'#title' => t('Defalut View mode'),
|
'#title' => t('Defalut View mode'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// limits by view mode
|
||||||
foreach (variable_get('availableviewmodes', array()) as $viewmode => $value) {
|
foreach (variable_get('availableviewmodes', array()) as $viewmode => $value) {
|
||||||
$form[$viewmode.'_limite'] = array(
|
$form[$viewmode.'_limite'] = array(
|
||||||
'#type'=>'textfield',
|
'#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);
|
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 - ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -751,291 +751,303 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|||||||
// $form = array();
|
// $form = array();
|
||||||
|
|
||||||
// TODO: get vid from settings
|
// TODO: get vid from settings
|
||||||
$vid = 15; // onthologie
|
$vid = variable_get('msa-advancedsearchvocabulary', null);
|
||||||
$voc = taxonomy_vocabulary_load($vid);
|
if($vid){
|
||||||
$voc_machinename = $voc->machine_name;
|
|
||||||
// dsm($voc, "voc");
|
|
||||||
|
|
||||||
$values = isset($form_state['values']) ? $form_state['values'] : null;
|
$voc = taxonomy_vocabulary_load($vid);
|
||||||
// dsm($values, "values");
|
$voc_machinename = $voc->machine_name;
|
||||||
|
// dsm($voc, "voc");
|
||||||
|
|
||||||
$args = arg();
|
$hidden_terms = variable_get('msa-hiddentaxoterms', array());
|
||||||
// dsm($args, 'args');
|
// dsm($hidden_terms, 'hidden_terms');
|
||||||
|
|
||||||
// get the first elemt of url args
|
$values = isset($form_state['values']) ? $form_state['values'] : null;
|
||||||
$path = array_shift($args);
|
// dsm($values, "values");
|
||||||
if (isset($args[0]) && $args[0] == "filters") {
|
|
||||||
$path .= '/'.array_shift($args);
|
$args = arg();
|
||||||
}
|
// dsm($args, 'args');
|
||||||
// get the keywords from args and reconstruct the filter lines with default values
|
|
||||||
$args_values = array();
|
// get the first elemt of url args
|
||||||
if($path == 'explore/filters' && $args[0] !== "ajax"){
|
$path = array_shift($args);
|
||||||
$keywords = explode("+", $args[0]);
|
if (isset($args[0]) && $args[0] == "filters") {
|
||||||
// TODO: what if a keyword contains a +
|
$path .= '/'.array_shift($args);
|
||||||
// dsm($keywords, 'keywords');
|
}
|
||||||
foreach ($keywords as $key => $value) {
|
// get the keywords from args and reconstruct the filter lines with default values
|
||||||
$name = str_replace('"', '', $value);
|
$args_values = array();
|
||||||
//Get the term
|
if($path == 'explore/filters' && $args[0] !== "ajax"){
|
||||||
$terms = taxonomy_get_term_by_name($name, $voc_machinename);
|
$keywords = explode("+", $args[0]);
|
||||||
$term = array_shift($terms);
|
// TODO: what if a keyword contains a +
|
||||||
// dsm($term, $term->tid.' : '.$term->name);
|
// dsm($keywords, 'keywords');
|
||||||
// get parents
|
foreach ($keywords as $key => $value) {
|
||||||
if(isset($term->tid)){
|
$name = str_replace('"', '', $value);
|
||||||
$parents = taxonomy_get_parents_all($term->tid);
|
//Get the term
|
||||||
// dsm($parents, 'parents');
|
$terms = taxonomy_get_term_by_name($name, $voc_machinename);
|
||||||
// build default values
|
$term = array_shift($terms);
|
||||||
for ($p=count($parents)-1; $p >=0 ; $p--) {
|
// dsm($term, $term->tid.' : '.$term->name);
|
||||||
$args_values[$key][] = $parents[$p]->tid;
|
// get parents
|
||||||
|
if(isset($term->tid)){
|
||||||
|
$parents = taxonomy_get_parents_all($term->tid);
|
||||||
|
// dsm($parents, 'parents');
|
||||||
|
// build default values
|
||||||
|
for ($p=count($parents)-1; $p >=0 ; $p--) {
|
||||||
|
$args_values[$key][] = $parents[$p]->tid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// dsm($args_values, 'args_values');
|
||||||
// dsm($args_values, 'args_values');
|
// TODO: show result count live
|
||||||
// TODO: show result count live
|
// TODO: filter next select form item
|
||||||
// TODO: filter next select form item
|
|
||||||
|
|
||||||
// define number of lines,
|
// define number of lines,
|
||||||
// 1 by default
|
// 1 by default
|
||||||
// or from url arguments
|
// or from url arguments
|
||||||
// or let it as it is if already chanched by ajax
|
// or let it as it is if already chanched by ajax
|
||||||
if(!isset($form_state['filterlines'])){
|
if(!isset($form_state['filterlines'])){
|
||||||
if(count($args_values)){
|
if(count($args_values)){
|
||||||
$form_state['filterlines'] = count($args_values);
|
$form_state['filterlines'] = count($args_values);
|
||||||
}else{
|
}else{
|
||||||
$form_state['filterlines'] = 1;
|
$form_state['filterlines'] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// dsm($form_state['filterlines'], "form_state['filterlines']");
|
||||||
// dsm($form_state['filterlines'], "form_state['filterlines']");
|
|
||||||
|
|
||||||
// filters form container
|
// filters form container
|
||||||
$form['filters'] = array(
|
$form['filters'] = array(
|
||||||
'#type' => 'container',
|
|
||||||
'#prefix' => '<div id="advancedsearch-filters">',
|
|
||||||
'#suffix' => '</div>',
|
|
||||||
);
|
|
||||||
|
|
||||||
$trigger = FALSE;
|
|
||||||
if (!empty($form_state['triggering_element']['#name'])) {
|
|
||||||
$trigger = $form_state['triggering_element'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$rmline = false;
|
|
||||||
if ($trigger) {
|
|
||||||
// dsm($form_state['triggering_element'], $form_state['triggering_element']['#name']);
|
|
||||||
// dsm($values, 'form state values');
|
|
||||||
|
|
||||||
// add a line if needed
|
|
||||||
if($trigger['#name'] == 'addfilters'){
|
|
||||||
$form_state['filterlines'] = $form_state['filterlines']+1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove a line if needed
|
|
||||||
if(strpos($trigger['#name'], 'rm-filter-') === 0){
|
|
||||||
// $form_state['filterlines'] = $form_state['filterlines']+1;
|
|
||||||
$rmline = $trigger['#return_value'];
|
|
||||||
// dsm($rmline, "rmline");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// build first level taxonomy tree and select options
|
|
||||||
$taxotree = taxonomy_get_tree($vid, 0, 1, false);
|
|
||||||
foreach ($taxotree as $index => $term) {
|
|
||||||
// TODO: get translated tag name
|
|
||||||
$level_0_ops[$term->tid] = t($term->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// build filters lines (ajax enabled)
|
|
||||||
for ($l=0; $l < $form_state['filterlines']; $l++) {
|
|
||||||
|
|
||||||
// if rmline this line,
|
|
||||||
// continue the loop without creating the line
|
|
||||||
if($l === $rmline){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// if we are after the removed line,
|
|
||||||
// create a second counter ($ll) to keep a continuous order for form items
|
|
||||||
// and keep the current counter ($l) to retrieve de current values
|
|
||||||
// if before removed line or no removed line at all, $l = $ll
|
|
||||||
if($rmline !== false && $l >= $rmline){
|
|
||||||
$ll = $l-1;
|
|
||||||
}else{
|
|
||||||
$ll = $l;
|
|
||||||
}
|
|
||||||
// dsm("l : ".$l." | ll : ".$ll);
|
|
||||||
|
|
||||||
$form['filters']['filterline-'.$ll] = array(
|
|
||||||
'#type' => 'container',
|
'#type' => 'container',
|
||||||
'#attributes' => array(
|
'#prefix' => '<div id="advancedsearch-filters">',
|
||||||
'class' => array("filter-line")
|
'#suffix' => '</div>',
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// get the default value
|
$trigger = FALSE;
|
||||||
// from from_state values if ajax
|
if (!empty($form_state['triggering_element']['#name'])) {
|
||||||
// or from url args
|
$trigger = $form_state['triggering_element'];
|
||||||
// or 0
|
|
||||||
$default0 = null;
|
|
||||||
if(isset($values['filter-'.$l.'-0']) && $values['filter-'.$l.'-0']){
|
|
||||||
$default0 = $values['filter-'.$l.'-0'];
|
|
||||||
}elseif(isset($args_values[$l][0])){
|
|
||||||
$default0 = $args_values[$l][0];
|
|
||||||
}
|
|
||||||
// dsm($default0, "default 0");
|
|
||||||
|
|
||||||
// form select element for first level
|
|
||||||
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-0'] = array(
|
|
||||||
'#type' => 'select',
|
|
||||||
'#options' => $level_0_ops,
|
|
||||||
'#name' => 'filter-'.$ll.'-0',
|
|
||||||
'#empty_option' => t("Choose a filter"),
|
|
||||||
// '#empty_values' => 0,
|
|
||||||
'#default_value' => $default0,
|
|
||||||
'#ajax' => array(
|
|
||||||
'callback' => 'materio_search_api_advanced_search_select_callback',
|
|
||||||
'wrapper' => 'advancedsearch-filters',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// without this line, form api will mess with default values
|
|
||||||
$form_state["input"]['filter-'.$ll.'-0'] = $default0;
|
|
||||||
|
|
||||||
// add level 1 filter if level 0 chosen
|
|
||||||
if($default0){
|
|
||||||
|
|
||||||
// build second level taxonomy tree and select options
|
|
||||||
$taxotree1 = taxonomy_get_tree($vid, $default0, 1, false);
|
|
||||||
$level_1_ops = array();
|
|
||||||
foreach ($taxotree1 as $index => $term) {
|
|
||||||
// TODO: get translated tag name
|
|
||||||
$level_1_ops[$term->tid] = t($term->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the default value
|
|
||||||
// from from_state values if ajax
|
|
||||||
// or from url args
|
|
||||||
// or 0
|
|
||||||
$default1 = null;
|
|
||||||
if(isset($values['filter-'.$l.'-1']) && $values['filter-'.$l.'-1']){
|
|
||||||
$default1 = $values['filter-'.$l.'-1'];
|
|
||||||
}elseif(isset($args_values[$l][1])){
|
|
||||||
$default1 = $args_values[$l][1];
|
|
||||||
}
|
|
||||||
// dsm($default1, "default 1");
|
|
||||||
|
|
||||||
// form select element for second level
|
|
||||||
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-1'] = array(
|
|
||||||
'#type' => 'select',
|
|
||||||
'#options' => $level_1_ops,
|
|
||||||
'#name' => 'filter-'.$ll.'-1',
|
|
||||||
'#empty_option' => t("Choose a filter"),
|
|
||||||
// '#empty_values' => 0,
|
|
||||||
'#default_value' => $default1,
|
|
||||||
'#ajax' => array(
|
|
||||||
'callback' => 'materio_search_api_advanced_search_select_callback',
|
|
||||||
'wrapper' => 'advancedsearch-filters',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// without this line, form api will mess with default values
|
|
||||||
$form_state["input"]['filter-'.$ll.'-1'] = $default1;
|
|
||||||
|
|
||||||
// add level 2 filter if level 1 chosen
|
|
||||||
if($default1){
|
|
||||||
|
|
||||||
// build second level taxonomy tree and select options
|
|
||||||
$taxotree2 = taxonomy_get_tree($vid, $default1, 1, false);
|
|
||||||
if(count($taxotree2)){
|
|
||||||
// $default2 = isset($args_values[$l][2]) ? $args_values[$l][2] : 0;
|
|
||||||
$default2 = null;
|
|
||||||
if(isset($values['filter-'.$l.'-2']) && $values['filter-'.$l.'-2']){
|
|
||||||
$default2 = $values['filter-'.$l.'-2'];
|
|
||||||
}elseif(isset($args_values[$l][2])){
|
|
||||||
$default2 = $args_values[$l][2];
|
|
||||||
}
|
|
||||||
// dsm($default2, "default 2");
|
|
||||||
|
|
||||||
$level_2_ops = array();
|
|
||||||
foreach ($taxotree2 as $index => $term) {
|
|
||||||
// TODO: get translated tag name
|
|
||||||
$level_2_ops[$term->tid] = t($term->name);
|
|
||||||
}
|
|
||||||
// form select element for third level
|
|
||||||
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
|
|
||||||
'#type' => 'select',
|
|
||||||
'#options' => $level_2_ops,
|
|
||||||
'#name' => 'filter-'.$ll.'-2',
|
|
||||||
'#empty_option' => t("Choose a filter"),
|
|
||||||
// '#empty_values' => 0,
|
|
||||||
'#default_value' => $default2,
|
|
||||||
);
|
|
||||||
// without this line, form api will mess with default values
|
|
||||||
$form_state["input"]['filter-'.$ll.'-2'] = $default2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add remove the line button
|
$rmline = false;
|
||||||
$form['filters']['filterline-'.$ll]['rm-filter-'.$ll] = array(
|
if ($trigger) {
|
||||||
|
// dsm($form_state['triggering_element'], $form_state['triggering_element']['#name']);
|
||||||
|
// dsm($values, 'form state values');
|
||||||
|
|
||||||
|
// add a line if needed
|
||||||
|
if($trigger['#name'] == 'addfilters'){
|
||||||
|
$form_state['filterlines'] = $form_state['filterlines']+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove a line if needed
|
||||||
|
if(strpos($trigger['#name'], 'rm-filter-') === 0){
|
||||||
|
// $form_state['filterlines'] = $form_state['filterlines']+1;
|
||||||
|
$rmline = $trigger['#return_value'];
|
||||||
|
// dsm($rmline, "rmline");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// build first level taxonomy tree and select options
|
||||||
|
$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++) {
|
||||||
|
|
||||||
|
// if rmline this line,
|
||||||
|
// continue the loop without creating the line
|
||||||
|
if($l === $rmline){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// if we are after the removed line,
|
||||||
|
// create a second counter ($ll) to keep a continuous order for form items
|
||||||
|
// and keep the current counter ($l) to retrieve de current values
|
||||||
|
// if before removed line or no removed line at all, $l = $ll
|
||||||
|
if($rmline !== false && $l >= $rmline){
|
||||||
|
$ll = $l-1;
|
||||||
|
}else{
|
||||||
|
$ll = $l;
|
||||||
|
}
|
||||||
|
// dsm("l : ".$l." | ll : ".$ll);
|
||||||
|
|
||||||
|
$form['filters']['filterline-'.$ll] = array(
|
||||||
|
'#type' => 'container',
|
||||||
|
'#attributes' => array(
|
||||||
|
'class' => array("filter-line")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// get the default value
|
||||||
|
// from from_state values if ajax
|
||||||
|
// or from url args
|
||||||
|
// or 0
|
||||||
|
$default0 = null;
|
||||||
|
if(isset($values['filter-'.$l.'-0']) && $values['filter-'.$l.'-0']){
|
||||||
|
$default0 = $values['filter-'.$l.'-0'];
|
||||||
|
}elseif(isset($args_values[$l][0])){
|
||||||
|
$default0 = $args_values[$l][0];
|
||||||
|
}
|
||||||
|
// dsm($default0, "default 0");
|
||||||
|
|
||||||
|
// form select element for first level
|
||||||
|
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-0'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#options' => $level_0_ops,
|
||||||
|
'#name' => 'filter-'.$ll.'-0',
|
||||||
|
'#empty_option' => t("Choose a filter"),
|
||||||
|
// '#empty_values' => 0,
|
||||||
|
'#default_value' => $default0,
|
||||||
|
'#ajax' => array(
|
||||||
|
'callback' => 'materio_search_api_advanced_search_select_callback',
|
||||||
|
'wrapper' => 'advancedsearch-filters',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// without this line, form api will mess with default values
|
||||||
|
$form_state["input"]['filter-'.$ll.'-0'] = $default0;
|
||||||
|
|
||||||
|
// add level 1 filter if level 0 chosen
|
||||||
|
if($default0){
|
||||||
|
|
||||||
|
// build second level taxonomy tree and select options
|
||||||
|
$taxotree1 = taxonomy_get_tree($vid, $default0, 1, false);
|
||||||
|
$level_1_ops = array();
|
||||||
|
foreach ($taxotree1 as $index => $term) {
|
||||||
|
// TODO: get translated tag name
|
||||||
|
$level_1_ops[$term->tid] = t($term->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the default value
|
||||||
|
// from from_state values if ajax
|
||||||
|
// or from url args
|
||||||
|
// or 0
|
||||||
|
$default1 = null;
|
||||||
|
if(isset($values['filter-'.$l.'-1']) && $values['filter-'.$l.'-1']){
|
||||||
|
$default1 = $values['filter-'.$l.'-1'];
|
||||||
|
}elseif(isset($args_values[$l][1])){
|
||||||
|
$default1 = $args_values[$l][1];
|
||||||
|
}
|
||||||
|
// dsm($default1, "default 1");
|
||||||
|
|
||||||
|
// form select element for second level
|
||||||
|
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-1'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#options' => $level_1_ops,
|
||||||
|
'#name' => 'filter-'.$ll.'-1',
|
||||||
|
'#empty_option' => t("Choose a filter"),
|
||||||
|
// '#empty_values' => 0,
|
||||||
|
'#default_value' => $default1,
|
||||||
|
'#ajax' => array(
|
||||||
|
'callback' => 'materio_search_api_advanced_search_select_callback',
|
||||||
|
'wrapper' => 'advancedsearch-filters',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// without this line, form api will mess with default values
|
||||||
|
$form_state["input"]['filter-'.$ll.'-1'] = $default1;
|
||||||
|
|
||||||
|
// add level 2 filter if level 1 chosen
|
||||||
|
if($default1){
|
||||||
|
|
||||||
|
// build second level taxonomy tree and select options
|
||||||
|
$taxotree2 = taxonomy_get_tree($vid, $default1, 1, false);
|
||||||
|
if(count($taxotree2)){
|
||||||
|
// $default2 = isset($args_values[$l][2]) ? $args_values[$l][2] : 0;
|
||||||
|
$default2 = null;
|
||||||
|
if(isset($values['filter-'.$l.'-2']) && $values['filter-'.$l.'-2']){
|
||||||
|
$default2 = $values['filter-'.$l.'-2'];
|
||||||
|
}elseif(isset($args_values[$l][2])){
|
||||||
|
$default2 = $args_values[$l][2];
|
||||||
|
}
|
||||||
|
// dsm($default2, "default 2");
|
||||||
|
|
||||||
|
$level_2_ops = array();
|
||||||
|
foreach ($taxotree2 as $index => $term) {
|
||||||
|
// TODO: get translated tag name
|
||||||
|
$level_2_ops[$term->tid] = t($term->name);
|
||||||
|
}
|
||||||
|
// form select element for third level
|
||||||
|
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#options' => $level_2_ops,
|
||||||
|
'#name' => 'filter-'.$ll.'-2',
|
||||||
|
'#empty_option' => t("Choose a filter"),
|
||||||
|
// '#empty_values' => 0,
|
||||||
|
'#default_value' => $default2,
|
||||||
|
);
|
||||||
|
// without this line, form api will mess with default values
|
||||||
|
$form_state["input"]['filter-'.$ll.'-2'] = $default2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add remove the line button
|
||||||
|
$form['filters']['filterline-'.$ll]['rm-filter-'.$ll] = array(
|
||||||
|
'#type' => 'image_button',
|
||||||
|
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/rmfilter.png',
|
||||||
|
'#title' => t('Remove this filter line'),
|
||||||
|
'#name' => 'rm-filter-'.$ll,
|
||||||
|
'#return_value' => $ll,
|
||||||
|
'#executes_submit_callback' => false,
|
||||||
|
'#ajax' => array(
|
||||||
|
'callback' => 'materio_search_api_advanced_search_rmline_callback',
|
||||||
|
'wrapper' => 'advancedsearch-filters',
|
||||||
|
// 'trigger_as' => array("name"=>"rmfilters".$l),
|
||||||
|
),
|
||||||
|
"#attributes" => array('class'=>array('rm-btn')),
|
||||||
|
);
|
||||||
|
|
||||||
|
} // end of lines loop
|
||||||
|
|
||||||
|
if($rmline !== false){
|
||||||
|
$form_state['filterlines'] = $form_state['filterlines']-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// button to add a new line of criterias
|
||||||
|
$form['filters']['addfilters'] = array(
|
||||||
'#type' => 'image_button',
|
'#type' => 'image_button',
|
||||||
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/rmfilter.png',
|
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/addfilter.png',
|
||||||
'#title' => t('Remove this filter line'),
|
'#title' => t('Add a filter line'),
|
||||||
'#name' => 'rm-filter-'.$ll,
|
'#name' => "addfilters",
|
||||||
'#return_value' => $ll,
|
'#return_value' => "add",
|
||||||
'#executes_submit_callback' => false,
|
|
||||||
'#ajax' => array(
|
'#ajax' => array(
|
||||||
'callback' => 'materio_search_api_advanced_search_rmline_callback',
|
'callback' => 'materio_search_api_advanced_search_addfilter_callback',
|
||||||
'wrapper' => 'advancedsearch-filters',
|
'wrapper' => 'advancedsearch-filters',
|
||||||
// 'trigger_as' => array("name"=>"rmfilters".$l),
|
|
||||||
),
|
),
|
||||||
"#attributes" => array('class'=>array('rm-btn')),
|
'#executes_submit_callback' => false,
|
||||||
|
'#attributes' => array(
|
||||||
|
'class'=>array('add-filter')
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
} // end of lines loop
|
// buttons form container
|
||||||
|
$form['rightcol'] = array(
|
||||||
|
'#type' => 'container',
|
||||||
|
);
|
||||||
|
// add a back to search/base home bouton if on explore/foo
|
||||||
|
if ($path == 'explore' || $path == 'explore/filters' || $path == 'bookmarks' || $path == 'lists' ) {
|
||||||
|
$link = l('<i class="fi-home"></i>', base_path().'actuality', array(
|
||||||
|
'html'=>true,
|
||||||
|
'attributes'=>array('class'=>'back-search-home')
|
||||||
|
));
|
||||||
|
$form['rightcol']['actu'] = array(
|
||||||
|
'#type' => 'markup',
|
||||||
|
'#markup' => $link,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if($rmline !== false){
|
// submit the search
|
||||||
$form_state['filterlines'] = $form_state['filterlines']-1;
|
$form['rightcol']['search'] = array(
|
||||||
}
|
'#type' => 'image_button',
|
||||||
|
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
|
||||||
|
'#title' => t('Search'),
|
||||||
|
'#name' => "search",
|
||||||
|
'#return_value' => "search",
|
||||||
|
);
|
||||||
|
|
||||||
// button to add a new line of criterias
|
}else{
|
||||||
$form['filters']['addfilters'] = array(
|
$form['novoc'] = array(
|
||||||
'#type' => 'image_button',
|
'#markup' => "Please choose a vocabulary to search from in materio search api settings"
|
||||||
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/addfilter.png',
|
|
||||||
'#title' => t('Add a filter line'),
|
|
||||||
'#name' => "addfilters",
|
|
||||||
'#return_value' => "add",
|
|
||||||
'#ajax' => array(
|
|
||||||
'callback' => 'materio_search_api_advanced_search_addfilter_callback',
|
|
||||||
'wrapper' => 'advancedsearch-filters',
|
|
||||||
),
|
|
||||||
'#executes_submit_callback' => false,
|
|
||||||
'#attributes' => array(
|
|
||||||
'class'=>array('add-filter')
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// buttons form container
|
|
||||||
$form['rightcol'] = array(
|
|
||||||
'#type' => 'container',
|
|
||||||
);
|
|
||||||
// add a back to search/base home bouton if on explore/foo
|
|
||||||
if ($path == 'explore' || $path == 'explore/filters' || $path == 'bookmarks' || $path == 'lists' ) {
|
|
||||||
$link = l('<i class="fi-home"></i>', base_path().'actuality', array(
|
|
||||||
'html'=>true,
|
|
||||||
'attributes'=>array('class'=>'back-search-home')
|
|
||||||
));
|
|
||||||
$form['rightcol']['actu'] = array(
|
|
||||||
'#type' => 'markup',
|
|
||||||
'#markup' => $link,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// submit the search
|
|
||||||
$form['rightcol']['search'] = array(
|
|
||||||
'#type' => 'image_button',
|
|
||||||
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
|
|
||||||
'#title' => t('Search'),
|
|
||||||
'#name' => "search",
|
|
||||||
'#return_value' => "search",
|
|
||||||
);
|
|
||||||
|
|
||||||
// dsm($form, 'form');
|
// dsm($form, 'form');
|
||||||
return $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('Actualities by materiO\'');
|
||||||
$vars['actualities_infos'] = t('');
|
$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) {
|
function theme_materio_search_api_form_element($variables) {
|
||||||
// dsm($variables, 'variables');
|
// dsm($variables, 'variables');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user