nid;
}
elseif (is_array($arg)) {
$nid = is_array($arg['nid']) ? $arg['nid']['#value'] : $arg['nid'];
}
$node = node_load($nid);
if ($node->type != 'project_issue') {
return;
}
switch ($op) {
case 'form':
// $arg is a form
if (!$node->comment_count) {
foreach (array('nid', 'type', 'pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) {
$edit->$var = $node->$var;
}
}
else {
// For speed purposes, we do not join -- order by timestamp desc would kill.
$comment = db_fetch_object(db_query_range('SELECT cid, subject FROM {comments} WHERE nid = %d ORDER BY timestamp DESC', $node->nid, 0, 1));
$edit = db_fetch_object(db_query('SELECT nid, cid, pid, rid, component, category, priority, assigned, sid FROM {project_issue_comment} WHERE cid = %d', $comment->cid));
$edit->title = $comment->subject;
}
$form = drupal_retrieve_form('project_issue_form', $edit, NULL);
$form['project_info']['#weight'] = -2;
$form['issue_info']['#weight'] = -1;
$form['#prefix'] = '
';
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#maxlength' => 64,
'#default_value' => $edit->title,
);
unset($form['page'], $form['issue_details']);
return $form;
case 'validate':
project_issue_comment_validate($arg);
break;
case 'insert': case 'update':
// $arg is form_values
db_query("INSERT INTO {project_issue_comment} (nid, cid, pid, rid, component, category, priority, assigned, sid) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d)", $arg['nid'], $arg['cid'], $arg['pid'], $arg['rid'], $arg['component'], $arg['category'], $arg['priority'], $arg['assigned'], $arg['sid']);
project_issue_update($arg);
return;
case 'view':
if ($additional = project_issue_comment_view($node, $arg)) {
$arg->comment = '' . $arg->comment;
}
break;
}
}
function project_issue_comment_view(&$node, $comment = NULL) {
static $additions;
if (!isset($comment)) {
// We are cloning here because we want to keep the original title.
$additions[$nid][0] = drupal_clone($node);
if ($node->comment_count) {
$node->title = db_result(db_query_range('SELECT subject FROM {comments} WHERE nid = %d ORDER BY timestamp DESC', $node->nid, 0, 1));
}
return;
}
$current = db_fetch_object(db_query('SELECT subject as title, pic.pid, rid, component, category, priority, assigned, sid FROM {project_issue_comment} pic INNER JOIN {comments} c ON pic.cid = c.cid WHERE c.cid = %d', $comment->cid));
$n = count($additions[$nid]) - 1;
$old = $additions[$nid][$n];
$rows = array();
$labels = array(
'title' => t('Title'),
'pid' => t('Project'),
'rid' => t('Version'),
'component' => t('Component'),
'category' => t('Category'),
'priority' => t('Priority'),
'assigned' => t('Assigned to'),
'sid' => t('Status'),
);
foreach ($labels as $field => $text) {
if ($old->$field != $current->$field) {
$rows[] = array(
$labels[$field] .':',
project_mail_summary($field, $old->$field),
'» '. project_mail_summary($field, $current->$field)
);
}
}
$additions[$nid][] = $current;
return theme('table', array(), $rows);
}