You are here

function pmorganization_node_grants in Drupal PM (Project Management) 7

Implements hook_node_grants().

File

pmorganization/pmorganization.module, line 615

Code

function pmorganization_node_grants($account, $op) {
  $is_pmperson = FALSE;
  if (!isset($account->pmorganization_nid) && module_exists('pmperson')) {
    _pmperson_user_load($account);
  }
  if (isset($account->pmperson_nid) and $account->pmperson_nid > 0) {
    $is_pmperson = TRUE;
  }
  $grants = array();
  switch ($op) {
    case 'view':
      if (user_access('Project Management Organization: view all', $account)) {
        $grants['pmorganization_view_all'] = array(
          0,
        );
      }
      if (user_access('Project Management Organization: view own', $account)) {
        $grants['pmorganization_view_own'] = array(
          $account->uid,
        );
      }
      if ($is_pmperson) {
        if (user_access('Project Management Organization: view belonged', $account)) {
          $grants['pmorganization_view_if_user_org'] = array(
            $account->pmorganization_nid,
          );
        }
      }
      break;
    case 'update':
      if (user_access('Project Management Organization: edit all', $account)) {
        $grants['pmorganization_update_all'] = array(
          0,
        );
      }
      if (user_access('Project Management Organization: edit own', $account)) {
        $grants['pmorganization_update_own'] = array(
          $account->uid,
        );
      }
      if ($is_pmperson) {
        if (user_access('Project Management Organization: edit belonged', $account)) {
          $grants['pmorganization_update_if_user_org'] = array(
            $account->pmorganization_nid,
          );
        }
      }
      break;
    case 'delete':
      if (user_access('Project Management Organization: delete all', $account)) {
        $grants['pmorganization_delete_all'] = array(
          0,
        );
      }
      if (user_access('Project Management Organization: delete own', $account)) {
        $grants['pmorganization_delete_own'] = array(
          $account->uid,
        );
      }
      break;
  }
  return $grants;
}