function oa_core_user_spaces_render in Open Atrium Core 7.2
Render callback for the content visibility panel.
1 string reference to 'oa_core_user_spaces_render'
- oa_core_user_spaces.inc in plugins/
content_types/ oa_core_user_spaces.inc - Defines the space summary panels pane.
File
- plugins/
content_types/ oa_core_user_spaces.inc, line 40 - Defines the space summary panels pane.
Code
function oa_core_user_spaces_render($subtype, $conf, $args, $context = NULL) {
if (empty($context->data) || !user_access('access content')) {
return;
}
$account = $context->data;
$vars = array();
if (isset($conf['types'])) {
$group_types = array_filter($conf['types']);
}
else {
$group_types = array(
OA_SPACE_TYPE => OA_SPACE_TYPE,
);
}
$status = !empty($conf['only_published']) ? NODE_PUBLISHED : NULL;
$all_spaces_ids = oa_core_get_public_spaces($group_types, $status);
$active_spaces_ids = array();
foreach ($group_types as $type) {
$active_spaces_ids = array_merge($active_spaces_ids, oa_core_get_groups_by_user_access($account, FALSE, $status, NULL, NULL, $type));
}
$active_spaces_ids = array_map(function ($node) {
return $node->nid;
}, $active_spaces_ids);
$all_spaces_ids = array_merge($all_spaces_ids, $active_spaces_ids);
$all_spaces_nodes = node_load_multiple($all_spaces_ids);
$all_spaces = oa_core_build_space_display($all_spaces_nodes, $conf, $account, $group_types);
$active_spaces_nodes = node_load_multiple($active_spaces_ids);
$active_spaces = oa_core_build_space_display($active_spaces_nodes, $conf, $account, $group_types);
$featured_spaces = array();
if (module_exists('oa_favorites')) {
$spaces = oa_favorites_get_spaces($account);
$featured_spaces_nodes = node_load_multiple($spaces['ids']);
$featured_spaces = oa_core_build_space_display($featured_spaces_nodes, $conf, $account, $group_types);
}
$archived_spaces = array();
if (module_exists('oa_archive') && ($flag = flag_get_flag('trash'))) {
$query = db_select('node', 'n');
$query
->join('flagging', 'a', 'a.fid = :fid AND n.nid = a.entity_id', array(
':fid' => $flag->fid,
));
$query
->fields('n', array(
'nid',
))
->condition('n.type', $group_types, 'IN')
->addTag('node_access');
$archived_spaces_ids = $query
->execute()
->fetchCol();
$archived_spaces_nodes = node_load_multiple($archived_spaces_ids);
$archived_spaces = oa_core_build_space_display($archived_spaces_nodes, $conf, $account, $group_types);
}
$page = 0;
// set our maximum item per page
$num_per_page = $conf['num_per_page'];
$vars['space_groups'] = array();
if (isset($conf['tabs'][SPACE_TAB_ACTIVE])) {
$conf['tabs'][SPACE_TAB_MEMBERS] = $conf['tabs'][SPACE_TAB_ACTIVE];
unset($conf['tabs'][SPACE_TAB_ACTIVE]);
}
if (!empty($conf['tabs'][SPACE_TAB_FAVORITE]) && !empty($featured_spaces)) {
$vars['space_groups'][t(SPACE_TAB_FAVORITE)]['spaces'] = $featured_spaces;
}
if (!empty($conf['tabs'][SPACE_TAB_MEMBERS]) && !empty($active_spaces)) {
if (!$conf['tabs'][SPACE_TAB_ALL] && $num_per_page > 0) {
$active_spaces = array_slice($active_spaces, 0, $num_per_page);
$vars['space_groups'][t(SPACE_TAB_MEMBERS)]['pager'] = l(t('See all'), 'spaces', array(
'attributes' => array(
'class' => $conf['link_class'],
),
));
}
$vars['space_groups'][t(SPACE_TAB_MEMBERS)]['spaces'] = $active_spaces;
}
if (!empty($conf['tabs'][SPACE_TAB_ARCHIVED]) && !empty($archived_spaces)) {
$vars['space_groups'][t(SPACE_TAB_ARCHIVED)]['spaces'] = $archived_spaces;
}
if (!empty($conf['tabs'][SPACE_TAB_ALL])) {
// pager_find_page() will return the current page number
$page = pager_find_page();
// build the offset variable
$offset = $num_per_page * $page;
// initialize our pager
pager_default_initialize(count($all_spaces), $num_per_page);
$all_spaces = array_slice($all_spaces, $offset, $num_per_page);
$vars['space_groups'][t(SPACE_TAB_ALL)]['spaces'] = $all_spaces;
$vars['space_groups'][t(SPACE_TAB_ALL)]['pager'] = theme('pager');
}
if ($page > 0) {
$vars['active'] = SPACE_TAB_ALL;
}
else {
$vars['active'] = key($vars['space_groups']);
}
$vars['title_tag'] = $conf['show_description'] ? 'h4' : 'div';
$vars['main_class'] = $conf['show_description'] ? 'member-full' : 'member-sidebar';
$block = new stdClass();
$title = '';
if (!empty($group_types[OA_SPACE_TYPE])) {
$title = t('Spaces');
}
if (!empty($group_types[OA_GROUP_TYPE])) {
if (empty($title)) {
$title = t('Groups');
}
else {
$title = t('Spaces and Groups');
}
}
if (count($vars['space_groups']) == 1) {
$block->title = key($vars['space_groups']) . ' ' . $title;
}
else {
$block->title = $title;
}
$block->content = theme('oa_core_user_spaces', $vars);
return $block;
}