function casetracker_nodeapi in Case Tracker 5
Same name and namespace in other branches
- 6 casetracker.module \casetracker_nodeapi()
Implementation of hook_nodeapi().
File
- ./
casetracker.module, line 234 - Enables the handling of projects and their cases.
Code
function casetracker_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'delete':
// cases: delete case and its comments.
if (in_array($node->type, variable_get('casetracker_case_node_types', array(
'casetracker_basic_case',
)), TRUE)) {
$comment_results = db_query("SELECT cid FROM {comments} WHERE nid = %d", $node->nid);
while ($comment_result = db_fetch_object($comment_results)) {
db_query("DELETE FROM {casetracker_comment_status} WHERE cid = %d", $comment_result->cid);
}
db_query('DELETE FROM {casetracker_case} WHERE nid = %d', $node->nid);
}
// projects: delete all the cases under the project and all the comments under each case.
if (in_array($node->type, variable_get('casetracker_project_node_types', array(
'casetracker_basic_project',
)), TRUE)) {
$case_results = db_query("SELECT nid from {casetracker_case} WHERE pid = %d", $node->nid);
while ($case_result = db_fetch_object($case_results)) {
db_query("DELETE FROM {casetracker_case} WHERE nid = %d", $case_result->nid);
$comment_results = db_query("SELECT cid FROM {comments} WHERE nid = %d", $case_result->nid);
while ($comment_result = db_fetch_object($comment_results)) {
db_query("DELETE FROM {casetracker_comment_status} WHERE cid = %d", $comment_result->cid);
}
node_delete($case_result->nid);
// this'll handle comment deletion too.
}
db_query("DELETE FROM {casetracker_project} WHERE nid = %d", $node->nid);
}
break;
case 'insert':
// cases: generate a case ID and send it along.
if (in_array($node->type, variable_get('casetracker_case_node_types', array(
'casetracker_basic_case',
)), TRUE)) {
$node->case_number = _casetracker_next_case_number($node->pid);
// $node->case_number is used in casetracker_mail_send().
db_query("INSERT INTO {casetracker_case} (nid, vid, pid, case_priority_id, case_type_id, case_status_id, assign_to, case_number) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)", $node->nid, $node->vid, $node->pid, $node->case_priority_id, $node->case_type_id, $node->case_status_id, casetracker_get_uid($node->assign_to), $node->case_number);
}
// projects: associate a node with our project number.
if (in_array($node->type, variable_get('casetracker_project_node_types', array(
'casetracker_basic_project',
)), TRUE)) {
$node->project_number = _casetracker_next_project_number();
// not used anywhere, but matches code style under cases.
db_query('INSERT INTO {casetracker_project} (nid, vid, project_number) VALUES (%d, %d, %d)', $node->nid, $node->vid, $node->project_number);
}
break;
case 'load':
// cases: return all our summary data.
if (in_array($node->type, variable_get('casetracker_case_node_types', array(
'casetracker_basic_case',
)), TRUE)) {
return db_fetch_array(db_query('SELECT pid, case_priority_id, case_type_id, assign_to, case_status_id, case_number FROM {casetracker_case} WHERE nid = %d AND vid = %d', $node->nid, $node->vid));
}
// projects: add our project number to the node object.
if (in_array($node->type, variable_get('casetracker_project_node_types', array(
'casetracker_basic_project',
)), TRUE)) {
return db_fetch_array(db_query('SELECT project_number FROM {casetracker_project} WHERE nid = %d AND vid = %d', $node->nid, $node->vid));
}
break;
case 'update':
// cases: update our case with the latest data.
if (in_array($node->type, variable_get('casetracker_case_node_types', array(
'casetracker_basic_case',
)), TRUE)) {
$result = $node->revision ? db_query("INSERT INTO {casetracker_case} (nid, vid, pid, case_priority_id, case_type_id, case_status_id, assign_to, case_number) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)", $node->nid, $node->vid, $node->pid, $node->case_priority_id, $node->case_type_id, $node->case_status_id, casetracker_get_uid($node->assign_to), $node->case_number) : db_query('UPDATE {casetracker_case} SET pid = %d, case_priority_id = %d, case_type_id = %d, case_status_id = %d, assign_to = %d, vid = %d WHERE nid = %d AND vid = %d', $node->pid, $node->case_priority_id, $node->case_type_id, $node->case_status_id, casetracker_get_uid($node->assign_to), $node->vid, $node->nid, $node->vid);
}
// projects: if revisions are enabled, associate the new revision to our project number.
if (in_array($node->type, variable_get('casetracker_project_node_types', array(
'casetracker_basic_project',
)), TRUE) && $node->revision) {
db_query('INSERT INTO {casetracker_project} (nid, vid, project_number) VALUES (%d, %d, %d)', $node->nid, $node->vid, $node->project_number);
}
break;
case 'view':
// cases: summary data to beginning of body.
if (in_array($node->type, variable_get('casetracker_case_node_types', array(
'casetracker_basic_case',
)), TRUE)) {
$project = node_load($node->pid);
// used in the breadcrumb and our theme function, mostly for nid and project number display.
drupal_set_breadcrumb(array(
l(t('Home'), NULL),
l(t('Case Tracker projects'), 'casetracker/projects'),
l($project->title, 'node/' . $node->pid),
l(t('All cases'), 'casetracker/cases/' . $node->pid . '/all'),
));
$node->content['casetracker_case_summary'] = array(
'#value' => theme('casetracker_case_summary', $node, $project),
'#weight' => -10,
);
}
// projects: summary data to beginning of body.
if (in_array($node->type, variable_get('casetracker_project_node_types', array(
'casetracker_basic_project',
)), TRUE)) {
$node->content['casetracker_project_summary'] = array(
'#value' => theme('casetracker_project_summary', $node),
'#weight' => -10,
);
}
break;
}
}