From d2cffdeddd8370f7a698abacae508b39cc0065d4 Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Sat, 27 Sep 2014 13:02:00 +0800 Subject: [PATCH] improved better search activated terms filtration regarding useinadvancedsearch term field added all children of level 2 terms --- materio_search_api.module | 46 ++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/materio_search_api.module b/materio_search_api.module index c83bf5c6..001493c7 100755 --- a/materio_search_api.module +++ b/materio_search_api.module @@ -731,11 +731,13 @@ function materio_search_api_advanced_search_form($form, &$form_state){ foreach ($tree as $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($term->field_used_on_advanced_search['und'][0]['value'] == 0 - || !count($children)) + if(!count($children)) continue; $form['slider']['voc-'.$vid]['tree-'.$term->tid] = array( @@ -761,26 +763,29 @@ function materio_search_api_advanced_search_form($form, &$form_state){ $options = array(); foreach ($children as $tid => $child) { - // $child = taxonomy_term_load($child->tid); - // if($child->field_used_on_advanced_search['und'][0]['value'] == 0){ - // continue; - // } + $child = taxonomy_term_load($child->tid); + // dsm($child, 'child'); + if($child->field_used_on_advanced_search['und'][0]['value'] == 0){ + continue; + } - $children2 = taxonomy_get_children($child->tid, $vid); + // $children2 = taxonomy_get_children($child->tid, $vid); + $children2 = taxonomy_get_children_all($child->tid, $vid); // dsm($children2, "children2"); - if(count($children2)) - $options[$tid] = $child->name; + if(!count($children2)) + continue; + + $options[$tid] = $child->name; $classes2 = array("treelevel2", $child->tid); $options2 = array(); $dflt_values2 = array(); foreach ($children2 as $tid2 => $child2) { - // $child2 = taxonomy_term_load($child2->tid); - // if($child2->field_used_on_advanced_search['und'][0]['value'] == 0){ - // continue; - // } + $child2 = taxonomy_term_load($tid2); + if($child2->field_used_on_advanced_search['und'][0]['value'] == 0) + continue; $options2[$tid2] = $child2->name; @@ -832,6 +837,21 @@ function materio_search_api_advanced_search_form($form, &$form_state){ return $form; } +function taxonomy_get_children_all($tid, $vid = 0, $key = 'tid'){ + $c = taxonomy_get_children($tid, $vid, $key); + $result = array(); + foreach ($c as $t => $d){ + $result[$t] = $d; + $below = taxonomy_get_children_all($t, $vid, $key); + if (!empty($below)) { + foreach ($below as $nt => $nd){ + $result[$nt] = $nd; + } + } + } + return $result; +} + function materio_search_api_advanced_search_form_validate($form, &$form_state){ // dsm($form, '$form'); // dsm($form_state, '$form_state');