? iaf.txt
? p
? w.txt
Index: comment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/comment.inc,v
retrieving revision 1.83
diff -u -p -r1.83 comment.inc
--- comment.inc 30 Jul 2007 14:31:36 -0000 1.83
+++ comment.inc 30 Jul 2007 14:40:20 -0000
@@ -1,143 +1,79 @@
$var = $node->$var;
- }
- project_comment_validate($edit);
- }
- $output .= drupal_get_form('project_comment_form', $edit);
-
- // set breadcrumb
- $project = node_load(array('nid' => $node->pid));
- $breadcrumb[] = l($project->title, 'node/'. $project->nid);
- $breadcrumb[] = l(t('Issues'), 'project/issues/'. $project->uri);
- $breadcrumb[] = l($node->title, 'node/'. $node->nid);
- project_project_set_breadcrumb($project, $breadcrumb);
-
- drupal_set_title(t('New comment'));
- switch ($_POST['op'] ? $_POST['op'] : arg(2)) {
- case 'add':
- $output .= node_view($node, NULL, TRUE);
- return $output;
- break;
- case t('Preview'):
- return $output;
- break;
- case t('Submit'):
- if (!form_get_errors()) {
- $edit->nid = $node->nid;
-
- project_comment_save($edit);
- drupal_goto("node/$node->nid");
- } else {
- return $output;
- }
- break;
- }
+function project_issue_comment(&$arg, $op) {
+ // $arg can be a comment object, or a form or form_values.
+ if (is_object($arg)) {
+ $nid = $arg->nid;
}
- else {
- drupal_set_message(t('You are not authorized to follow up on issues.'), 'error');
- drupal_goto("node/$nid");
+ elseif (is_array($arg)) {
+ $nid = is_array($arg['nid']) ? $arg['nid']['#value'] : $arg['nid'];
}
-}
-
-function project_comment_form($edit, $param = NULL) {
- $op = $_POST['op'];
- if (isset($param)) {
- $form = array(
- '#method' => $param['method'],
- '#action' => $param['action'],
- '#attributes' => $param['options'],
- );
- } else {
- $form['#attributes'] = array('enctype' => 'multipart/form-data');
+ $node = node_load($nid);
+ if ($node->type != 'project_issue') {
+ return;
}
- $form['#prefix'] = '
';
- $form['project_issue_form'] = project_issue_form($edit, $param);
- unset($form['project_issue_form']['#prefix']);
- unset($form['project_issue_form']['#suffix']);
- _project_issue_form_add_required_fields($form['project_issue_form'], FALSE);
- if ($edit->cid) {
- $form['cid']= array('#type' => 'hidden', '#value' => $edit->cid);
- }
- $form['preview'] = array('#type' => 'button', '#value' => t('Preview'));
- if (!form_get_errors()) {
- $form['submit'] = array('#type' => 'button', '#value' => t('Submit'));
- }
- if ($op == t('Preview')) {
- $form['#after_build'] = array('project_comment_form_add_preview');
- }
- return $form;
+ 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_comment_validate(&$edit) {
- global $user;
-
- $edit->uid = $user->uid;
- $edit->name = $user->name;
-
- if ($edit->cid) {
- $comment = project_comment_load($edit->cid);
- $edit->nid = $comment->nid;
- }
+function project_issue_comment_view(&$node, $comment = NULL) {
+ static $additions;
- $edit->comment = true;
-
- project_issue_comment_validate($edit);
- $edit->validated = true;
-}
-
-function project_comment_view($node, $main = 0) {
- global $user;
- $rows = array();
- $result = db_query('SELECT p.*, u.name FROM {project_comments} p INNER JOIN {users} u USING (uid) WHERE p.nid = %d ORDER BY p.created ASC', $node->nid);
- if (db_num_rows($result)) {
- $output = '';
- $i = 0;
- while ($comment = db_fetch_object($result)) {
- $comment->body = db_decode_blob($comment->body);
- $comment->data = db_decode_blob($comment->data);
- $i++;
- $output .= _project_comment_view_single($comment, $i);
+ 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));
}
- $output .= '
';
- return theme('box', t('Updates'), $output);
+ return;
}
-}
-
-/**
- * Private method to view a single project comment (issue followup).
- *
- * @param $comment
- * An array or object of the comment to view.
- * @param $count
- * The integer that shows what number of comment this is.
- *
- * @return
- * A string of validated output to theme/display.
- *
- */
-function _project_comment_view_single($comment, $count) {
- $comment = (object)$comment;
- $summary = array();
- $output = '';
-
- $fields = array(
+ $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'),
@@ -147,154 +83,15 @@ function _project_comment_view_single($c
'assigned' => t('Assigned to'),
'sid' => t('Status'),
);
-
- // If we got this from the DB, we'll have a $data field to unserialize.
- $comment = drupal_unpack($comment);
-
- // Print out what changed about the issue with this comment. If the
- // comment is in the DB, we'll have 'old' and 'new' fields from the
- // 'data' field, which record exactly what changed. If not, we'll
- // load the origial node and compare against that.
- if (!isset($comment->data)) {
- $node = node_load(array('nid' => arg(3), 'type' => 'project_issue'));
- }
- foreach ($fields as $field => $text) {
- if (isset($comment->old->$field) && isset($comment->new->$field)) {
- $summary[] = array(
- $text .':',
- project_mail_summary($field, $comment->old->$field),
- '» '. project_mail_summary($field, $comment->new->$field)
- );
- }
- elseif (isset($node->$field) && isset($comment->$field) && $node->$field != $comment->$field ) {
- $summary[] = array(
- $text .':',
- project_mail_summary($field, $node->$field),
- '» '. project_mail_summary($field, $comment->$field)
- );
- }
- }
-
- if ($comment->file_path && file_exists($comment->file_path)) {
- $summary[] = array(t('Attachment:'), ''. basename($comment->file_path) .' ('. format_size($comment->file_size) .')');
- }
-
- if ($summary || $comment->body) {
- if ($count) {
- $output .= '';
- }
- if ($summary) {
- $output .= '';
- $output .= theme('table', array(), $summary);
- $output .= '
';
- }
- if ($comment->body) {
- $output .= '';
- $output .= check_markup($comment->body);
- $output .= '
';
+ 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)
+ );
}
}
- return $output;
-}
-
-function project_comment_load($cid) {
- $object = db_fetch_object(db_query('SELECT p.*, u.name FROM {project_comments} p INNER JOIN {users} u USING (uid) WHERE p.cid = %d ORDER BY p.created DESC', $cid));
- $object->body = db_decode_blob($object->body);
- $object->data = db_decode_blob($object->data);
- return $object;
-}
-
-function project_comment_save($edit) {
- global $user;
-
- if (empty($edit->cid)) {
- $edit->cid = db_next_id('{project}_cid');
- if ($edit->file) {
- $directory = file_create_path(variable_get('project_directory_issues', 'issues'));
- $edit->file->filename = project_issue_munge_filename($edit->file->filename);
- $file = file_save_upload($edit->file, $directory);
- unset($edit->file);
- }
-
- if (empty($edit->uid)) {
- $edit->uid = $user->uid;
- }
- $node = node_load(array('nid' => $edit->nid, 'type' => 'project_issue'));
-
- // Check if comment changed any of the state values and update the node if necessary
- foreach (array('pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) {
- if ($node->$var != $edit->$var) {
- $data['old']->$var = $node->$var;
- $data['new']->$var = $edit->$var;
- $node->$var = $edit->$var;
- }
- }
-
- // Add processed cck info into the node object for node_save
- if (function_exists('_content_widget_invoke')) {
- $type = content_types($node->type);
- while (list($field, $val) = each($type['fields'])) {
- $node->$field = $edit->$field;
- }
- _content_widget_invoke('process form values', $node);
- }
-
- watchdog('content', t('project_issue: added comment %title', array('%title' => $edit->title)), WATCHDOG_NOTICE, l('view', "node/$node->nid"));
- $node->changed = time();
- db_query("INSERT INTO {project_comments} (cid, nid, uid, created, changed, body, data, file_path, file_mime, file_size) VALUES (%d, %d, %d, %d, %d, %b, %b, '%s', '%s', %d)", $edit->cid, $edit->nid, $edit->uid, $node->changed, $node->changed, $edit->body, serialize($data), $file->filepath, $file->filemime, $file->filesize);
-
- // Update node_comment_statistics so the tracker page lists the number of comments
- $count = db_result(db_query('SELECT COUNT(cid) FROM {project_comments} WHERE nid = %d', $edit->nid));
- db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, time(), $user->name, $user->uid, $edit->nid);
-
- node_save($node);
- }
-
- return $edit->cid;
-}
-
-/**
- * Form API callback for previewing a project comment.
- *
- * @param $form
- * The form to add the preview information to.
- * @param $edit
- * The form values for the comment to preview.
- *
- * @return
- * The modified form to render.
- *
- */
-function project_comment_form_add_preview($form, $edit) {
- drupal_set_title(t('Preview comment'));
- if (is_array($edit)) {
- $comment = (object)$edit;
- }
- else {
- $comment = $edit;
- }
- project_comment_validate($comment);
-
- // Preview the comment with security check.
- if (!form_get_errors()) {
- $output = _project_comment_view_single($comment, 0);
- }
-
- $form['comment_preview'] = array(
- '#value' => $output,
- '#weight' => -100,
- '#prefix' => '',
- );
-
- $output = '';
- if (is_numeric(arg(3))) {
- $node = node_load(array('nid' => arg(3), 'type' => 'project_issue'));
- $output .= node_view($node, NULL, TRUE);
- $form['comment_preview_below'] = array('#value' => $output, '#weight' => 100);
- }
- unset($form['#sorted']);
- return $form;
+ $additions[$nid][] = $current;
+ return theme('table', array(), $rows);
}
Index: issue.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/issue.inc,v
retrieving revision 1.238
diff -u -p -r1.238 issue.inc
--- issue.inc 30 Jul 2007 14:31:36 -0000 1.238
+++ issue.inc 30 Jul 2007 14:40:21 -0000
@@ -924,10 +924,6 @@ function project_issue_view($node, $teas
'#value' => '',
'#weight' => -3,
);
- $node->content['project_issue_comments'] = array(
- '#value' => project_comment_view($node),
- '#weight' => 2,
- );
// Breadcrumb navigation
$breadcrumb[] = array('path' => 'project', 'title' => t('Projects'));
Index: project_issue.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.install,v
retrieving revision 1.10
diff -u -p -r1.10 project_issue.install
--- project_issue.install 13 Jul 2007 03:29:27 -0000 1.10
+++ project_issue.install 30 Jul 2007 14:40:21 -0000
@@ -51,6 +51,18 @@ function project_issue_install() {
PRIMARY KEY (cid),
KEY project_comments_nid (nid)
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+ db_query("CREATE TABLE IF NOT EXISTS {project_issue_comment} (
+ nid int(11) default NULL,
+ cid int(11) default NULL,
+ rid int(11) default NULL,
+ component varchar(255) default NULL,
+ category varchar(255) default NULL,
+ priority int(11) default NULL,
+ assigned int(11) default NULL,
+ sid int(11) default NULL,
+ title varchar(255) NOT NULL,
+ pid int(10) unsigned NOT NULL
+ ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE IF NOT EXISTS {project_subscriptions} (
nid int(10) unsigned NOT NULL default '0',
uid int(10) unsigned NOT NULL default '0',
@@ -115,6 +127,20 @@ function project_issue_install() {
);");
db_query("CREATE SEQUENCE {project}_cid_seq INCREMENT 1 START 1");
}
+ if (!db_table_exists('project_issue_comment')) {
+ db_query("CREATE TABLE {project_issue_comment} (
+ nid int default NULL,
+ cid int default NULL,
+ rid int default NULL,
+ component varchar(255) default NULL,
+ category varchar(255) default NULL,
+ priority int default NULL,
+ assigned int default NULL,
+ sid int default NULL,
+ pid int unsigned NOT NULL
+ ) TYPE=MyISAM
+ /*!40100 DEFAULT CHARACTER SET utf8 */;");
+ }
if (!db_table_exists('project_subscriptions')) {
db_query("CREATE TABLE {project_subscriptions} (
nid int NOT NULL default '0',
Index: project_issue.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.module,v
retrieving revision 1.32
diff -u -p -r1.32 project_issue.module
--- project_issue.module 30 Jul 2007 14:31:36 -0000 1.32
+++ project_issue.module 30 Jul 2007 14:40:21 -0000
@@ -490,6 +490,9 @@ function project_issue_issue_nodeapi(&$n
form_set_error('sid', t('Invalid issue status %status: you do not have permission to set this status', array('%status' => $state)));
}
break;
+ case 'view':
+ project_issue_comment_view($node);
+ break;
}
}