You are here

function redhen_relation_role_get_permissions in RedHen CRM 7

Return relation role permission for a given account and permission.

Parameters

object $account: Account.

Return value

array Permissions array.

6 calls to redhen_relation_role_get_permissions()
redhen_contact_access in modules/redhen_contact/redhen_contact.module
Checks contact access for various operations.
redhen_org_access in modules/redhen_org/redhen_org.module
Checks org access for various operations.
redhen_org_page in modules/redhen_org/includes/redhen_org.pages.inc
Page callback for org overview page.
redhen_org_page_access in modules/redhen_org/redhen_org.module
Access callback for organization list page.
redhen_relation_access in modules/redhen_relation/redhen_relation.module
Access callback for viewing and managing relations on the RedHen connection pages.

... See full list

File

modules/redhen_relation/redhen_relation.module, line 301
Redhen CRM Relation Module.

Code

function redhen_relation_role_get_permissions($account) {
  $return =& drupal_static(__FUNCTION__);
  if (!isset($return[$account->uid])) {
    $return_permissions = array();
    $contact = redhen_contact_load_by_user($account);
    if ($contact) {
      $related = redhen_relation_relations($contact, REDHEN_RELATION_AFFILIATION, TRUE);
      $relations = relation_load_multiple(array_keys($related));
      foreach ($relations as $relation_id => $relation) {
        $relation_wrapper = entity_metadata_wrapper('relation', $relation);

        // Loop through all roles on this relation.
        $redhen_relation_roles = $relation_wrapper->redhen_relation_roles
          ->value();
        foreach ($redhen_relation_roles as $redhen_relation_role) {

          // Role needs to exist.
          if ($redhen_relation_role) {
            $redhen_relation_role_wrapper = entity_metadata_wrapper('redhen_relation_role', $redhen_relation_role);
            $org_id = $related[$relation_id][0]->org_id;
            $permissions = $redhen_relation_role_wrapper->permissions
              ->value();

            // Add all permissions from all roles on this relation.
            foreach ($permissions as $permission => $value) {

              // Add permissions if set.
              if ($value) {
                $return_permissions[$org_id][$permission] = $value;
              }
            }
          }
        }
      }
    }
    $return[$account->uid] = $return_permissions;
  }
  return $return[$account->uid];
}