--- project_access/project_access_old.module	2009-01-11 21:06:22.250000000 -0800
+++ project_access/project_access.module	2009-01-11 21:07:13.234375000 -0800
@@ -1003,3 +1003,67 @@ function project_access_filter_projects(
     }
   }
 }
+
+/*
+ * Implementation of hook_node_access_records
+ */
+function project_access_node_access_records($node) {
+  $nid = (int)$node->nid;
+  if($node->type == 'project_project') {
+    //get user level grants and put in project_access_user realm
+    $user_grants = _project_access_get_grants('uid','project_access_user',$nid); 
+
+    //get role level grants and put in project_access_role realm
+    $role_grants = _project_access_get_grants('rid','project_access_role',$nid);
+  
+    //merge two arrays into one
+    $grants = array_merge($user_grants, $role_grants);
+  }    
+  return $grants;      
+}  
+
+
+/*
+ * Helper function to get grants from project_access table
+ */
+function _project_access_get_grants($type,$realm,$nid) {
+  $sql_user = "SELECT * FROM project_access WHERE access_type = '%s' AND nid = %d";
+  $result_user = db_query($sql_user,$type,$nid);
+  while ($users = mysql_fetch_object($result_user)) {
+    $grants[] = array(
+      'realm' => $realm,
+      'gid' => $users->aid,
+      'grant_view' => $users->grant_view,
+      'grant_update' => $users->grant_update,
+      'grant_delete' => $users->grant_delete,
+    );  
+  } 
+  return $grants;
+}
+
+
+
+/*
+ * Implementation of hook_node_grants
+ */
+function project_access_node_grants($account, $op) {
+
+  if (variable_get(project_access_by_user,0)) {
+    $level = "user";
+  }
+  elseif (variable_get(project_access_by_role,0)) {
+    $level = "role";
+  }
+  
+  switch ($level) {
+    case "user":
+      dsm($account->uid);
+      $grants['project_access_user'] = array($account->uid);
+      break;
+    case "role":
+      $grants['project_access_role'] = array(array_keys($account->roles));
+      break;
+  }
+
+  return $grants;
+}
\ No newline at end of file
