Skip to content

Instantly share code, notes, and snippets.

@lkacenja
Created June 17, 2014 19:35
Show Gist options
  • Save lkacenja/06734409bf5fafa044d6 to your computer and use it in GitHub Desktop.
Save lkacenja/06734409bf5fafa044d6 to your computer and use it in GitHub Desktop.
<?php
function csi_api_indicator_get_data($nid) {
$values = array();
$all_data = &drupal_static(__FUNCTION__);
if (empty($all_data)) {
$all_data = array();
}
if (!empty($all_data[$nid])) {
return $all_data[$nid];
}
else {
$node = node_load($nid);
$l = $node->language;
$values = array();
if (!empty($node->field_indicator_data_table[$l][0]['value'])) {
$table_name = $node->field_indicator_data_table[$l][0]['value'];
if (!empty($node->field_indicator_result_field[$l]) && !empty($node->field_indicator_geo_id_field[$l][0]['value'])) {
$fields = array(
$node->field_indicator_result_field[$l][0]['value'],
$node->field_indicator_geo_id_field[$l][0]['value'],
);
}
$filters = array();
if (!empty($node->field_indicator_data_filters[$l])) {
foreach ($node->field_indicator_data_filters[$l] as $key => $filter) {
$filters[$filter['first']] = $filter['second'];
}
}
if (!empty($node->field_indicator_years[$l])) {
foreach($node->field_indicator_years[$l] AS $tid) {
$term = taxonomy_term_load($tid['tid']);
$table_name = $table_name . '_' . $term->name;
$values[$term->name] = data_engine_get_table($table_name, 0, '', $fields, $filters);
}
$all_data[$nid] = $values;
}
}
}
return $values;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment