? 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 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Code for the issue priorities admin configuration form.
+ */
+
+function project_issue_admin_priorities_form(&$form_state) {
+  $result = db_query('SELECT priority, name, weight FROM {project_issue_priorities} ORDER BY weight');
+  $min = PHP_INT_MAX;
+  $max = -PHP_INT_MAX;
+  while ($priority = db_fetch_object($result)) {
+    $min = min($min, $priority->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']),
+      '&nbsp',
+    ),
+  );
+  $output = '<div>' . theme('table', $header, $rows, array('id' => 'project-issue-admin-priority-table')) . '</div>';
+  $output .= drupal_render($form);
+  return $output;
+}
+
+/*
+function project_issue_delete_state_confirm(&$form_state, $sid) {
+  $states = project_issue_state();
+  $name = $states[$sid];
+
+  $total = db_result(db_query('SELECT COUNT(nid) AS total FROM {project_issues} WHERE sid = %d', $sid));
+  if ($total > 0) {
+    $form['new_sid'] = array(
+      '#type' => 'select',
+      '#title' => t('Reassign status'),
+      '#default_value' => $sid,
+      '#options' => $states,
+      '#description' => t('There are !total existing issues with the status of @name. Please select a new status for these issues.', array('!total' => $total, '@name' => $name)),
+    );
+  }
+  $form['sid'] = array(
+    '#type' => 'value',
+    '#value' => $sid,
+  );
+  $form['name'] = array(
+    '#type' => 'hidden',
+    '#value' => $name,
+  );
+  return confirm_form(
+    $form,
+    t('Are you sure you want to delete the status option %name?', array('%name' => $name)),
+    'admin/project/project-issue-status',
+    t('This action cannot be undone.'),
+    t('Delete'), t('Cancel')
+  );
+}
+
+function project_issue_delete_state_confirm_validate($form, &$form_state) {
+  if ($form_state['values']['new_sid'] == $form_state['values']['sid']) {
+    form_set_error('new_sid', t('Choose a new issue status for existing issues of status %name.', array('%name' => $form_state['values']['name'])));
+  }
+}
+
+function project_issue_delete_state_confirm_submit($form, &$form_state) {
+  if ($form_state['values']['new_sid']) {
+    db_query('UPDATE {project_issues} SET sid = %d WHERE sid = %d', $form_state['values']['new_sid'], $form_state['values']['sid']);
+  }
+  db_query('DELETE FROM {project_issue_state} WHERE sid = %d', $form_state['values']['sid']);
+  drupal_set_message(t('Project issue status %issue deleted.', array('%issue' => $form_state['values']['name'])));
+  $form_state['redirect'] ='admin/project/project-issue-status';
+}
+*/
Index: includes/comment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/comment.inc,v
retrieving revision 1.155
diff -u -p -r1.155 comment.inc
--- includes/comment.inc	23 Sep 2009 00:27:05 -0000	1.155
+++ includes/comment.inc	7 Feb 2010 23:14:38 -0000
@@ -46,7 +46,8 @@ function project_issue_comment(&$arg, $o
 
       if (isset($id)) {
         $rid = isset($arg['project_info']['rid']) ? $arg['project_info']['rid'] : 0;
-        db_query("INSERT INTO {project_issue_comments} (nid, cid, pid, rid, component, category, priority, assigned, sid, title, timestamp, comment_number) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d, '%s', %d, %d)", $arg['nid'], $arg['cid'], $arg['project_info']['pid'], $rid, $arg['project_info']['component'], $arg['category'], $arg['priority'], $arg['project_info']['assigned'], $arg['sid'], $arg['title'], $arg['timestamp'], $id);
+        $priority_weight = db_result(db_query('SELECT weight FROM {priority_issue_priorities} WHERE priority = %d', $arg['priority']));
+        db_query("INSERT INTO {project_issue_comments} (nid, cid, pid, rid, component, category, priority, priority_weight, assigned, sid, title, timestamp, comment_number) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d, '%s', %d, %d)", $arg['nid'], $arg['cid'], $arg['project_info']['pid'], $rid, $arg['project_info']['component'], $arg['category'], $arg['priority'], $arg['priority_weight'], $arg['project_info']['assigned'], $arg['sid'], $arg['title'], $arg['timestamp'], $id);
         db_query("UPDATE {comments} SET subject = '%s' WHERE cid = %d", "#$id", $arg['cid']);
         project_issue_update_by_comment($arg, 'insert');
         $affected_projects[$old_data->pid] = 1;
@@ -83,7 +84,7 @@ function project_issue_comment(&$arg, $o
       // We should also invalidate the block cache for whatever project is now
       // used for this issue, since we might be deleting a comment that moved
       // an issue from one project to another.
-      $affected_projects[$current_data->pid] = 1;      
+      $affected_projects[$current_data->pid] = 1;
       break;
 
     case 'view':
Index: includes/issue_node_form.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/issue_node_form.inc,v
retrieving revision 1.5
diff -u -p -r1.5 issue_node_form.inc
--- includes/issue_node_form.inc	8 Oct 2009 23:36:16 -0000	1.5
+++ includes/issue_node_form.inc	7 Feb 2010 23:14:38 -0000
@@ -238,6 +238,7 @@ function _project_issue_form($node, $for
     );
   }
 
+  $priority = $node->project_issue['priority'] ? $node->project_issue['priority'] : 2;
   if ($allow_metadata_changes) {
     $form['project_info'] = array(
       '#type' => 'fieldset',
@@ -286,7 +287,7 @@ function _project_issue_form($node, $for
     $form['issue_info']['priority'] = array(
       '#type' => 'select',
       '#title' => t('Priority'),
-      '#default_value' => $node->project_issue['priority'] ? $node->project_issue['priority'] : 2,
+      '#default_value' => $priority,
       '#options' => $priorities,
     );
     $form['issue_info']['assigned'] = array(
@@ -340,7 +341,7 @@ function _project_issue_form($node, $for
     );
     $form['project_issue']['priority'] = array(
       '#type' => 'value',
-      '#value' => $node->project_issue['priority'],
+      '#value' => $priority,
     );
     $form['project_issue']['assigned'] = array(
       '#type' => 'value',
@@ -351,6 +352,10 @@ function _project_issue_form($node, $for
       '#value' => $node->project_issue['sid'],
     );
   }
+  $form['project_issue']['priority_weight'] = array(
+    '#type' => 'value',
+    '#value' => db_result(db_query('SELECT weight FROM {project_issue_priorities} WHERE priority = %d', $priority)),
+  );
 
   $form['issue_details'] = array(
     '#type' => 'fieldset',
@@ -481,4 +486,3 @@ function _project_issue_insert($node) {
   // new issue will have altered the summary totals.
   cache_clear_all('project_issue_cockpit_block:'. $node->pid, 'cache');
 }
-
