advanced search :
separate tree terms generation and form generation fixed a php notice
This commit is contained in:
parent
d2cffdeddd
commit
11617ec99c
@ -684,6 +684,8 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|||||||
// dsm($form_state, 'form_state');
|
// dsm($form_state, 'form_state');
|
||||||
// dsm($form, 'form');
|
// dsm($form, 'form');
|
||||||
// global $user;
|
// global $user;
|
||||||
|
$as_tree = materio_serach_api_get_advancedsearch_tree();
|
||||||
|
dsm($as_tree, 'as_tree');
|
||||||
|
|
||||||
$keys = arg();
|
$keys = arg();
|
||||||
$path = array_shift($keys);
|
$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(
|
$form['slider'] = array(
|
||||||
'#type' => 'fieldset',
|
'#type' => 'fieldset',
|
||||||
// '#title' => $voc->name,
|
// '#title' => $voc->name,
|
||||||
'#tree' => true,
|
'#tree' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($vocabularies as $vid) {
|
foreach ($as_tree as $vid => $tree) {
|
||||||
// dsm($vid, "vid");
|
|
||||||
|
|
||||||
$voc = taxonomy_vocabulary_load($vid);
|
// $voc = taxonomy_vocabulary_load($vid);
|
||||||
// dsm($voc, 'voc');
|
// dsm($voc, 'voc');
|
||||||
|
|
||||||
$form['slider']['voc-'.$vid] = array(
|
$form['slider']['voc-'.$vid] = array(
|
||||||
@ -722,25 +721,10 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|||||||
'#tree' => true,
|
'#tree' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
$tree = taxonomy_get_tree($vid, 0, 1, TRUE);
|
|
||||||
// dsm($tree, 'tree');
|
|
||||||
|
|
||||||
if(!count($tree))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foreach ($tree as $term) {
|
foreach ($tree as $term) {
|
||||||
// dsm($term, "term");
|
// dsm($term, 'term');
|
||||||
|
|
||||||
if($term->field_used_on_advanced_search['und'][0]['value'] == 0)
|
$form['slider']['voc-'.$vid]['tree-'.$term['tid']] = array(
|
||||||
continue;
|
|
||||||
|
|
||||||
$children = taxonomy_get_children($term->tid, $vid);
|
|
||||||
// dsm($children, "children");
|
|
||||||
|
|
||||||
if(!count($children))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$form['slider']['voc-'.$vid]['tree-'.$term->tid] = array(
|
|
||||||
'#type' => 'fieldset',
|
'#type' => 'fieldset',
|
||||||
// '#title' => $term->name,
|
// '#title' => $term->name,
|
||||||
'#attributes' => array("class"=>array("treelevel1")),
|
'#attributes' => array("class"=>array("treelevel1")),
|
||||||
@ -748,9 +732,9 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|||||||
);
|
);
|
||||||
|
|
||||||
$placeholder = t("Select an option");
|
$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',
|
'#type' => 'select',
|
||||||
'#title' => $term->name,
|
'#title' => $term['name'],
|
||||||
'#attributes' => array(
|
'#attributes' => array(
|
||||||
"class"=>array("treelevel1"),
|
"class"=>array("treelevel1"),
|
||||||
"title"=>$placeholder,
|
"title"=>$placeholder,
|
||||||
@ -762,37 +746,19 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|||||||
);
|
);
|
||||||
|
|
||||||
$options = array();
|
$options = array();
|
||||||
foreach ($children as $tid => $child) {
|
foreach ($term['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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// $children2 = taxonomy_get_children($child->tid, $vid);
|
$options[$tid] = $child['name'];
|
||||||
$children2 = taxonomy_get_children_all($child->tid, $vid);
|
|
||||||
// dsm($children2, "children2");
|
|
||||||
|
|
||||||
if(!count($children2))
|
$classes2 = array("treelevel2", $child['tid']);
|
||||||
continue;
|
|
||||||
|
|
||||||
$options[$tid] = $child->name;
|
|
||||||
|
|
||||||
$classes2 = array("treelevel2", $child->tid);
|
|
||||||
|
|
||||||
$options2 = array();
|
$options2 = array();
|
||||||
$dflt_values2 = array();
|
$dflt_values2 = array();
|
||||||
foreach ($children2 as $tid2 => $child2) {
|
foreach ($child['children'] as $tid2 => $child2) {
|
||||||
$child2 = taxonomy_term_load($tid2);
|
$options2[$tid2] = $child2['name'];
|
||||||
if($child2->field_used_on_advanced_search['und'][0]['value'] == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$options2[$tid2] = $child2->name;
|
|
||||||
|
|
||||||
// default Values
|
// default Values
|
||||||
if(in_array($tid2, $default_keys))
|
if(in_array($tid2, $default_keys))
|
||||||
$dflt_values2[] = $tid2;
|
$dflt_values2[] = $tid2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($options2)){
|
if(count($options2)){
|
||||||
@ -800,14 +766,14 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|||||||
if(count($dflt_values2))
|
if(count($dflt_values2))
|
||||||
$classes2[] = 'visible';
|
$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',
|
'#type' => 'select',
|
||||||
'#title' => $child->name,
|
'#title' => $child['name'],
|
||||||
'#multiple' => true,
|
'#multiple' => true,
|
||||||
'#attributes' => array(
|
'#attributes' => array(
|
||||||
"class" => $classes2, // , "form-control"
|
"class" => $classes2, // , "form-control"
|
||||||
"title" => "-Please select-",
|
"title" => "-Please select-",
|
||||||
"tid" => $child->tid,
|
"tid" => $child['tid'],
|
||||||
),
|
),
|
||||||
'#theme_wrappers' => array('materio_search_api_form_element'),
|
'#theme_wrappers' => array('materio_search_api_form_element'),
|
||||||
// '#empty_option' => '-Please select-',
|
// '#empty_option' => '-Please select-',
|
||||||
@ -818,9 +784,9 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(count($options)){
|
if(count($options)){
|
||||||
$form['slider']['voc-'.$vid]['tree-'.$term->tid]['children']['#options'] = $options;
|
$form['slider']['voc-'.$vid]['tree-'.$term['tid']]['children']['#options'] = $options;
|
||||||
}else{
|
}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;
|
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'){
|
function taxonomy_get_children_all($tid, $vid = 0, $key = 'tid'){
|
||||||
$c = taxonomy_get_children($tid, $vid, $key);
|
$c = taxonomy_get_children($tid, $vid, $key);
|
||||||
$result = array();
|
$result = array();
|
||||||
|
@ -139,6 +139,7 @@ function materio_search_api_results_search(){
|
|||||||
// }
|
// }
|
||||||
$typed = implode(' +', $keys);
|
$typed = implode(' +', $keys);
|
||||||
}else{
|
}else{
|
||||||
|
$advanced = false;
|
||||||
$typed = implode('/', $keys);
|
$typed = implode('/', $keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user