|
@@ -128,6 +128,12 @@ function materio_search_api_search_api_data_type_info() {
|
|
'prefix' => 'temmap',
|
|
'prefix' => 'temmap',
|
|
'always multiValued' => TRUE,
|
|
'always multiValued' => TRUE,
|
|
),
|
|
),
|
|
|
|
+ // 'term_tid' => array(
|
|
|
|
+ // 'name' => t('Taxonomy term tid'),
|
|
|
|
+ // 'fallback' => 'integer',
|
|
|
|
+ // 'prefix' => 'im',
|
|
|
|
+ // 'always multiValued' => TRUE,
|
|
|
|
+ // ),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -146,8 +152,11 @@ function materio_search_api_search_api_solr_dynamic_field_info() {
|
|
'prefix' => 'temmap',
|
|
'prefix' => 'temmap',
|
|
'always multiValued' => TRUE,
|
|
'always multiValued' => TRUE,
|
|
),
|
|
),
|
|
|
|
+ // 'term_tid' => array(
|
|
|
|
+ // 'prefix' => 'im',
|
|
|
|
+ // 'always multiValued' => TRUE,
|
|
|
|
+ // ),
|
|
);
|
|
);
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -168,33 +177,39 @@ function materio_search_api_entity_property_info_alter(&$info){
|
|
$node_props['materio_search_api_onthologie_term_'.$i.'_text'] = array(
|
|
$node_props['materio_search_api_onthologie_term_'.$i.'_text'] = array(
|
|
'type'=>'text',
|
|
'type'=>'text',
|
|
'label'=> t('Main onthologie term '.$i. ' as text (+ synonyms)'),
|
|
'label'=> t('Main onthologie term '.$i. ' as text (+ synonyms)'),
|
|
- // 'query callback'=>'entity_metadata_table_query',
|
|
|
|
'getter callback'=>'materio_search_api_get_onthologie_term_'.$i.'_text',
|
|
'getter callback'=>'materio_search_api_get_onthologie_term_'.$i.'_text',
|
|
);
|
|
);
|
|
|
|
+ $node_props['materio_search_api_onthologie_term_'.$i.'_tid'] = array(
|
|
|
|
+ 'type'=>'text',
|
|
|
|
+ 'label'=> t('Main onthologie term '.$i. ' as tid'),
|
|
|
|
+ 'getter callback'=>'materio_search_api_get_onthologie_term_'.$i.'_tid',
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
$node_props['materio_search_api_onthologie_term_others_text'] = array(
|
|
$node_props['materio_search_api_onthologie_term_others_text'] = array(
|
|
'type'=>'list<text>',
|
|
'type'=>'list<text>',
|
|
'label'=> t('Others onthologie terms as text (+ synonyms)'),
|
|
'label'=> t('Others onthologie terms as text (+ synonyms)'),
|
|
- // 'query callback'=>'entity_metadata_table_query',
|
|
|
|
'getter callback'=>'materio_search_api_get_taxonomy_terms_others_text',
|
|
'getter callback'=>'materio_search_api_get_taxonomy_terms_others_text',
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ $node_props['materio_search_api_onthologie_term_others_tid'] = array(
|
|
|
|
+ 'type'=>'list<text>',
|
|
|
|
+ 'label'=> t('Others onthologie terms as tid'),
|
|
|
|
+ 'getter callback'=>'materio_search_api_get_taxonomy_terms_others_tid',
|
|
|
|
+ );
|
|
|
|
+
|
|
$node_props['materio_search_api_taglibres_text'] = array(
|
|
$node_props['materio_search_api_taglibres_text'] = array(
|
|
'type'=>'list<text>',
|
|
'type'=>'list<text>',
|
|
'label'=> t('Tag libres terms as text (+ synonyms)'),
|
|
'label'=> t('Tag libres terms as text (+ synonyms)'),
|
|
- // 'query callback'=>'entity_metadata_table_query',
|
|
|
|
'getter callback'=>'materio_search_api_get_taglibres_terms_text',
|
|
'getter callback'=>'materio_search_api_get_taglibres_terms_text',
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
$node_materiau_props = &$info['node']['bundles']['materiau']['properties'];
|
|
$node_materiau_props = &$info['node']['bundles']['materiau']['properties'];
|
|
|
|
|
|
$node_materiau_props['materio_search_api_node_propertie_companie'] = array(
|
|
$node_materiau_props['materio_search_api_node_propertie_companie'] = array(
|
|
'type'=>'list<text>',
|
|
'type'=>'list<text>',
|
|
'label'=> t('Manufacturers and distributors companies localised (dont addresse)'),
|
|
'label'=> t('Manufacturers and distributors companies localised (dont addresse)'),
|
|
- // 'query callback'=>'entity_metadata_table_query',
|
|
|
|
'getter callback'=>'materio_search_api_get_node_propertie_companie',
|
|
'getter callback'=>'materio_search_api_get_node_propertie_companie',
|
|
);
|
|
);
|
|
|
|
|
|
@@ -208,9 +223,11 @@ function materio_search_api_entity_property_info_alter(&$info){
|
|
'type' => 'text',
|
|
'type' => 'text',
|
|
'getter callback' => 'materio_search_api_term_property_dup_name',
|
|
'getter callback' => 'materio_search_api_term_property_dup_name',
|
|
);
|
|
);
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+* taxonomy propoerties as text + synonymes
|
|
|
|
+*/
|
|
function materio_search_api_get_onthologie_term_1_text($item){
|
|
function materio_search_api_get_onthologie_term_1_text($item){
|
|
// dsm($item, 'item');
|
|
// dsm($item, 'item');
|
|
return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 0);
|
|
return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 0);
|
|
@@ -292,6 +309,55 @@ function materio_search_api_get_taxo_term_field_text($item, $field_name, $delta)
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+* taxonomy properties as tid
|
|
|
|
+*/
|
|
|
|
+function materio_search_api_get_onthologie_term_1_tid($item){
|
|
|
|
+ // dsm($item, 'item');
|
|
|
|
+ return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 0);
|
|
|
|
+}
|
|
|
|
+function materio_search_api_get_onthologie_term_2_tid($item){
|
|
|
|
+ // dsm($item, 'item');
|
|
|
|
+ return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 1);
|
|
|
|
+}
|
|
|
|
+function materio_search_api_get_onthologie_term_3_tid($item){
|
|
|
|
+ // dsm($item, 'item');
|
|
|
|
+ return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 2);
|
|
|
|
+}
|
|
|
|
+function materio_search_api_get_onthologie_term_4_tid($item){
|
|
|
|
+ // dsm($item, 'item');
|
|
|
|
+ return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 3);
|
|
|
|
+}
|
|
|
|
+function materio_search_api_get_onthologie_term_5_tid($item){
|
|
|
|
+ // dsm($item, 'item');
|
|
|
|
+ return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 4);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function materio_search_api_get_taxonomy_terms_others_tid($item){
|
|
|
|
+ // dsm($item, 'item');
|
|
|
|
+ $delta = 5;
|
|
|
|
+ $terms = array();
|
|
|
|
+ while( isset($item->field_onthologie['und'][$delta]) ){
|
|
|
|
+ $terms[] = materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", $delta);
|
|
|
|
+ $delta++;
|
|
|
|
+ }
|
|
|
|
+ return $terms;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function materio_search_api_get_taxo_term_field_tid($item, $field_name, $delta){
|
|
|
|
+ // dsm($item, 'item');
|
|
|
|
+ // dsm($delta, 'delta');
|
|
|
|
+ $tid = null;
|
|
|
|
+ if(isset($item->{$field_name}['und'][$delta]))
|
|
|
|
+ $tid = $item->{$field_name}['und'][$delta]['tid'];
|
|
|
|
+
|
|
|
|
+ // print 'tid = '.$tid."\n";
|
|
|
|
+ return $tid;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+*
|
|
|
|
+*/
|
|
function materio_search_api_get_node_propertie_companie($item){
|
|
function materio_search_api_get_node_propertie_companie($item){
|
|
// dsm($item, '$item');
|
|
// dsm($item, '$item');
|
|
$lang = "fr";//$item->language;
|
|
$lang = "fr";//$item->language;
|
|
@@ -507,7 +573,20 @@ function materio_search_api_search_form($form, &$form_state){
|
|
|
|
|
|
$args = arg();
|
|
$args = arg();
|
|
$path = array_shift($args);
|
|
$path = array_shift($args);
|
|
- $keys = implode('/', $args);
|
|
|
|
|
|
+ // dsm($args, 'args');
|
|
|
|
+ if($args[0] == "advanced"){
|
|
|
|
+ $advanced = true;
|
|
|
|
+ array_shift($args);
|
|
|
|
+ // dsm($args, 'shifted arsg');
|
|
|
|
+ // foreach ($args as $arg) {
|
|
|
|
+ // $typed[] = $arg;//(integer)$arg;
|
|
|
|
+ // }
|
|
|
|
+ $keys = implode(' +', $args);
|
|
|
|
+ }else{
|
|
|
|
+ $keys = implode('/', $args);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
if(user_access('use materio search api autocomplete')){ // use materio search api autocomplete | use materio search api filters
|
|
if(user_access('use materio search api autocomplete')){ // use materio search api autocomplete | use materio search api filters
|
|
$query = new EntityFieldQuery();
|
|
$query = new EntityFieldQuery();
|
|
@@ -523,7 +602,6 @@ function materio_search_api_search_form($form, &$form_state){
|
|
$form['searchfield'] = array(
|
|
$form['searchfield'] = array(
|
|
'#type' => 'textfield',
|
|
'#type' => 'textfield',
|
|
'#default_value' => $path == 'explore' ? $keys : $default_value, // TODO: set the search page path global or a variable in settings
|
|
'#default_value' => $path == 'explore' ? $keys : $default_value, // TODO: set the search page path global or a variable in settings
|
|
- // '#value' => $keys,
|
|
|
|
'#autocomplete_path' => 'materiosearchapi/autocomplete/searchapi',
|
|
'#autocomplete_path' => 'materiosearchapi/autocomplete/searchapi',
|
|
//'#autocomplete_path' => 'materiosearchapi/autocomplete/dbselect',
|
|
//'#autocomplete_path' => 'materiosearchapi/autocomplete/dbselect',
|
|
'#size' => 30,
|
|
'#size' => 30,
|
|
@@ -604,7 +682,22 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
// dsm($form, 'form');
|
|
// dsm($form, 'form');
|
|
// global $user;
|
|
// global $user;
|
|
|
|
|
|
- $form = array();
|
|
|
|
|
|
+ $keys = arg();
|
|
|
|
+ $path = array_shift($keys);
|
|
|
|
+ // dsm($keys, 'keys');
|
|
|
|
+ if($path == 'explore' && $keys[0] == "advanced"){
|
|
|
|
+ $advanced = true;
|
|
|
|
+ array_shift($keys);
|
|
|
|
+ $default_keys = $keys;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $form = array(
|
|
|
|
+ 'title' => array(
|
|
|
|
+ '#prefix' => "<h2>",
|
|
|
|
+ '#markup' => t("Advanced Search"),
|
|
|
|
+ '#suffix' => "</h2>",
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
|
|
$vocabularies = variable_get('advancedsearchvocs', array());
|
|
$vocabularies = variable_get('advancedsearchvocs', array());
|
|
|
|
|
|
@@ -621,30 +714,20 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
$tree = taxonomy_get_tree($vid, 0, 1);
|
|
$tree = taxonomy_get_tree($vid, 0, 1);
|
|
// dsm($tree, 'tree');
|
|
// dsm($tree, 'tree');
|
|
|
|
|
|
- # don't know how to add parent term condition
|
|
|
|
- // $query = new EntityFieldQuery();
|
|
|
|
- // $result = $query->entityCondition('entity_type', 'taxonomy_term')
|
|
|
|
- // ->propertyCondition('vid', $vid)
|
|
|
|
- // // ->propertyCondition('parent', 0)
|
|
|
|
- // // ->fieldCondition('field_used_on_advanced_search', 'value', 0, "!=")
|
|
|
|
- // ->propertyOrderBy('weight')
|
|
|
|
- // ->execute();
|
|
|
|
-
|
|
|
|
- // dsm($result, 'result');
|
|
|
|
-
|
|
|
|
- // if (!empty($result['taxonomy_term'])) {
|
|
|
|
-
|
|
|
|
- // }
|
|
|
|
|
|
+ if(!count($tree))
|
|
|
|
+ continue;
|
|
|
|
|
|
foreach ($tree as $term) {
|
|
foreach ($tree as $term) {
|
|
$term = taxonomy_term_load($term->tid);
|
|
$term = taxonomy_term_load($term->tid);
|
|
// 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);
|
|
$children = taxonomy_get_children($term->tid, $vid);
|
|
// dsm($children, "children");
|
|
// dsm($children, "children");
|
|
|
|
|
|
|
|
+ if($term->field_used_on_advanced_search['und'][0]['value'] == 0
|
|
|
|
+ || !count($children))
|
|
|
|
+ continue;
|
|
|
|
+
|
|
$form['tree-'.$term->tid] = array(
|
|
$form['tree-'.$term->tid] = array(
|
|
'#type' => 'fieldset',
|
|
'#type' => 'fieldset',
|
|
// '#title' => $term->name,
|
|
// '#title' => $term->name,
|
|
@@ -652,15 +735,17 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
'#tree' => true,
|
|
'#tree' => true,
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ $placeholder = t("Select an option");
|
|
$form['tree-'.$term->tid]['children'] = array(
|
|
$form['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"=>"-Please select-",
|
|
|
|
|
|
+ "title"=>$placeholder,
|
|
|
|
+ "data-placeholder" => $placeholder,
|
|
), //, "form-control"
|
|
), //, "form-control"
|
|
'#theme_wrappers' => array('materio_search_api_form_element'),
|
|
'#theme_wrappers' => array('materio_search_api_form_element'),
|
|
- '#empty_option' => '-Please select-',
|
|
|
|
|
|
+ '#empty_option' => $placeholder,
|
|
'#empty_value' => 1,
|
|
'#empty_value' => 1,
|
|
);
|
|
);
|
|
|
|
|
|
@@ -677,7 +762,10 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
if(count($children2))
|
|
if(count($children2))
|
|
$options[$tid] = $child->name;
|
|
$options[$tid] = $child->name;
|
|
|
|
|
|
|
|
+ $classes2 = array("treelevel2", $child->tid);
|
|
|
|
+
|
|
$options2 = [];
|
|
$options2 = [];
|
|
|
|
+ $dflt_values2 = [];
|
|
foreach ($children2 as $tid2 => $child2) {
|
|
foreach ($children2 as $tid2 => $child2) {
|
|
// $child2 = taxonomy_term_load($child2->tid);
|
|
// $child2 = taxonomy_term_load($child2->tid);
|
|
// if($child2->field_used_on_advanced_search['und'][0]['value'] == 0){
|
|
// if($child2->field_used_on_advanced_search['und'][0]['value'] == 0){
|
|
@@ -685,31 +773,40 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
// }
|
|
// }
|
|
|
|
|
|
$options2[$tid2] = $child2->name;
|
|
$options2[$tid2] = $child2->name;
|
|
|
|
+
|
|
|
|
+ // default Values
|
|
|
|
+ if(in_array($tid2, $default_keys))
|
|
|
|
+ $dflt_values2[] = $tid2;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- if(count($options2))
|
|
|
|
|
|
+ if(count($options2)){
|
|
|
|
+
|
|
|
|
+ if(count($dflt_values2))
|
|
|
|
+ $classes2[] = 'visible';
|
|
|
|
+
|
|
$form['tree-'.$term->tid]['tid-'.$child->tid] = array(
|
|
$form['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" => array("treelevel2", $child->tid), // , "form-control"
|
|
|
|
|
|
+ "class" => $classes2, // , "form-control"
|
|
"title" => "-Please select-",
|
|
"title" => "-Please select-",
|
|
|
|
+ "tid" => $child->tid,
|
|
),
|
|
),
|
|
'#theme_wrappers' => array('materio_search_api_form_element'),
|
|
'#theme_wrappers' => array('materio_search_api_form_element'),
|
|
- '#empty_option' => '-Please select-',
|
|
|
|
- '#empty_value' => 1,
|
|
|
|
|
|
+ // '#empty_option' => '-Please select-',
|
|
|
|
+ // '#empty_value' => 1,
|
|
'#options' => $options2,
|
|
'#options' => $options2,
|
|
|
|
+ '#default_value' => $dflt_values2,
|
|
);
|
|
);
|
|
-
|
|
|
|
- // $form['tree-'.$term->tid]['child-'.$tid] = array(
|
|
|
|
- // '#type' => 'checkbox',
|
|
|
|
- // '#title' => $child->name,
|
|
|
|
- // // '#options' => $options,
|
|
|
|
- // );
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(count($options)){
|
|
|
|
+ $form['tree-'.$term->tid]['children']['#options'] = $options;
|
|
|
|
+ }else{
|
|
|
|
+ unset($form['tree-'.$term->tid]);
|
|
}
|
|
}
|
|
- $form['tree-'.$term->tid]['children']['#options'] = $options;
|
|
|
|
- // break;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -735,30 +832,22 @@ function materio_search_api_advanced_search_form_validate($form, &$form_state){
|
|
}
|
|
}
|
|
|
|
|
|
function materio_search_api_advanced_search_form_submit($form, &$form_state){
|
|
function materio_search_api_advanced_search_form_submit($form, &$form_state){
|
|
- // dsm($form_state, 'form_state');
|
|
|
|
- // global $user;
|
|
|
|
- // if(user_access('use materio search api filters')){
|
|
|
|
- // foreach($form_state['values']['bundles_filter'] as $bundle => $value)
|
|
|
|
- // if($value)
|
|
|
|
- // $bundles[] = $bundle;
|
|
|
|
-
|
|
|
|
- // # if no filter checked we checked them all by default
|
|
|
|
- // if(!isset($bundles))
|
|
|
|
- // foreach($form_state['values']['bundles_filter'] as $bundle => $value)
|
|
|
|
- // $bundles[] = $bundle;
|
|
|
|
- // }else{
|
|
|
|
- // # if user have no access to filters
|
|
|
|
- // $index = search_api_index_load(variable_get('mainsearchindex', -1));
|
|
|
|
- // $indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
|
|
|
-
|
|
|
|
- // foreach ($indexed_bundles as $bundle) {
|
|
|
|
- // $bundles[] = $bundle;
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // user_save($user, array("data"=>array('materiosearchapi_bundlesfilter' => $bundles)));
|
|
|
|
|
|
+ dsm($form, 'form');
|
|
|
|
+ dsm($form_state, 'form_state');
|
|
|
|
+ $fs_values = $form_state['values'];
|
|
|
|
+ dsm($fs_values, 'values');
|
|
|
|
+
|
|
|
|
+ foreach($fs_values as $tree => $values){
|
|
|
|
+ foreach ($values as $values => $selected) {
|
|
|
|
+ if(is_array($selected) && count($selected)){
|
|
|
|
+ foreach ($selected as $tid) {
|
|
|
|
+ $tids[] = $tid;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- // $form_state['redirect'] = 'explore/'.$form_state['values']['searchfield'];
|
|
|
|
|
|
+ $form_state['redirect'] = 'explore/advanced/'.implode('/', $tids);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -864,6 +953,9 @@ function materio_search_api_theme($existing, $type, $theme, $path) {
|
|
function template_preprocess_materio_search_api_search_block(&$vars){
|
|
function template_preprocess_materio_search_api_search_block(&$vars){
|
|
// dsm($vars, '$vars');
|
|
// dsm($vars, '$vars');
|
|
$vars['searchform'] = drupal_get_form("materio_search_api_search_form");
|
|
$vars['searchform'] = drupal_get_form("materio_search_api_search_form");
|
|
|
|
+ if(user_access('use materio search api advanced search')){
|
|
|
|
+ $vars['advancedsearchform'] = drupal_get_form("materio_search_api_advanced_search_form");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
|
|
function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
|
|
@@ -1074,6 +1166,12 @@ function theme_materio_search_api_form_element($variables) {
|
|
$attributes['class'][] = $value;
|
|
$attributes['class'][] = $value;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ foreach ($element['#attributes'] as $attr => $value) {
|
|
|
|
+ if(!in_array($attr, array('class', 'multiple', 'id', 'type', 'name'))){
|
|
|
|
+ $attributes[$attr] = $value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
$output = '<div' . drupal_attributes($attributes) . '>' . "\n";
|
|
$output = '<div' . drupal_attributes($attributes) . '>' . "\n";
|
|
|
|
|
|
|
|
|