|
@@ -180,30 +180,47 @@ function materio_search_api_entity_property_info_alter(&$info){
|
|
|
|
|
|
$node_props = &$info['node']['properties'];
|
|
$node_props = &$info['node']['properties'];
|
|
|
|
|
|
- for ($i=1; $i <= 5 ; $i++) {
|
|
|
|
- $node_props['materio_search_api_onthologie_term_'.$i.'_text'] = array(
|
|
|
|
- 'type'=>'text',
|
|
|
|
- 'label'=> t('Main onthologie term '.$i. ' as text (+ synonyms)'),
|
|
|
|
- 'getter callback'=>'materio_search_api_get_onthologie_term_'.$i.'_text',
|
|
|
|
|
|
+ $fields = msa_get_custom_onto_taxo_searchable_fields();
|
|
|
|
+
|
|
|
|
+ foreach ($fields['termname'] as $field) {
|
|
|
|
+ $node_props[$field['name']] = array(
|
|
|
|
+ 'type'=>$field['type'],
|
|
|
|
+ 'label'=> $field['label'],
|
|
|
|
+ 'getter callback'=>$field['getter']
|
|
);
|
|
);
|
|
- $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',
|
|
|
|
|
|
+ }
|
|
|
|
+ foreach ($fields['tid'] as $field) {
|
|
|
|
+ $node_props[$field['name']] = array(
|
|
|
|
+ 'type'=>$field['type'],
|
|
|
|
+ 'label'=> $field['label'],
|
|
|
|
+ 'getter callback'=>$field['getter']
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- $node_props['materio_search_api_onthologie_term_others_text'] = array(
|
|
|
|
- 'type'=>'list<text>',
|
|
|
|
- 'label'=> t('Others onthologie terms as text (+ synonyms)'),
|
|
|
|
- 'getter callback'=>'materio_search_api_get_taxonomy_terms_others_text',
|
|
|
|
- );
|
|
|
|
|
|
+ // for ($i=1; $i <= 5 ; $i++) {
|
|
|
|
+ // $node_props['materio_search_api_onthologie_term_'.$i.'_text'] = array(
|
|
|
|
+ // 'type'=>'text',
|
|
|
|
+ // 'label'=> t('Main onthologie term '.$i. ' as text (+ synonyms)'),
|
|
|
|
+ // '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(
|
|
|
|
+ // 'type'=>'list<text>',
|
|
|
|
+ // 'label'=> t('Others onthologie terms as text (+ synonyms)'),
|
|
|
|
+ // '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_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>',
|
|
@@ -211,7 +228,6 @@ function materio_search_api_entity_property_info_alter(&$info){
|
|
'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(
|
|
@@ -220,7 +236,6 @@ function materio_search_api_entity_property_info_alter(&$info){
|
|
'getter callback'=>'materio_search_api_get_node_propertie_companie',
|
|
'getter callback'=>'materio_search_api_get_node_propertie_companie',
|
|
);
|
|
);
|
|
|
|
|
|
-
|
|
|
|
// TAXONOMIE TERMS PROPERTIES
|
|
// TAXONOMIE TERMS PROPERTIES
|
|
|
|
|
|
$term_props = &$info['taxonomy_term']['properties'];
|
|
$term_props = &$info['taxonomy_term']['properties'];
|
|
@@ -239,6 +254,38 @@ function materio_search_api_entity_property_info_alter(&$info){
|
|
// );
|
|
// );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+function msa_get_custom_onto_taxo_searchable_fields(){
|
|
|
|
+
|
|
|
|
+ for ($i=1; $i <= 5 ; $i++) {
|
|
|
|
+ $fields_name['termname'][] = array(
|
|
|
|
+ 'type' => 'text',
|
|
|
|
+ 'name' => 'materio_search_api_onthologie_term_'.$i.'_text',
|
|
|
|
+ 'label' => t('Main onthologie term '.$i. ' as text (+ synonyms)'),
|
|
|
|
+ 'getter' => 'materio_search_api_get_onthologie_term_'.$i.'_text'
|
|
|
|
+ );
|
|
|
|
+ $fields_name['tid'][] = array(
|
|
|
|
+ 'type' => 'text',
|
|
|
|
+ 'name' => 'materio_search_api_onthologie_term_'.$i.'_tid',
|
|
|
|
+ 'label' => t('Main onthologie term '.$i. ' as tid'),
|
|
|
|
+ 'getter' => 'materio_search_api_get_onthologie_term_'.$i.'_tid'
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $fields_name['termname'][] = array(
|
|
|
|
+ 'type'=>'list<text>',
|
|
|
|
+ 'name' => 'materio_search_api_onthologie_term_others_text',
|
|
|
|
+ 'label' => t('Others onthologie terms as text (+ synonyms)'),
|
|
|
|
+ 'getter' => 'materio_search_api_get_taxonomy_terms_others_text'
|
|
|
|
+ );
|
|
|
|
+ $fields_name['tid'][] = array(
|
|
|
|
+ 'type'=>'list<text>',
|
|
|
|
+ 'name' => 'materio_search_api_onthologie_term_others_tid',
|
|
|
|
+ 'label' => t('Others onthologie terms as tid'),
|
|
|
|
+ 'getter' => 'materio_search_api_get_taxonomy_terms_others_tid'
|
|
|
|
+ );
|
|
|
|
+ return $fields_name;
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* taxonomy propoerties as text + synonymes
|
|
* taxonomy propoerties as text + synonymes
|
|
*/
|
|
*/
|
|
@@ -750,9 +797,11 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
// global $user;
|
|
// global $user;
|
|
// $form = array();
|
|
// $form = array();
|
|
|
|
|
|
- // TODO: get vid from settings
|
|
|
|
|
|
+ // get vid from settings
|
|
$vid = variable_get('msa-advancedsearchvocabulary', null);
|
|
$vid = variable_get('msa-advancedsearchvocabulary', null);
|
|
if($vid){
|
|
if($vid){
|
|
|
|
+ // global $language;
|
|
|
|
+ // dsm($language, "language");
|
|
|
|
|
|
$voc = taxonomy_vocabulary_load($vid);
|
|
$voc = taxonomy_vocabulary_load($vid);
|
|
$voc_machinename = $voc->machine_name;
|
|
$voc_machinename = $voc->machine_name;
|
|
@@ -775,18 +824,33 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
// get the keywords from args and reconstruct the filter lines with default values
|
|
// get the keywords from args and reconstruct the filter lines with default values
|
|
$args_values = array();
|
|
$args_values = array();
|
|
if($path == 'explore/filters' && $args[0] !== "ajax"){
|
|
if($path == 'explore/filters' && $args[0] !== "ajax"){
|
|
- $keywords = explode("+", $args[0]);
|
|
|
|
- // TODO: what if a keyword contains a +
|
|
|
|
- // 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);
|
|
|
|
|
|
+ // 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) {
|
|
|
|
+ $term = taxonomy_term_load($tid);
|
|
// dsm($term, $term->tid.' : '.$term->name);
|
|
// dsm($term, $term->tid.' : '.$term->name);
|
|
// get parents
|
|
// get parents
|
|
if(isset($term->tid)){
|
|
if(isset($term->tid)){
|
|
- $parents = taxonomy_get_parents_all($term->tid);
|
|
|
|
|
|
+ $parents = taxonomy_get_parents_all($tid);
|
|
// dsm($parents, 'parents');
|
|
// dsm($parents, 'parents');
|
|
// build default values
|
|
// build default values
|
|
for ($p=count($parents)-1; $p >=0 ; $p--) {
|
|
for ($p=count($parents)-1; $p >=0 ; $p--) {
|
|
@@ -843,11 +907,14 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
}
|
|
}
|
|
|
|
|
|
// build first level taxonomy tree and select options
|
|
// build first level taxonomy tree and select options
|
|
- $taxotree = taxonomy_get_tree($vid, 0, 1, false);
|
|
|
|
|
|
+ $taxotree = taxonomy_get_tree($vid, 0, 1, true);
|
|
|
|
+ // $taxotree = msa_get_taxo_tree($vid, 0, 1);
|
|
|
|
+ // dsm($taxotree, "taxotree");
|
|
|
|
+ // return $form;
|
|
foreach ($taxotree as $index => $term) {
|
|
foreach ($taxotree as $index => $term) {
|
|
// TODO: get translated tag name
|
|
// TODO: get translated tag name
|
|
if(!in_array($term->tid, $hidden_terms)){
|
|
if(!in_array($term->tid, $hidden_terms)){
|
|
- $level_0_ops[$term->tid] = t($term->name);
|
|
|
|
|
|
+ $level_0_ops[$term->tid] = $term->name;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -909,11 +976,13 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
if($default0){
|
|
if($default0){
|
|
|
|
|
|
// build second level taxonomy tree and select options
|
|
// build second level taxonomy tree and select options
|
|
- $taxotree1 = taxonomy_get_tree($vid, $default0, 1, false);
|
|
|
|
|
|
+ $taxotree1 = taxonomy_get_tree($vid, $default0, 1, true);
|
|
|
|
+ // dsm($taxotree1, 'taxotree1');
|
|
$level_1_ops = array();
|
|
$level_1_ops = array();
|
|
foreach ($taxotree1 as $index => $term) {
|
|
foreach ($taxotree1 as $index => $term) {
|
|
// TODO: get translated tag name
|
|
// TODO: get translated tag name
|
|
- $level_1_ops[$term->tid] = t($term->name);
|
|
|
|
|
|
+ // $term = taxonomy_term_load($tid);
|
|
|
|
+ $level_1_ops[$term->tid] = $term->name;
|
|
}
|
|
}
|
|
|
|
|
|
// get the default value
|
|
// get the default value
|
|
@@ -948,7 +1017,7 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
if($default1){
|
|
if($default1){
|
|
|
|
|
|
// build second level taxonomy tree and select options
|
|
// build second level taxonomy tree and select options
|
|
- $taxotree2 = taxonomy_get_tree($vid, $default1, 1, false);
|
|
|
|
|
|
+ $taxotree2 = taxonomy_get_tree($vid, $default1, 1, true);
|
|
if(count($taxotree2)){
|
|
if(count($taxotree2)){
|
|
// $default2 = isset($args_values[$l][2]) ? $args_values[$l][2] : 0;
|
|
// $default2 = isset($args_values[$l][2]) ? $args_values[$l][2] : 0;
|
|
$default2 = null;
|
|
$default2 = null;
|
|
@@ -1052,6 +1121,36 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
|
return $form;
|
|
return $form;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+function msa_get_taxo_tree($vid, $parent, $depth){
|
|
|
|
+ $query = new EntityFieldQuery();
|
|
|
|
+ $query->entityCondition('entity_type', 'taxonomy_term')
|
|
|
|
+ ->propertyCondition('vid', $vid);
|
|
|
|
+ // ->propertyCondition('parent', $parent);
|
|
|
|
+ // ->propertyCondition('status', 1);
|
|
|
|
+ // ->entityCondition('bundle', $voc_machinename)
|
|
|
|
+
|
|
|
|
+ $result = $query->execute();
|
|
|
|
+
|
|
|
|
+ if (isset($result['taxonomy_term'])) {
|
|
|
|
+ $terms = $result['taxonomy_term'];
|
|
|
|
+
|
|
|
|
+ // At first we need to get field's id. If you already know field id, you can ommit this step
|
|
|
|
+ // Get all fields attached to a given node type
|
|
|
|
+ $fields = field_info_instances('taxonomy_term');
|
|
|
|
+
|
|
|
|
+ // Get id of body field
|
|
|
|
+ // $field_id = $fields['name']['field_id'];
|
|
|
|
+
|
|
|
|
+ // Attach a field of selected id only to get value for it
|
|
|
|
+ field_attach_load('taxonomy_term', $terms, FIELD_LOAD_CURRENT, array('field_id' => 'name'));
|
|
|
|
+
|
|
|
|
+ // Get values of our node field
|
|
|
|
+ // $output = field_get_items('node', $stories, 'field_story_image');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $terms;
|
|
|
|
+}
|
|
|
|
+
|
|
function materio_search_api_advanced_search_select_callback($form, &$form_state) {
|
|
function materio_search_api_advanced_search_select_callback($form, &$form_state) {
|
|
return $form['filters'];
|
|
return $form['filters'];
|
|
}
|
|
}
|
|
@@ -1078,14 +1177,16 @@ function materio_search_api_advanced_search_form_submit($form, &$form_state){
|
|
|
|
|
|
$values = $form_state['values'];
|
|
$values = $form_state['values'];
|
|
$filterlines = isset($form_state['filterlines']) ? $form_state['filterlines'] : 0;
|
|
$filterlines = isset($form_state['filterlines']) ? $form_state['filterlines'] : 0;
|
|
- $keywords = array();
|
|
|
|
|
|
+ // $keywords = array();
|
|
|
|
|
|
// extract last tag of each lines
|
|
// extract last tag of each lines
|
|
for ($l=0; $l < $filterlines ; $l++) {
|
|
for ($l=0; $l < $filterlines ; $l++) {
|
|
for ($i=2; $i > 0 ; $i--) {
|
|
for ($i=2; $i > 0 ; $i--) {
|
|
if(isset($values['filter-'.$l.'-'.$i]) && $values['filter-'.$l.'-'.$i]){
|
|
if(isset($values['filter-'.$l.'-'.$i]) && $values['filter-'.$l.'-'.$i]){
|
|
- $term = taxonomy_term_load($values['filter-'.$l.'-'.$i]);
|
|
|
|
- $keywords[$term->tid] = '"'.$term->name.'"';
|
|
|
|
|
|
+ // $term = taxonomy_term_load($values['filter-'.$l.'-'.$i]);
|
|
|
|
+ // $keywords[$term->tid] = '"'.$term->name.'"';
|
|
|
|
+ // $tids[] = '"'.$values['filter-'.$l.'-'.$i].'"';
|
|
|
|
+ $tids[] = $values['filter-'.$l.'-'.$i];
|
|
continue 2;
|
|
continue 2;
|
|
}else{
|
|
}else{
|
|
continue;
|
|
continue;
|
|
@@ -1095,7 +1196,7 @@ function materio_search_api_advanced_search_form_submit($form, &$form_state){
|
|
|
|
|
|
// dsm($keywords, 'keywordstid');
|
|
// dsm($keywords, 'keywordstid');
|
|
|
|
|
|
- $keywords_str = implode("+", $keywords);
|
|
|
|
|
|
+ $keywords_str = implode("+", $tids);
|
|
|
|
|
|
// dsm($keywords_str);
|
|
// dsm($keywords_str);
|
|
|
|
|