? LICENSE.txt
? comment.inc.new
? iaf.txt
? ifac.patch.txt
Index: comment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/comment.inc,v
retrieving revision 1.85
diff -u -p -r1.85 comment.inc
--- comment.inc 19 Aug 2007 23:23:37 -0000 1.85
+++ comment.inc 1 Sep 2007 16:32:32 -0000
@@ -1,151 +1,98 @@
$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;
- }
- }
- else {
- drupal_set_message(t('You are not authorized to follow up on issues.'), 'error');
- drupal_goto("node/$nid");
+function project_issue_comment(&$arg, $op) {
+ static $edit;
+ // $arg can be a comment object, or a form or form_values.
+ if (is_object($arg)) {
+ $nid = $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');
- }
- $form['#prefix'] = '
';
- $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);
+ switch ($op) {
+ case 'form':
+ // $arg is a form
+ if (!$node->comment_count) {
+ foreach (array('nid', 'pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) {
+ $edit->$var = $node->$var;
+ }
+ }
+ else {
+ $edit = db_fetch_object(db_query_range('SELECT nid, title, pid, rid, component, category, priority, assigned, sid, timestamp FROM {project_issue_comments} WHERE nid = %d ORDER BY timestamp DESC ', $node->nid, 0, 1));
+ }
+ // We need to ask for almost the same metadata as project issue itself
+ // so let's reuse the form.
+ $form = drupal_retrieve_form('project_issue_form', $edit, NULL);
+ // We need this otherwise pid collides with comment.
+ $form['project_info']['#tree'] = TRUE;
+ $form['project_info']['#weight'] = -2;
+ $form['issue_info']['#weight'] = -1;
+ $form['#prefix'] = '
';
+ $form['title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Issue title'),
+ '#maxlength' => 64,
+ '#default_value' => $edit->title,
+ '#weight' => 0,
+ );
+ unset($form['page'], $form['issue_details']);
+ return $form;
+ case 'validate':
+ // We need to flatten the project_info.
+ $test = $arg;
+ $test['pid'] = $arg['project_info']['pid'];
+ $test['component'] = $arg['project_info']['component'];
+ if (!array_diff(array_filter((array)$edit), $test)) {
+ form_set_error('body', t('You must either specify a description or change something about this issue.'));
+ }
+ break;
+ case 'insert': case 'update':
+ // $arg is form_values
+ db_query("INSERT INTO {project_issue_comments} (nid, cid, pid, rid, component, category, priority, assigned, sid, title, timestamp) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d, '%s', %d)", $arg['nid'], $arg['cid'], $arg['project_info']['pid'], $arg['rid'], $arg['project_info']['component'], $arg['category'], $arg['priority'], $arg['assigned'], $arg['sid'], $arg['title'], $arg['timestamp']);
+ project_issue_update($arg);
+ break;
+ case 'view':
+ if (isset($arg->cid)) {
+ $project_issue_table = project_issue_comment_view($node, $arg);
+ }
+ else {
+ $test = drupal_clone($arg);
+ $test->pid = $arg->project_info['pid'];
+ $test->component = $arg->project_info['component'];
+ $project_issue_table = _project_issue_comment_table(_project_issue_comment_labels(), $edit, $test);
+ }
+ if ($project_issue_table) {
+ $arg->comment = '
'. $project_issue_table .'
' . $arg->comment;
+ }
+ break;
}
- $output .= '
';
- return theme('box', t('Updates'), $output);
- }
}
/**
- * 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.
- *
+ * Implementation of hook_form_alter.
*/
-function _project_comment_view_single($comment, $count) {
- $comment = (object)$comment;
- $summary = array();
- $output = '';
+function project_issue_form_alter($form_id, &$form) {
+ if ($form_id == 'comment_form') {
+ $node = node_load($form['nid']['#value']);
+ if ($node->type == 'project_issue') {
+ // Comment is not required for project issue followups, we have our own
+ // validate handler.
+ // The 'your name' item just wastes screen estate.
+ unset($form['comment_filter']['comment']['#required'], $form['_author']);
+ }
+ }
+}
- $fields = array(
+function _project_issue_comment_labels() {
+ return array(
'title' => t('Title'),
'pid' => t('Project'),
'rid' => t('Version'),
@@ -155,154 +102,58 @@ 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:'), '