I'm creating a new node - a tutorial. It's purpose is to record tutor-student tutorials/interviews. I've got most of it working, just have a problem the access. There are two roles -tutor and student. I want:
- Any tutor to be able to create, read and edit any tutorial record
- Only the authoring tutor can delete a tutorial
- Of the students, only the tutorial's student can view the tutorial
Here's the code:
<?php
/**
* Implementation of hook_perm().
* Define the permissions this module uses
*/
function tutorial_perm() {
return array('view tutorials', 'create tutorials', 'manage tutorials');
}
/**
* Implementation of hook_access().
*/
function tutorial_access($op, $node) {
global $user;
// Either any tutor or the tutorial's student can view the tutorial
$tut = db_fetch_object(db_query('SELECT t.sid FROM {tutorial} t WHERE t.nid = %d', $node->nid));
if($op == 'access') {
return (in_array('tutor', $user->roles) || ($user->uid == $tut->sid));
}
if ($op == 'create') {
return user_access('create tutorials');
}
// Any tutor can update the tutorial.
if ($op == 'update') {
return user_access('manage tutorials');
}
// Only the authoring tutor can delete the tutorial.
if ($op == 'delete') {
return (user_access('manage tutorials') && ($user->uid == $node->uid));
}