You are here

function pmexpense_node_access_records in Drupal PM (Project Management) 7

Implements hook_node_access_records().

File

pmexpense/pmexpense.module, line 735
Hook implementations and main functions for PM Expense.

Code

function pmexpense_node_access_records($node) {
  if (empty($node->status)) {

    // Lets Drupal take care of permission to unpublished nodes.
    return array();
  }
  $type = is_string($node) ? $node : $node->type;
  $grants = array();
  if ($type == 'pmexpense') {

    // Project Management expense: view all
    $grants[] = array(
      'realm' => 'pmexpense_view_all',
      'gid' => 0,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
      'priority' => 0,
    );

    // Project Management expense: view own
    $grants[] = array(
      'realm' => 'pmexpense_view_own',
      'gid' => $node->uid,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
      'priority' => 0,
    );

    // Project Management expense: view of user organization
    if (isset($node->organization_nid) && !empty($node->organization_nid)) {
      $grants[] = array(
        'realm' => 'pmexpense_view_if_user_organization',
        'gid' => $node->organization_nid,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }

    // Project Management expense: edit all
    $grants[] = array(
      'realm' => 'pmexpense_update_all',
      'gid' => 0,
      'grant_view' => 0,
      'grant_update' => 1,
      'grant_delete' => 0,
      'priority' => 0,
    );

    // Project Management expense: edit own
    $grants[] = array(
      'realm' => 'pmexpense_update_own',
      'gid' => $node->uid,
      'grant_view' => 0,
      'grant_update' => 1,
      'grant_delete' => 0,
      'priority' => 0,
    );

    // Project Management expense: edit of user organization
    if (isset($node->organization_nid) && !empty($node->organization_nid)) {
      $grants[] = array(
        'realm' => 'pmexpense_update_if_user_organization',
        'gid' => $node->organization_nid,
        'grant_view' => 0,
        'grant_update' => 1,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }

    // Project Management expense: delete all
    $grants[] = array(
      'realm' => 'pmexpense_delete_all',
      'gid' => 0,
      'grant_view' => 0,
      'grant_update' => 0,
      'grant_delete' => 1,
      'priority' => 0,
    );

    // Project Management expense: delete own
    $grants[] = array(
      'realm' => 'pmexpense_delete_own',
      'gid' => $node->uid,
      'grant_view' => 0,
      'grant_update' => 0,
      'grant_delete' => 1,
      'priority' => 0,
    );

    // Project Management expense: delete of user organization
    if (isset($node->organization_nid) && !empty($node->organization_nid)) {
      $grants[] = array(
        'realm' => 'pmexpense_delete_if_user_organization',
        'gid' => $node->organization_nid,
        'grant_view' => 0,
        'grant_update' => 0,
        'grant_delete' => 1,
        'priority' => 0,
      );
    }
  }
  return $grants;
}