You are here

function pmtimetracking_node_access_records in Drupal PM (Project Management) 7

Implements hook_node_access_records().

File

pmtimetracking/pmtimetracking.module, line 644
Main module functions for PM Timetracking.

Code

function pmtimetracking_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 == 'pmtimetracking') {

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

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

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

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

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

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

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

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

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