Commit c6759b5a authored by Jonathan Hunt's avatar Jonathan Hunt

#6 Add Place type to /places report, along with edit link.

parent e3023c82
......@@ -30,21 +30,23 @@ function climbnz_place_places() {
$output = '';
$items = _nodehierarchy_parent_options('place');
// @todo: check permissions.
$edit = false;
// @todo: get place types.
// entity field query of type indexed by nid.
$edit = user_access('edit any place content');
$place_types = climbnz_place_place_types();
$header = array(
t('Type'),
t('Place'),
);
if ($edit) {
$header[] = '<!--edit-->'; // Add column for edit
}
$rows = array();
foreach ($items as $key => $item) {
$rows[] = array(
'{type}', // $place_types[$item['field_place_type_value']],
ucfirst(check_plain($place_types[$item['nid']]->field_type_value)),
_climbnz_place_parent_option_title($item),
$edit ? l('edit', 'node/'. $item['nid'] .'/edit', array('query' => 'destination=places')) : '',
$edit ? l('edit', 'node/'. $item['nid'] .'/edit', array('query' => array('destination' => 'places'))) : '',
);
}
$output .= theme('table', array('header' => $header, 'rows' => $rows));
......@@ -53,6 +55,14 @@ function climbnz_place_places() {
return $output;
}
/**
* To avoid loading every place node, we fetch all Place type values keyed by nid.
*/
function climbnz_place_place_types() {
$result = db_query('SELECT entity_id,field_type_value FROM field_data_field_type')->fetchAllAssoc('entity_id');
return $result;
}
function climbz_place_menu_tree_output($tree) {
$output = '';
$items = array();
......@@ -91,7 +101,10 @@ function climbz_place_menu_tree_output($tree) {
* Based on _nodehierarchy_parent_option_title().
*/
function _climbnz_place_parent_option_title($item) {
return str_repeat('&nbsp;&nbsp;', $item['depth']-1) .' '. l(truncate_utf8($item['title'], 60, TRUE, FALSE), $item['link_path']);
// For some reason, unparented Places have no link_path.
$link_path = $item['link_path'] ? $item['link_path'] : 'node/' . $item['nid'];
return str_repeat('&nbsp;&nbsp;', $item['depth']-1) .' '. l(truncate_utf8($item['title'], 60, TRUE, FALSE), $link_path);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment