? LICENSE.txt ? fakeadd ? generate ? p_i_p.patch ? scripts ? search_index ? theme ? translations ? views Index: issue.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/issue.inc,v retrieving revision 1.354 diff -u -p -r1.354 issue.inc --- issue.inc 18 Jun 2009 03:28:55 -0000 1.354 +++ issue.inc 7 Feb 2010 23:14:37 -0000 @@ -236,7 +236,13 @@ function project_issue_default_states() } function project_issue_priority($priority = 0) { - $priorities = array(1 => t('critical'), t('normal'), t('minor')); + static $priorities; + if (!isset($priorities)) { + $result = db_query('SELECT priority, name FROM {project_issue_priorities} ORDER BY weight'); + while ($priority = db_fetch_object($result)) { + $priorities[$priority->priority] = $priority->name; + } + } return $priority ? $priorities[$priority] : $priorities; } Index: project_issue.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.install,v retrieving revision 1.64 diff -u -p -r1.64 project_issue.install --- project_issue.install 21 Aug 2009 22:51:31 -0000 1.64 +++ project_issue.install 7 Feb 2010 23:14:37 -0000 @@ -117,6 +117,13 @@ function project_issue_schema() { 'not null' => TRUE, 'default' => 0, ), + 'priority_weight' => array( + 'description' => 'The weight of the priority for this issue.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), 'rid' => array( 'description' => 'The {project_release_nodes}.rid (version identifier) for this issue (only used in conjunction with the project_release module).', 'type' => 'int', @@ -204,6 +211,13 @@ function project_issue_schema() { 'not null' => TRUE, 'default' => 0, ), + 'priority_weight' => array( + 'description' => 'The weight of the priority for this issue after this comment was made.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), 'assigned' => array( 'description' => 'The {users}.uid of the user to which this issue was assigned after this comment was made.', 'type' => 'int', @@ -249,6 +263,32 @@ function project_issue_schema() { ), ); + $schema['project_issue_priorities'] = array( + 'description' => 'The issue priorities.', + 'fields' => array( + 'priority' => array( + 'description' => 'The priority for this issue after this comment was made.', + 'type' => 'serial', + 'not null' => TRUE, + ), + 'name' => array( + 'description' => 'Display-friendly name for this priority.', + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ), + 'weight' => array( + 'description' => 'Weight for this priority, used when ordering priorities.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('priority'), + ); + $schema['project_subscriptions'] = array( 'description' => 'Table keeping track of per-user project_issue subscriptions.', 'fields' => array( @@ -364,6 +404,9 @@ function project_issue_install() { variable_set('comment_upload_project_issue', 1); // Enable file attachments for issues. variable_set('upload_project_issue', 1); + db_query("INSERT INTO {project_issue_priorities} (priority, name, weight) VALUES (1, 'critical', 1)"); + db_query("INSERT INTO {project_issue_priorities} (priority, name, weight) VALUES (2, 'normal', 2)"); + db_query("INSERT INTO {project_issue_priorities} (priority, name, weight) VALUES (3, 'minor', 3)"); } /** @@ -446,3 +489,36 @@ function project_issue_update_6002() { return $ret; } +function project_issue_update_6003() { + $ret = array(); + $table = array( + 'description' => 'The issue priorities.', + 'fields' => array( + 'priority' => array( + 'description' => 'The priority for this issue after this comment was made.', + 'type' => 'serial', + 'not null' => TRUE, + ), + 'name' => array( + 'description' => 'Display-friendly name for this priority.', + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ), + 'weight' => array( + 'description' => 'Weight for this priority, used when ordering priorities.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('priority'), + ); + db_create_table($ret, 'project_issue_priorities', $table); + db_query("INSERT INTO {project_issue_priorities} (priority, name, weight) VALUES (1, 'critical', 1)"); + db_query("INSERT INTO {project_issue_priorities} (priority, name, weight) VALUES (2, 'normal', 2)"); + db_query("INSERT INTO {project_issue_priorities} (priority, name, weight) VALUES (3, 'minor', 3)"); + return $ret; +} Index: project_issue.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.module,v retrieving revision 1.174 diff -u -p -r1.174 project_issue.module --- project_issue.module 6 Aug 2009 23:35:34 -0000 1.174 +++ project_issue.module 7 Feb 2010 23:14:38 -0000 @@ -101,6 +101,19 @@ function project_issue_menu() { 'file' => 'includes/admin.settings.inc', ); + // Administrative pages + $items['admin/project/project-issue-priorities'] = array( + 'title' => 'Project issue priorities', + 'description' => 'Configure what issue priorities should be used on your site.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('project_issue_admin_priorities_form'), + 'access arguments' => array('administer projects'), + 'weight' => 1, + 'type' => MENU_NORMAL_ITEM, + 'file' => 'includes/admin.priorities.inc', + ); + + // Administer issue status settings $items['admin/project/project-issue-status'] = array( 'title' => 'Project issue status options', @@ -325,6 +338,12 @@ function project_issue_theme() { 'form' => NULL, ), ), + 'project_issue_admin_priorities_form' => array( + 'file' => 'includes/admin.priorities.inc', + 'arguments' => array( + 'form' => NULL, + ), + ), 'project_issue_project_edit_form' => array( 'file' => 'includes/project_edit_issues.inc', 'arguments' => array( @@ -527,7 +546,7 @@ function project_issue_access($op, $node * Helper to trim all elements in an array. */ function project_issue_trim(&$item, $key) { - $item = trim($item); + $item = trim($item); } /** @@ -621,7 +640,7 @@ function project_issue_add_auto_followup * ); * * @return - * TRUE if the comment was successfully added to the requested issue, + * TRUE if the comment was successfully added to the requested issue, * otherwise FALSE. */ function project_issue_add_followup($changes) { @@ -1760,4 +1779,3 @@ function project_issue_project_page_link $links['development']['links'] = $patches + $links['development']['links']; } } - Index: includes/admin.priorities.inc =================================================================== RCS file: includes/admin.priorities.inc diff -N includes/admin.priorities.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ includes/admin.priorities.inc 7 Feb 2010 23:14:38 -0000 @@ -0,0 +1,220 @@ +weight); + $max = max($max, $priority->weight); + $form['priority'][$priority->priority]['name'] = array( + '#type' => 'textfield', + '#default_value' => $priority->name, + '#size' => 20, + '#maxlength' => 255, + ); + $form['priority'][$priority->priority]['weight'] = array( + '#type' => 'weight', + '#default_value' => $priority->weight, + '#delta' => &$delta, + '#attributes' => array('class' => 'project-issue-priority-weight'), + ); + $exists = db_result(db_query_range('SELECT priority FROM {project_issues} WHERE priority = %d', 0, 1)) || db_result(db_query_range('SELECT priority FROM {project_issue_comments} WHERE priority = %d', 0, 1)); + $del_link = $exists ? '' : l(t('Delete'), 'admin/project/project-issue-priority/delete/'. $priority->priority); + $form['delete'][$priority->priority] = array( + '#type' => 'markup', + '#value' => $del_link, + ); + } + $delta = max(abs($min), abs($max), 15); + $form['priority_add']['name'] = array( + '#type' => 'textfield', + '#size' => 20, + '#maxlength' => 255, + ); + $form['priority_add']['weight'] = array( + '#type' => 'weight', + '#default_value' => 0, + '#delta' => 15, + '#attributes' => array('class' => 'project-issue-priority-weight'), + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + ); + $form['#tree'] = TRUE; + return $form; +} + +/** + * Submit handler for project_issue_admin_states_form. + */ +function project_issue_admin_priorities_form_submit($form, &$form_state) { + $offset = PHP_MAX_INT; + foreach ($form_state['values']['priority'] as $priority_id => $value) { + $offset = min($offset, $value['weight']); + } + // Calculate an offset adding which to every weight results in a nonnegative + // number. + $offset = $offset < 0 ? -$offset : 0; + // Update existing priorities. + $update_expression = ''; + $weights = array(); + foreach ($form_state['values']['priority'] as $priority_id => $value) { + $weight = $value['weight'] + $offset; + $form_state['values']['priority'][$priority_id]['weight'] = $weight; + $priority = db_fetch_object(db_query('SELECT priority, name, weight FROM {project_issue_priorities} WHERE priority = %d', $priority_id)); + // Check to see whether the record needs updating. We love PHP and '0'. + if ($priority->name != $value['name'] || (string)$priority->weight !== (string)$weight) { + $update_expression .= " WHEN %d THEN %d"; + $weights[] = $priority->priority; + $weights[] = $weight; + db_query("UPDATE {project_issue_priorities} SET name = '%s', weight = %d WHERE priority = %d", $value['name'], $weight, $priority_id); + } + } + // Add new priority. + if ($form_state['values']['priority_add']['name']) { + // Check to see whether the state already exists: + $issue_state = db_result(db_query("SELECT COUNT(*) FROM {project_issue_priorities} WHERE name = '%s'", $form_state['values']['priority_add']['name'])); + if (empty($issue_state)) { + db_query("INSERT INTO {project_issue_priorities} (name, weight) VALUES ('%s', %d)", $form_state['values']['priority_add']['name'], $form_state['values']['priority_add']['weight'] + $offset); + } + else { + drupal_set_message(t('Priority %priority already exists.', array ('%priority' => $form_state['values']['priority_add']['name'])), 'error'); + } + } + if ($weights) { + $weight_sql = "UPDATE {project_issues} SET priority_weight = CASE priority $update_expression END WHERE nid BETWEEN %d AND %d"; + $batch = array( + 'operations' => array( + array('_project_issue_priorities_update', array($weight_sql, $weights)), + ), + 'finished' => '_project_issue_priorities_finished', + 'title' => t('Processing'), + // We use a single multi-pass operation, so the default + // 'Remaining x of y operations' message will be confusing here. + 'progress_message' => '', + 'error_message' => t('The update has encountered an error.'), + // The operations do not live in the .module file, so we need to + // tell the batch engine which file to load before calling them. + 'file' => drupal_get_path('module', 'project_issue') .'/includes/admin.priorities.inc', + ); + batch_set($batch); + } +} + +/** + * Mass update batch operation + */ +function _project_issue_priorities_update($weight_sql, $weights, &$context) { + if (!isset($context['sandbox']['progress'])) { + $context['sandbox']['progress'] = 0; + // Avoid COUNT(*) like hell. + $context['sandbox']['max'] = db_result(db_query('SELECT MAX(nid) FROM {project_issues}')); + $context['sandbox']['min'] = db_result(db_query('SELECT MIN(nid) - 1 FROM {project_issues}')); + } + $arguments = $weights; + // MySQL does not support LIMIT & IN/ALL/ANY/SOME subquery so we do the hard + // work ourselves. + $results = db_query_range('SELECT nid FROM {project_issues} WHERE nid > %d', 0, 100, $context['sandbox']['current']); + while ($node = db_fetch_object($results)) { + if (!isset($first_nid)) { + $first_nid = $node->nid; + } + $last_nid = $node->nid; + } + $arguments[] = $first_nid; + $arguments[] = $last_nid; + db_query($weight_sql, $arguments); + if ($last_nid < $context['sandbox']['max']) { + $context['sandbox']['progress'] = ($last_nid - $context['sandbox']['min']) / ($context['sandbox']['max'] - $context['sandbox']['min']); + } + else { + $context['sandbox']['progress'] = 1; + } +} + +function theme_project_issue_admin_priorities_form($form) { + drupal_add_tabledrag('project-issue-admin-priority-table', 'order', 'self', 'project-issue-priority-weight'); + $header = array( + t('Priority'), + t('Weight'), + t('Operations'), + ); + foreach (element_children($form['priority']) as $key) { + $rows[] = array( + 'class' => 'draggable', + 'data' => array( + drupal_render($form['priority'][$key]['name']), + drupal_render($form['priority'][$key]['weight']), + drupal_render($form['delete'][$key]), + ), + ); + } + $rows[] = array( + 'class' => 'draggable', + 'data' => array( + drupal_render($form['priority_add']['name']), + drupal_render($form['priority_add']['weight']), + ' ', + ), + ); + $output = '