function oa_sitemap_spaces in Open Atrium Sitemap 7.2
Main helper function to grab all the spaces for the sitemap.
@returns An array of data
Parameters
$node: Node object or nid to load for, or 0 for top level.
$spaces: Array by reference to be filled with space listing
$seen_nids: An array of NIDS that don't need to be reprocessed.
$parent_child_depth: We want to load the current level and it's parents children for proper movement in sitemap, this is an internal value that manages that.
$override_parent_id: Set the parent ID to this.
1 call to oa_sitemap_spaces()
- oa_sitemap_spaces_callback in ./
oa_sitemap.module - JSON callback to return space/subspace/section data for a given space node
File
- ./
oa_sitemap.module, line 229
Code
function oa_sitemap_spaces($node, &$spaces, $seen_nids = array(), $parent_child_depth = 2, $override_parent_id = 0) {
global $user;
if (is_numeric($node) && $node > 0) {
$node = node_load($node);
}
$nid = $node ? $node->nid : 0;
$new_space = empty($node) ? user_access('create ' . OA_SPACE_TYPE . ' content', $user) : module_exists('oa_subspaces') && og_user_access('node', $nid, 'create ' . OA_SPACE_TYPE . ' content', $user);
$visibility = 1;
$admin_access = empty($node) ? $new_space : node_access('update', $node);
$section_links = array();
// Make sure not already processed, as may be working up the tree to get
// parent's children.
if (!empty($spaces[$nid]) && !$parent_child_depth) {
return;
}
if ($node) {
$visibility = field_get_items('node', $node, 'group_access');
$visibility = $visibility[0]['value'];
$sections = oa_core_space_sections($nid, NODE_PUBLISHED, FALSE, array(
'field_oa_section|tid',
'field_oa_group_ref|target_id',
'field_oa_team_ref|target_id',
'field_oa_user_ref|target_id',
));
foreach ($sections as $section) {
$id = $section->field_oa_section_tid;
if (empty($id)) {
$term = taxonomy_get_term_by_name('Default', 'section_type');
$id = !empty($term) ? current(array_keys($term)) : 0;
}
$section_links[] = array(
'nid' => $section->nid,
'parent_id' => $nid == 0 ? -1 : $nid,
'type' => OA_SECTION_TYPE,
'title' => $section->title,
'url' => url('node/' . $section->nid),
'url_edit' => url('node/' . $section->nid . '/edit'),
//don't have a full section node, so can't call node_access('update',section)
//so use the parent's admin access
'admin' => $admin_access,
'visibility' => empty($section->field_oa_group_ref_target_id) && empty($section->field_oa_team_ref_target_id) && empty($section->field_oa_user_ref_target_id),
'icon_id' => $id,
'token' => drupal_get_token('sitemap-node-' . $section->nid),
);
}
$parents = field_get_items('node', $node, 'oa_parent_space');
$spaces[$nid] = array(
'nid' => $nid,
'parent_id' => $override_parent_id ? $override_parent_id : ($parents && (($parent = node_load($parents[0]['target_id'])) && $parent->type == 'oa_space') ? $parents[0]['target_id'] : 0),
'title' => decode_entities(check_plain($node->title)),
'url' => url('node/' . $nid),
'url_edit' => url('node/' . $nid . '/edit'),
'status' => $node->status,
'new_section' => og_user_access('node', $nid, "create " . OA_SECTION_TYPE . " content", $user),
);
}
else {
$spaces[$nid] = array(
'nid' => 0,
'parent_id' => -1,
'title' => t('Site Home'),
// variable_get('site_name', t('Home')),
'url' => url('<front>'),
'url_edit' => '',
'status' => 1,
'new_section' => FALSE,
);
}
$spaces[$nid] += array(
'nid' => $nid,
'type' => OA_SPACE_TYPE,
'admin' => $admin_access,
'visibility' => $visibility,
'new_space' => $new_space,
'sections' => $section_links,
'subspaces' => array(),
'children_fetched' => $parent_child_depth > 0,
'token' => drupal_get_token('sitemap-node-' . $nid),
);
// Fetch the children.
if ($parent_child_depth > 0) {
foreach (oa_core_get_groups_by_parent($nid) as $child) {
$spaces[$nid]['subspaces'][$child] = $child;
oa_sitemap_spaces($child, $spaces, $seen_nids, 0, $nid);
}
}
// If parent_id is not in spaces, need to get it.
$parent_id = $spaces[$nid]['parent_id'];
if ($parent_id > -1 && empty($spaces[$parent_id]) && empty($seen_nids[$parent_id])) {
oa_sitemap_spaces($parent_id, $spaces, $seen_nids, $parent_child_depth ? $parent_child_depth - 1 : 0);
$spaces[$parent_id]['subspaces'][$nid] = $nid;
}
return $spaces;
}