| 1 |
<?php
|
| 2 |
// $Id: casetracker_basic.module,v 1.21 2008/03/09 14:23:41 zero2one Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Enables a basic project node type for use with Case Tracker.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_perm().
|
| 11 |
*/
|
| 12 |
function casetracker_basic_perm() {
|
| 13 |
return array('create projects', 'create cases', 'edit own projects', 'edit own cases');
|
| 14 |
}
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_node_info().
|
| 18 |
*/
|
| 19 |
function casetracker_basic_node_info() {
|
| 20 |
return array(
|
| 21 |
'casetracker_basic_project' => array(
|
| 22 |
'name' => t('Project'),
|
| 23 |
'module' => 'casetracker_basic_project',
|
| 24 |
'description' => t('Create a basic project for use with Case Tracker.'),
|
| 25 |
'help' => t('Create a basic project for use with Case Tracker.'),
|
| 26 |
'body_label' => t('Description'),
|
| 27 |
),
|
| 28 |
'casetracker_basic_case' => array(
|
| 29 |
'name' => t('Case'),
|
| 30 |
'module' => 'casetracker_basic_case',
|
| 31 |
'description' => t('Open a new case assigned to a particular project.'),
|
| 32 |
'help' => t('Open a new case assigned to a particular project.'),
|
| 33 |
'body_label' => t('Description'),
|
| 34 |
),
|
| 35 |
);
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Implementation of hook_form().
|
| 40 |
*/
|
| 41 |
function casetracker_basic_project_form(&$node) {
|
| 42 |
$form = array();
|
| 43 |
if (casetracker_is_project($node->type)) {
|
| 44 |
$type = node_get_types('type', $node);
|
| 45 |
$form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => !empty($node->title) ? $node->title : NULL, '#weight' => -5);
|
| 46 |
$form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
|
| 47 |
}
|
| 48 |
return $form;
|
| 49 |
}
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Implementation of hook_form().
|
| 53 |
*/
|
| 54 |
function casetracker_basic_case_form(&$node) {
|
| 55 |
$form = array();
|
| 56 |
if (casetracker_is_case($node->type)) {
|
| 57 |
$type = node_get_types('type', $node);
|
| 58 |
$form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => !empty($node->title) ? $node->title : NULL, '#weight' => -5);
|
| 59 |
$form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
|
| 60 |
}
|
| 61 |
return $form;
|
| 62 |
}
|
| 63 |
|
| 64 |
/**
|
| 65 |
* Implementation of hook_access().
|
| 66 |
*/
|
| 67 |
function casetracker_basic_project_access($op, $node, $account) {
|
| 68 |
switch ($op) {
|
| 69 |
case 'create':
|
| 70 |
return user_access('create projects', $account);
|
| 71 |
break;
|
| 72 |
case 'update':
|
| 73 |
case 'delete':
|
| 74 |
if (user_access('edit own projects', $account) && ($account->uid == $node->uid)) {
|
| 75 |
return TRUE;
|
| 76 |
}
|
| 77 |
break;
|
| 78 |
}
|
| 79 |
}
|
| 80 |
|
| 81 |
/**
|
| 82 |
* Implementation of hook_access().
|
| 83 |
*/
|
| 84 |
function casetracker_basic_case_access($op, $node) {
|
| 85 |
global $user;
|
| 86 |
|
| 87 |
switch ($op) {
|
| 88 |
case 'view':
|
| 89 |
// we have to check if the OG module is installed, otherwise this will
|
| 90 |
// overule the OG nodeaccess
|
| 91 |
if (!module_exists('og')) {
|
| 92 |
return user_access('access case tracker');
|
| 93 |
}
|
| 94 |
// we check if the case isn't created by the current user or is
|
| 95 |
// assigned to the current user, if so that user gets access
|
| 96 |
elseif (
|
| 97 |
user_access('access case tracker')
|
| 98 |
&& 0 < (int)$user->uid
|
| 99 |
&& ((int)$node->casetracker->assign_to === (int)$user->uid
|
| 100 |
|| (int)$node->uid === (int)$user->uid)
|
| 101 |
) {
|
| 102 |
return TRUE;
|
| 103 |
}
|
| 104 |
break;
|
| 105 |
case 'create':
|
| 106 |
return user_access('create cases');
|
| 107 |
case 'update':
|
| 108 |
case 'delete':
|
| 109 |
if (user_access('edit own cases') && ($user->uid == $node->uid)) {
|
| 110 |
return TRUE;
|
| 111 |
}
|
| 112 |
break;
|
| 113 |
}
|
| 114 |
}
|