Index: comment.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/comment.inc,v retrieving revision 1.77 diff -u -p -r1.77 comment.inc --- comment.inc 8 Mar 2007 08:02:14 -0000 1.77 +++ comment.inc 29 Jul 2007 23:42:58 -0000 @@ -1,283 +1,97 @@ arg(3), 'type' => 'project_issue')); - if (!node_access('view', $node)) { - drupal_access_denied(); +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; + } + 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['#suffix'] = '
'; + $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; - } - - if ($_POST['op'] == t('Preview') || $_POST['op'] == t('Submit')) { - project_comment_validate($edit); - } else { - foreach (array('nid', 'type', 'pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) { - $edit->$var = $node->$var; + case 'view': + if ($additional = project_issue_comment_view($node, $arg)) { + $arg->comment = '
'. $additional .'
' . $arg->comment; } - project_comment_validate($edit); + break; } - $output .= drupal_get_form('project_comment_form', $edit); - - $breadcrumb = drupal_get_breadcrumb(); - $breadcrumb[] = l($node->title, "node/$node->nid"); - drupal_set_breadcrumb($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_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'] = '
'; - $form['#suffix'] = '
'; - $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; -} - -function project_comment_validate(&$edit) { - global $user; - - $edit->uid = $user->uid; - $edit->name = $user->name; +function project_issue_comment_view(&$node, $comment = NULL) { + static $additions; - if ($edit->cid) { - $comment = project_comment_load($edit->cid); - $edit->nid = $comment->nid; - } - - $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); - $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( - 'title' => 'Title', - 'pid' => 'Project', - 'rid' => 'Version', - 'component' => 'Component', - 'category' => 'Category', - 'priority' => 'Priority', - 'assigned' => 'Assigned to', - 'sid' => 'Status' + $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'), ); - - // 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( - t($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( - t($text) .':', - project_mail_summary($field, $node->$field), - '» '. project_mail_summary($field, $comment->$field) - ); + 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) + ); } } - - 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 .= '
'; - $output .= t('!count submitted by !user on !date', array('!count' => l("#$count", "node/$comment->nid", array ('id' => "comment-$comment->cid", 'name' => "comment-$comment->cid"), NULL, "comment-$comment->cid"), '!user' => theme('username', $comment), '!date' => format_date($comment->created))) . theme('mark', node_mark($comment->nid, $comment->changed)); - $output .= '
'; - } - if ($summary) { - $output .= '
'; - $output .= theme('table', array(), $summary); - $output .= '
'; - } - if ($comment->body) { - $output .= '
'; - $output .= check_markup($comment->body); - $output .= '
'; - } - } - 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); - 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; - } - } - - 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, '%s', '%s', '%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' => '
', - '#suffix' => '
', - ); - - $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.226 diff -u -p -r1.226 issue.inc --- issue.inc 1 Mar 2007 08:46:57 -0000 1.226 +++ issue.inc 29 Jul 2007 23:42:59 -0000 @@ -159,7 +159,7 @@ function project_issue_build_form_url($u return project_project_retrieve($url_arg); } } - + // dispatch to hanlders based on value of $_POST['form_id'] if ($_POST['form_id'] == 'project_issue_query_result_quick_search') { return project_issue_quick_search($url_arg, $filters); @@ -170,7 +170,7 @@ function project_issue_build_form_url($u } /** - * Handles quick search form + * Handles quick search form * * @param $url_arg * Value returned from arg(2) @@ -194,11 +194,11 @@ function project_issue_quick_search($url } $destination = 'project/issues/'. $project->uri; } - + // if 'q' is the only thing in $_GET, and it == destination, don't redirect if (count($_GET) == 1 && isset($_GET['q']) && $_GET['q'] == $destination) { - // put $_POST where pager will see them + // put $_POST where pager will see them foreach ($filters as $filter) { if (!empty($_POST[$filter])) { $_REQUEST[$filter] = $_POST[$filter]; @@ -534,7 +534,7 @@ function project_issue_form($node, $para if (trim($project->help)) { drupal_set_message(filter_xss($project->help)); } - if (module_exists('project_release') && + if (module_exists('project_release') && $releases = project_release_get_releases($project, 0)) { $releases = array(t('')) + $releases; } @@ -690,7 +690,7 @@ function project_issue_form($node, $para function project_issue_form_pre_render($form_id, &$form) { if ($form_id == 'project_issue_node_form') { - // Only move to the next page if there were no form errors. + // Only move to the next page if there were no form errors. // We don't want to keep incrementing page forever, since users // can successfully preview many times. However, if we already // have a value for 'Project' (via a submit with project in the @@ -766,7 +766,7 @@ function project_issue_node_form_validat if ($form_values['page'] == 2) { if ($form_values['pid'] && $project = node_load($form_values['pid'])) { $node->title = $form_values['title']; - if (module_exists('project_release') && + if (module_exists('project_release') && $releases = project_release_get_releases($project, 0)) { empty($form_values['rid']) and form_set_error('rid', t('You have to specify a valid version.')); } @@ -835,7 +835,7 @@ function project_issue_comment_validate( // make sure this followup changes something or has a body if (!empty($_POST) && empty($node->body)) { - if (is_numeric(arg(3))) { + if (is_numeric(arg(3))) { $issue = node_load(arg(3)); } if (isset($issue) @@ -917,11 +917,6 @@ function project_issue_view($node, $teas '#value' => '
'. t('Description') .'
', '#weight' => -3, ); - $node->content['project_issue_comments'] = array( - '#value' => project_comment_view($node), - '#weight' => 2, - ); - // Breadcrumb navigation $breadcrumb[] = array('path' => 'project', 'title' => t('Projects')); if (project_use_taxonomy()) { @@ -1015,7 +1010,7 @@ function project_issue_access($op, $node * * @return * An array of states (sid as key, name as value) that match the - * given filters, or the name of the requested state. + * given filters, or the name of the requested state. */ function project_issue_state($sid = 0, $restrict = false, $is_author = false, $defaults = false) { static $options; @@ -1564,7 +1559,7 @@ function project_issue_query_result($que // array to map pids to project names. If we're using the project // taxonomy, it will really be an array of arrays, where each // project type is itself an array. So, we flatten the array once - // and then can use it safely in the rest of this method. + // and then can use it safely in the rest of this method. if (project_use_taxonomy()) { $flat_projects = array(); foreach ($projects as $tmp) { @@ -1736,7 +1731,7 @@ function project_issue_query_url($query * exists and contains some data. If the query was otherwise going to * be empty, this function will automatically add the default set of * issue states (active, fixed, patch needs work, etc). - * + * * @param $query * The existing query object we're adding to. (This should probably * be a reference, instead of returning the object again). Index: project_issue.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.install,v retrieving revision 1.9 diff -u -p -r1.9 project_issue.install --- project_issue.install 1 Mar 2007 22:01:10 -0000 1.9 +++ project_issue.install 29 Jul 2007 23:42:59 -0000 @@ -54,7 +54,20 @@ function project_issue_install() { KEY project_comments_nid (nid) ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - db_query("CREATE TABLE IF NOT EXISTS {project_subscriptions} ( + 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 + ) TYPE=MyISAM + /*!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', level tinyint(3) unsigned NOT NULL default '0', @@ -120,6 +133,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.22 diff -u -p -r1.22 project_issue.module --- project_issue.module 28 Jan 2007 23:49:41 -0000 1.22 +++ project_issue.module 29 Jul 2007 23:42:59 -0000 @@ -204,7 +204,7 @@ function project_issue_menu($may_cache) 'access' => $access, 'type' => MENU_NORMAL_ITEM, ); - if (module_exists('search')) { + if (module_exists('search')) { $items[] = array( 'path' => 'search/issues', 'title' => t('Issues'), @@ -508,6 +508,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; } }