Skip to content

Instantly share code, notes, and snippets.

@newsomc
Created November 14, 2012 22:01
Show Gist options
  • Save newsomc/4075133 to your computer and use it in GitHub Desktop.
Save newsomc/4075133 to your computer and use it in GitHub Desktop.
function locations_events_list() {
$locations_vid = _locations_get_vid();
$locations_terms = taxonomy_get_tree($locations_vid);
/*
$loc_result = db_select('locations_term', 'lt')
->join('locations', 'l', 'l.lid = lt.lid')
->fields('lt', array('tid'))
->fields('l', array('activities'))
->isNotNull('l.activities')
->execute();*/
$loc_result = db_query('SELECT lt.tid, l.activities
FROM {locations_term} lt
JOIN {locations} l ON l.lid = lt.lid
WHERE l.activities IS NOT NULL');
// Retrieve term ids that are designated as event venues
foreach ($loc_result as $evt_locs) {
//var_dump($evt_locs);
$loc_activities = unserialize($evt_locs->activities);
if (is_array($loc_activities) && in_array('event', $loc_activities, TRUE)) {
$locations[] = array(
'tid' => $evt_locs->tid,
);
}
}
foreach ($locations_terms as $term_key => $term_values) {
foreach ($locations as $pos => $location_term) {
if ($location_term['tid'] == $term_values->tid) {
if ($term_values->depth == 1) {
$parent = taxonomy_term_load($term_values->parents[0]);
$event_options[$term_values->tid] = $parent->name . ', ' . $term_values->name;
}
elseif ($term_values->depth == 2) {
$parents = taxonomy_get_parents_all($term_values->tid);
$event_options[$term_values->tid] = $parents[2]->name . ', ' . $parents[1]->name . ', ' . $term_values->name;
}
else {
$event_options[$term_values->tid] = $term_values->name;
}
}
}
}
asort($event_options);
return $event_options;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment