You are here

function oa_og_subgroups_check_access in Open Atrium Core 7.2

Check access for this group's parents.

Copy of _og_subgroups_check_access but using our functions for optomization.

See also

_og_subgroups_check_access().

1 call to oa_og_subgroups_check_access()
oa_user_access_nids in includes/oa_core.util.inc
Determine whether a user has a given privilege for groups.

File

includes/oa_core.util.inc, line 1741
Code for Utility functions for OpenAtrium spaces

Code

function oa_og_subgroups_check_access($string, $group_type, $id, $user_groups, $check_member_access = FALSE) {

  // Check only one level at a time due to permission inheritance field.
  if ($parent_groups = og_subgroups_intersect_groups(og_subgroups_parents_load($group_type, $id, TRUE, FALSE), $user_groups)) {
    foreach ($parent_groups as $parent_group_type => $ids) {

      // Find all groups that ahve inheritence set to child (assume inherit
      // [default] otherwise).
      $child_inheritence = _og_subgroups_get_field_matching($parent_group_type, $ids, OG_USER_INHERITANCE_PERMISSION_FIELD, OG_USER_INHERITANCE_PERMISSION_CHILD);
      $parent_inheritence = array_diff($ids, $child_inheritence);
      if ($parent_inheritence = array_diff($ids, $child_inheritence)) {
        if (array_filter(oa_user_access_nids($parent_group_type, $parent_inheritence, $string, NULL, TRUE))) {
          return TRUE;
        }
      }
      if ($check_member_access) {
        foreach ($child_inheritence as $parent_group_id) {
          if (og_subgroups_check_member_user_access($group_type, $id, $string)) {
            return TRUE;
          }
        }
      }

      // Check parents if neither current nor member gave access.
      foreach ($parent_inheritence as $parent_group_id) {
        if (oa_og_subgroups_check_access($string, $parent_group_type, $parent_group_id, $user_groups)) {
          return TRUE;
        }
      }
    }
  }
  return FALSE;
}