function oa_core_space_sections in Open Atrium Core 7.2
Return a list of sections within a space Uses access control, so only sections with access are returned
Parameters
int $gid space ID:
int $status NULL for any status, otherwise specify status to return:
bool $bypass_access_check, TRUE to bypass access control:
array $fields, array of additional fields to return, otherwise just title: fields array has format fieldname|column. e.g., field_oa_space|tid
bool $include_archived Whether to include archived nodes or not:
Return value
array of section data: $array[$nid] = $title. If $fields is specified the return array is the full associative array of nid, title, fields
4 calls to oa_core_space_sections()
- oa_core_build_space_display in plugins/
content_types/ oa_core_user_spaces.inc - Builds display variables for spaces. Optionally sections as well.
- oa_core_form_views_exposed_form_alter in ./
oa_core.module - Implements hook_form_FORM_ID_alter().
- oa_core_oa_section_ref_process in includes/
oa_core.fields.inc - Process function of the oa_section_ref field.
- _oa_buttons_get_space_command_buttons in modules/
oa_buttons/ oa_buttons.module - Get the command buttons allowed by a single space, as well as any sections within it.
File
- includes/
oa_core.util.inc, line 943 - Code for Utility functions for OpenAtrium spaces
Code
function oa_core_space_sections($gid, $status = NULL, $bypass_access_check = FALSE, $fields = array(), $include_archived = FALSE) {
$query = db_select('node', 'n');
$query
->rightJoin('og_membership', 'og', 'n.nid = og.etid');
$query
->leftJoin('field_data_field_oa_section_weight', 'w', "n.nid = w.entity_id AND w.entity_type = 'node'");
$extra_fields = array();
foreach ($fields as $field) {
if (strpos($field, 'field_') === 0 || strpos($field, '|') !== FALSE) {
$field_list = explode('|', $field);
$field_name = $field_list[0];
$column = !empty($field_list[1]) ? $field_list[1] : 'value';
$query
->leftJoin('field_data_' . $field_name, $field_name, 'n.nid = ' . $field_name . '.entity_id');
$query
->fields($field_name, array(
$field_name . '_' . $column,
));
}
else {
$extra_fields[] = $field;
}
}
if (isset($status)) {
$query
->condition('n.status', $status);
}
$query
->fields('n', array(
'nid',
'title',
) + $extra_fields)
->condition('n.type', OA_SECTION_TYPE)
->condition('og.entity_type', 'node')
->condition('og.field_name', OA_SPACE_FIELD)
->condition('og.gid', $gid)
->orderBy('w.field_oa_section_weight_value')
->orderBy('n.title');
if (!$bypass_access_check) {
$query
->addTag('node_access');
}
if (module_exists('flag') && !$include_archived) {
if ($flag = flag_get_flag('trash')) {
$query
->leftJoin('flagging', 'a', "a.fid = :fid AND a.entity_id = n.nid", array(
':fid' => $flag->fid,
));
// This makes sure that archived content isn't included, because 'uid'
// will be NULL if the join didn't connect anything.
$query
->isNull('a.uid');
}
}
$result = $query
->execute();
if (empty($fields)) {
return $result
->fetchAllKeyed(0, 1);
}
else {
return $result
->fetchAllAssoc('nid');
}
}