You are here

function _pm_permission_get_assigned_id in Drupal PM (Project Management) 8

Same name and namespace in other branches
  1. 7.3 includes/pm.permission.inc \_pm_permission_get_assigned_id()

Should recursively hunt for a particular parent and get its id.

1 call to _pm_permission_get_assigned_id()
_pm_permission_grants_assigned in includes/pm.permission.inc
Generate grants for assigned permission set.

File

includes/pm.permission.inc, line 571
Main module file for the pm_permission module.

Code

function _pm_permission_get_assigned_id($node, $type, $assigned) {
  $assigned_nids = FALSE;
  switch ($assigned) {
    case 'Project Manager':
      $field_name = variable_get("pm_permission_field_pm_reference", FALSE);
      break;
    case 'Assigned':
      $field_name = variable_get("pm_permission_field_assigned_reference", FALSE);
      break;
    default:
      break;
  }
  if ($field_name) {
    try {
      $wrapper = entity_metadata_wrapper('node', $node);
      $field_info = field_info_field($field_name);
      if ($field_info['cardinality'] == 1) {
        $account = $wrapper->{$field_name}
          ->value();
        if ($account) {
          $assigned_nids[] = $account->uid;
        }
      }
      else {
        foreach ($wrapper->{$field_name}
          ->getIterator() as $account_wrapper) {
          $assigned_nids[] = $account_wrapper
            ->getIdentifier();
        }
      }
    } catch (Exception $e) {
      _pm_permission_watchdog_log($e);
    }
  }
  return $assigned_nids;
}