diff --git a/materio_search_api.module b/materio_search_api.module index 001493c7..859fc3e0 100755 --- a/materio_search_api.module +++ b/materio_search_api.module @@ -684,6 +684,8 @@ function materio_search_api_advanced_search_form($form, &$form_state){ // dsm($form_state, 'form_state'); // dsm($form, 'form'); // global $user; + $as_tree = materio_serach_api_get_advancedsearch_tree(); + dsm($as_tree, 'as_tree'); $keys = arg(); $path = array_shift($keys); @@ -702,18 +704,15 @@ function materio_search_api_advanced_search_form($form, &$form_state){ ) ); - $vocabularies = variable_get('advancedsearchvocs', array()); - $form['slider'] = array( '#type' => 'fieldset', // '#title' => $voc->name, '#tree' => true, ); - foreach ($vocabularies as $vid) { - // dsm($vid, "vid"); + foreach ($as_tree as $vid => $tree) { - $voc = taxonomy_vocabulary_load($vid); + // $voc = taxonomy_vocabulary_load($vid); // dsm($voc, 'voc'); $form['slider']['voc-'.$vid] = array( @@ -722,25 +721,10 @@ function materio_search_api_advanced_search_form($form, &$form_state){ '#tree' => true, ); - $tree = taxonomy_get_tree($vid, 0, 1, TRUE); - // dsm($tree, 'tree'); - - if(!count($tree)) - continue; - foreach ($tree as $term) { - // dsm($term, "term"); + // dsm($term, 'term'); - if($term->field_used_on_advanced_search['und'][0]['value'] == 0) - continue; - - $children = taxonomy_get_children($term->tid, $vid); - // dsm($children, "children"); - - if(!count($children)) - continue; - - $form['slider']['voc-'.$vid]['tree-'.$term->tid] = array( + $form['slider']['voc-'.$vid]['tree-'.$term['tid']] = array( '#type' => 'fieldset', // '#title' => $term->name, '#attributes' => array("class"=>array("treelevel1")), @@ -748,9 +732,9 @@ function materio_search_api_advanced_search_form($form, &$form_state){ ); $placeholder = t("Select an option"); - $form['slider']['voc-'.$vid]['tree-'.$term->tid]['children'] = array( + $form['slider']['voc-'.$vid]['tree-'.$term['tid']]['children'] = array( '#type' => 'select', - '#title' => $term->name, + '#title' => $term['name'], '#attributes' => array( "class"=>array("treelevel1"), "title"=>$placeholder, @@ -762,37 +746,19 @@ function materio_search_api_advanced_search_form($form, &$form_state){ ); $options = array(); - foreach ($children as $tid => $child) { - $child = taxonomy_term_load($child->tid); - // dsm($child, 'child'); - if($child->field_used_on_advanced_search['und'][0]['value'] == 0){ - continue; - } + foreach ($term['children'] as $tid => $child) { - // $children2 = taxonomy_get_children($child->tid, $vid); - $children2 = taxonomy_get_children_all($child->tid, $vid); - // dsm($children2, "children2"); + $options[$tid] = $child['name']; - if(!count($children2)) - continue; - - $options[$tid] = $child->name; - - $classes2 = array("treelevel2", $child->tid); + $classes2 = array("treelevel2", $child['tid']); $options2 = array(); $dflt_values2 = array(); - foreach ($children2 as $tid2 => $child2) { - $child2 = taxonomy_term_load($tid2); - if($child2->field_used_on_advanced_search['und'][0]['value'] == 0) - continue; - - $options2[$tid2] = $child2->name; - + foreach ($child['children'] as $tid2 => $child2) { + $options2[$tid2] = $child2['name']; // default Values if(in_array($tid2, $default_keys)) $dflt_values2[] = $tid2; - } if(count($options2)){ @@ -800,14 +766,14 @@ function materio_search_api_advanced_search_form($form, &$form_state){ if(count($dflt_values2)) $classes2[] = 'visible'; - $form['slider']['voc-'.$vid]['tree-'.$term->tid]['tid-'.$child->tid] = array( + $form['slider']['voc-'.$vid]['tree-'.$term['tid']]['tid-'.$child['tid']] = array( '#type' => 'select', - '#title' => $child->name, + '#title' => $child['name'], '#multiple' => true, '#attributes' => array( "class" => $classes2, // , "form-control" "title" => "-Please select-", - "tid" => $child->tid, + "tid" => $child['tid'], ), '#theme_wrappers' => array('materio_search_api_form_element'), // '#empty_option' => '-Please select-', @@ -818,9 +784,9 @@ function materio_search_api_advanced_search_form($form, &$form_state){ } } if(count($options)){ - $form['slider']['voc-'.$vid]['tree-'.$term->tid]['children']['#options'] = $options; + $form['slider']['voc-'.$vid]['tree-'.$term['tid']]['children']['#options'] = $options; }else{ - unset($form['slider']['voc-'.$vid]['tree-'.$term->tid]); + unset($form['slider']['voc-'.$vid]['tree-'.$term['tid']]); } } @@ -837,6 +803,67 @@ function materio_search_api_advanced_search_form($form, &$form_state){ return $form; } +function materio_serach_api_get_advancedsearch_tree(){ + $as_tree = array(); + $vocabularies = variable_get('advancedsearchvocs', array()); + + foreach ($vocabularies as $vid) { + // dsm($vid, "vid"); + + // $voc = taxonomy_vocabulary_load($vid); + // dsm($voc, 'voc'); + + $tree = taxonomy_get_tree($vid, 0, 1, TRUE); + // dsm($tree, 'tree'); + + if(!count($tree)) continue; + + foreach ($tree as $term) { + // dsm($term, "term : ".$term->name); + + if(!isset($term->field_used_on_advanced_search['und'][0]['value']) + || $term->field_used_on_advanced_search['und'][0]['value'] == 0) + continue; + + $children = taxonomy_get_children($term->tid, $vid); + // dsm($children, "children"); + + if(!count($children)) continue; + + foreach ($children as $tid => $child) { + $child = taxonomy_term_load($child->tid); + dsm($child, 'child : '.$child->name); + if($child->field_used_on_advanced_search['und'][0]['value'] == 0) + continue; + + // $children2 = taxonomy_get_children($child->tid, $vid); + $children2 = taxonomy_get_children_all($child->tid, $vid); + // dsm($children2, "children2"); + + if(!count($children2)) continue; + + foreach ($children2 as $tid2 => $child2) { + $child2 = taxonomy_term_load($tid2); + // dsm($child2, 'child2 : '.$child2->name); + if(!isset($child2->field_used_on_advanced_search['und'][0]['value']) + || $child2->field_used_on_advanced_search['und'][0]['value'] == 0) + continue; + + $as_tree[$vid][$term->tid]['children'][$child->tid]['children'][] = array('tid'=>$child2->tid,'name'=>$child2->name); + } + + if(isset($as_tree[$vid][$term->tid]['children'][$child->tid]['children'])) + $as_tree[$vid][$term->tid]['children'][$child->tid] += array("tid"=>$child->tid,"name"=>$child->name); + } + + if(isset($as_tree[$vid][$term->tid]['children'])) + $as_tree[$vid][$term->tid] += array("tid"=>$term->tid,"name"=>$term->name); + } + } + + return $as_tree; +} + function taxonomy_get_children_all($tid, $vid = 0, $key = 'tid'){ $c = taxonomy_get_children($tid, $vid, $key); $result = array(); diff --git a/materio_search_api.pages.inc b/materio_search_api.pages.inc index 830db04b..3de2fb6f 100755 --- a/materio_search_api.pages.inc +++ b/materio_search_api.pages.inc @@ -139,6 +139,7 @@ function materio_search_api_results_search(){ // } $typed = implode(' +', $keys); }else{ + $advanced = false; $typed = implode('/', $keys); }