|
@@ -796,14 +796,10 @@ function materio_search_api_search_form_submit($form, &$form_state){
|
|
|
function materio_search_api_advanced_search_form($form, &$form_state){
|
|
|
// dsm($form_state, 'form_state');
|
|
|
// dsm($form, 'form');
|
|
|
- // global $user;
|
|
|
- // $form = array();
|
|
|
|
|
|
// get vid from settings
|
|
|
$vid = variable_get('msa-advancedsearchvocabulary', null);
|
|
|
if($vid){
|
|
|
- // global $language;
|
|
|
- // dsm($language, "language");
|
|
|
|
|
|
$voc = taxonomy_vocabulary_load($vid);
|
|
|
$voc_machinename = $voc->machine_name;
|
|
@@ -826,25 +822,6 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
|
// get the keywords from args and reconstruct the filter lines with default values
|
|
|
$args_values = array();
|
|
|
if($path == 'explore/filters' && $args[0] !== "ajax"){
|
|
|
- // WORKING WITH TERM NAMES instead of tids
|
|
|
- // $keywords = explode("+", $args[0]);
|
|
|
- // // dsm($keywords, 'keywords');
|
|
|
- // foreach ($keywords as $key => $value) {
|
|
|
- // $name = str_replace('"', '', $value);
|
|
|
- // //Get the term
|
|
|
- // $terms = taxonomy_get_term_by_name($name, $voc_machinename);
|
|
|
- // $term = array_shift($terms);
|
|
|
- // // dsm($term, $term->tid.' : '.$term->name);
|
|
|
- // // 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;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
// WORKING WITH TIDS instead of term name
|
|
|
$tids = explode("+", $args[0]);
|
|
|
foreach ($tids as $key => $tid) {
|
|
@@ -878,13 +855,38 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
|
}
|
|
|
// dsm($form_state['filterlines'], "form_state['filterlines']");
|
|
|
|
|
|
+
|
|
|
// filters form container
|
|
|
$form['filters'] = array(
|
|
|
'#type' => 'container',
|
|
|
- '#prefix' => '<div id="advancedsearch-filters">',
|
|
|
+ '#attributes' => array('class' => array("advancedsearch-filters")),
|
|
|
+ '#prefix' => '<div id="advancedsearch-filters-wrapper">',
|
|
|
'#suffix' => '</div>',
|
|
|
);
|
|
|
|
|
|
+ $form['filters']['filters-table'] = array(
|
|
|
+ '#type' => 'container',
|
|
|
+ '#attributes' => array('class' => array("advanced-search-form-table"))
|
|
|
+ );
|
|
|
+
|
|
|
+ // form headers
|
|
|
+ // $form['filters']['filters-table']['headers'] = array(
|
|
|
+ // '#type' => 'container',
|
|
|
+ // '#attributes' => array('class' => array("advanced-search-form-headers")),
|
|
|
+ // 'category' => array(
|
|
|
+ // '#markup' => t("Category"),
|
|
|
+ // '#prefix' => '<div>','#suffix' => '</div>',
|
|
|
+ // ),
|
|
|
+ // 'main' => array(
|
|
|
+ // '#markup' => t("Main Filter"),
|
|
|
+ // '#prefix' => '<div>','#suffix' => '</div>',
|
|
|
+ // ),
|
|
|
+ // 'child' => array(
|
|
|
+ // '#markup' => t("Child Filter"),
|
|
|
+ // '#prefix' => '<div>','#suffix' => '</div>',
|
|
|
+ // )
|
|
|
+ // );
|
|
|
+
|
|
|
$trigger = FALSE;
|
|
|
if (!empty($form_state['triggering_element']['#name'])) {
|
|
|
$trigger = $form_state['triggering_element'];
|
|
@@ -939,11 +941,9 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
|
}
|
|
|
// dsm("l : ".$l." | ll : ".$ll);
|
|
|
|
|
|
- $form['filters']['filterline-'.$ll] = array(
|
|
|
+ $form['filters']['filters-table']['filterline-'.$ll] = array(
|
|
|
'#type' => 'container',
|
|
|
- '#attributes' => array(
|
|
|
- 'class' => array("filter-line")
|
|
|
- )
|
|
|
+ '#attributes' => array('class' => array("filter-line"))
|
|
|
);
|
|
|
|
|
|
// get the default value
|
|
@@ -959,99 +959,122 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
|
// dsm($default0, "default 0");
|
|
|
|
|
|
// form select element for first level
|
|
|
- $form['filters']['filterline-'.$ll]['filter-'.$ll.'-0'] = array(
|
|
|
+ $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-0'] = array(
|
|
|
'#type' => 'select',
|
|
|
'#options' => $level_0_ops,
|
|
|
'#name' => 'filter-'.$ll.'-0',
|
|
|
- '#empty_option' => t("Choose a filter"),
|
|
|
+ '#empty_option' => t("Choose a category"),
|
|
|
// '#empty_values' => 0,
|
|
|
'#default_value' => $default0,
|
|
|
'#ajax' => array(
|
|
|
'callback' => 'materio_search_api_advanced_search_select_callback',
|
|
|
- 'wrapper' => 'advancedsearch-filters',
|
|
|
+ 'wrapper' => 'advancedsearch-filters-wrapper',
|
|
|
),
|
|
|
);
|
|
|
// 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, true);
|
|
|
- // dsm($taxotree1, 'taxotree1');
|
|
|
- $level_1_ops = array();
|
|
|
- foreach ($taxotree1 as $index => $term) {
|
|
|
- // TODO: get translated tag name
|
|
|
- // $term = taxonomy_term_load($tid);
|
|
|
- $level_1_ops[$term->tid] = $term->name;
|
|
|
- }
|
|
|
+ if(is_null($default0)){
|
|
|
+ // $form['filters']['filterline-'.$ll]['filter-'.$ll.'-1']
|
|
|
+ $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-1'] = array(
|
|
|
+ '#markup' => t("Main Filter"),
|
|
|
+ '#prefix' => '<div class="filter-markup"><span>',
|
|
|
+ '#suffix' => '</span></div>',
|
|
|
+ );
|
|
|
+ // the definition of this markup appears twice, i may avoid that ...
|
|
|
+ $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
|
|
|
+ '#markup' => t("Child Filter"),
|
|
|
+ '#prefix' => '<div class="filter-markup"><span>',
|
|
|
+ '#suffix' => '</span></div>',
|
|
|
+ );
|
|
|
+ }else{
|
|
|
+ // build second level taxonomy tree and select options
|
|
|
+ $taxotree1 = taxonomy_get_tree($vid, $default0, 1, true);
|
|
|
+ // dsm($taxotree1, 'taxotree1');
|
|
|
+ $level_1_ops = array();
|
|
|
+ foreach ($taxotree1 as $index => $term) {
|
|
|
+ // TODO: get translated tag name
|
|
|
+ // $term = taxonomy_term_load($tid);
|
|
|
+ $level_1_ops[$term->tid] = $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',
|
|
|
- ),
|
|
|
+ // 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']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-1'] = array(
|
|
|
+ '#type' => 'select',
|
|
|
+ '#options' => $level_1_ops,
|
|
|
+ '#name' => 'filter-'.$ll.'-1',
|
|
|
+ '#empty_option' => t("Choose a main filter"),
|
|
|
+ // '#empty_values' => 0,
|
|
|
+ '#default_value' => $default1,
|
|
|
+ '#ajax' => array(
|
|
|
+ 'callback' => 'materio_search_api_advanced_search_select_callback',
|
|
|
+ 'wrapper' => 'advancedsearch-filters-wrapper',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ // 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(is_null($default1)){
|
|
|
+ $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
|
|
|
+ '#markup' => t("Child Filter"),
|
|
|
+ '#prefix' => '<div class="filter-markup"><span>',
|
|
|
+ '#suffix' => '</span></div>',
|
|
|
);
|
|
|
- // 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, true);
|
|
|
- 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;
|
|
|
- }
|
|
|
+ }else{
|
|
|
+ // build second level taxonomy tree and select options
|
|
|
+ $taxotree2 = taxonomy_get_tree($vid, $default1, 1, true);
|
|
|
+ if(!count($taxotree2)){
|
|
|
+ $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
|
|
|
+ '#markup' => t("No Child"),
|
|
|
+ '#prefix' => '<div class="filter-markup"><span>',
|
|
|
+ '#suffix' => '</span></div>',
|
|
|
+ );
|
|
|
+ }else{
|
|
|
+ // $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']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
|
|
|
+ '#type' => 'select',
|
|
|
+ '#options' => $level_2_ops,
|
|
|
+ '#name' => 'filter-'.$ll.'-2',
|
|
|
+ '#empty_option' => t("Refine with a child 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(
|
|
|
+ $form['filters']['filters-table']['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'),
|
|
@@ -1060,7 +1083,7 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
|
'#executes_submit_callback' => false,
|
|
|
'#ajax' => array(
|
|
|
'callback' => 'materio_search_api_advanced_search_rmline_callback',
|
|
|
- 'wrapper' => 'advancedsearch-filters',
|
|
|
+ 'wrapper' => 'advancedsearch-filters-wrapper',
|
|
|
// 'trigger_as' => array("name"=>"rmfilters".$l),
|
|
|
),
|
|
|
"#attributes" => array('class'=>array('rm-btn')),
|
|
@@ -1081,17 +1104,16 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
|
'#return_value' => "add",
|
|
|
'#ajax' => array(
|
|
|
'callback' => 'materio_search_api_advanced_search_addfilter_callback',
|
|
|
- 'wrapper' => 'advancedsearch-filters',
|
|
|
+ 'wrapper' => 'advancedsearch-filters-wrapper',
|
|
|
),
|
|
|
'#executes_submit_callback' => false,
|
|
|
- '#attributes' => array(
|
|
|
- 'class'=>array('add-filter')
|
|
|
- ),
|
|
|
+ '#attributes' => array('class'=>array('add-filter'))
|
|
|
);
|
|
|
|
|
|
// buttons form container
|
|
|
$form['rightcol'] = array(
|
|
|
'#type' => 'container',
|
|
|
+ "#attributes" => array('class'=>array('right-col')),
|
|
|
);
|
|
|
// add a back to search/base home bouton if on explore/foo
|
|
|
if ($path == 'explore' || $path == 'explore/filters' || $path == 'bookmarks' || $path == 'lists' ) {
|
|
@@ -1168,7 +1190,7 @@ function materio_search_api_advanced_search_rmline_callback($form, &$form_state)
|
|
|
function materio_search_api_advanced_search_form_validate($form, &$form_state){
|
|
|
if($form_state['triggering_element']['#name'] == 'search'){
|
|
|
// dsm($form, '$form');
|
|
|
- // dsm($form_state, 'form_state');
|
|
|
+ dsm($form_state, 'form_state');
|
|
|
|
|
|
if (!isset($form_state['values']['filter-0-1']) || $form_state['values']['filter-0-1'] == '') {
|
|
|
form_set_error('filters', 'Please choose at least 1 keyword.');
|