Created
September 7, 2018 15:42
-
-
Save briward/3fab3f42ba6635d6faaa8b7672d97c46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function oa_core_visibility_data($node) { | |
$static = &drupal_static(__FUNCTION__, array()); | |
if (!empty($static[$node->nid])) { | |
return $static[$node->nid]; | |
} | |
$data = array(); | |
$data['published'] = !empty($node->status); | |
$data['archived'] = FALSE; | |
if (module_exists('flag')) { | |
$flag = flag_load('trash'); | |
$data['archived'] = $flag->is_flagged($node->nid); | |
} | |
if ($node->type == OA_SPACE_TYPE || $node->type == OA_GROUP_TYPE) { | |
$visibility = field_get_items('node', $node, 'group_access'); | |
$private = oa_core_get_group_privacy($node); | |
$data['public'] = !$private; | |
$data['space_public_in_private'] = $private && empty($visibility[0]['value']); | |
if (!$data['public'] && ($ids = og_subgroups_parents_load('node', $node->nid)) && !empty($ids['node'])) { | |
if ($groups = array_filter(oa_core_get_titles($ids['node'], 'oa_group', 'title', array('link'), TRUE, 0))) { | |
$data['accessors']['group'] = array( | |
'links' => $groups['links'], | |
'label' => t('Groups'), | |
); | |
} | |
if ($spaces = array_filter(oa_core_get_titles($ids['node'], 'oa_space', 'title', array('link'), TRUE, 0))) { | |
$data['accessors']['space'] = array( | |
'links' => $spaces['links'], | |
'label' => t('Spaces'), | |
); | |
} | |
} | |
} | |
else { | |
if ($node->type == OA_SECTION_TYPE) { | |
$section_node = $node; | |
} | |
else { | |
$section_reference_field = field_get_items('node', $node, OA_SECTION_FIELD); | |
if (isset($section_reference_field[0]['target_id'])) { | |
$section_node = node_load($section_reference_field[0]['target_id']); | |
} | |
} | |
if (empty($section_node)) { | |
$section_node = $node; | |
} | |
$space_reference_field = field_get_items('node', $section_node, OA_SPACE_FIELD); | |
$space_node = node_load($space_reference_field[0]['target_id']); | |
if (empty($space_node)) { | |
$data['public'] = TRUE; | |
} | |
else { | |
$space_private = oa_core_get_group_privacy($space_node); | |
$visibility = field_get_items('node', $space_node, 'group_access'); | |
$data['space_public_in_private'] = $space_private && empty($visibility[0]['value']); | |
$private = oa_core_get_group_privacy($space_reference_field[0]['target_id']); | |
$data['public'] = ((($section_node->type != OA_SECTION_TYPE) || oa_core_section_is_public($section_node)) | |
&& !$private); | |
if (!$data['public']) { | |
$spaces = _oa_core_build_visibility_links('node', $section_node, OA_GROUP_FIELD, OA_SPACE_TYPE); | |
if ($private || !empty($spaces)) { | |
$data['accessors']['space'] = array( | |
'links' => $spaces + _oa_core_build_visibility_links('node', $section_node, OA_SPACE_FIELD, OA_SPACE_TYPE), | |
'label' => t('Spaces'), | |
); | |
} | |
$spaces = _oa_core_build_visibility_links('node', $section_node, OA_GROUP_FIELD, OA_GROUP_TYPE); | |
if ($private || !empty($spaces)) { | |
$data['accessors']['group'] = array( | |
'links' => $spaces + _oa_core_build_visibility_links('node', $section_node, OA_SPACE_FIELD, OA_GROUP_TYPE), | |
'label' => t('Groups'), | |
); | |
} | |
$data['accessors']['teams'] = array( | |
'links' => _oa_core_build_visibility_links('node', $section_node, OA_TEAM_FIELD), | |
'label' => t('Teams'), | |
); | |
$data['accessors']['users'] = array( | |
'links' => _oa_core_build_visibility_links('user', $section_node, OA_USER_FIELD), | |
'label' => t('Additional Users'), | |
); | |
} | |
} | |
} | |
$data['title'] = $data['public'] ? t('Public') : t('Private'); | |
$static[$node->nid] = $data; | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment