Users want to get a report of tickets filtered by priority (e.g. just the "high priority tickets"). I wanted a link for than functionality to generate that report. Here's a patch to add that feature via an API.

*** support/support.old	Thu Jul  9 15:51:34 2009
--- ../modules/support/support.module	Mon Jul 13 05:26:23 2009
*************** function support_page($client = NULL, $s
*** 2032,2038 ****
      $state = $state ? "AND t.state = $state" : '';
    }
  
!   $sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count, t.state, t.priority, t.assigned FROM {node} n LEFT JOIN {support_ticket} t ON n.nid = t.nid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid WHERE (c.status = ". COMMENT_PUBLISHED ." OR c.status IS NULL) AND n.status = 1 AND n.type = 'support_ticket' AND client = $client $state $my_open";
    if (!user_access('view other users tickets') && !user_access('administer support') && !user_access('edit any ticket') && !user_access('delete any ticket')) {
      $sql .= " AND n.uid = $user->uid";
    }
--- 2032,2043 ----
      $state = $state ? "AND t.state = $state" : '';
    }
  
!   $pid = empty($_REQUEST['pid'])?'':(int) $_REQUEST['pid'];
!   if (is_int($pid)) { 
!     $priority_id = " AND t.priority = $pid ";
!   }
! 
!   $sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count, t.state, t.priority, t.assigned FROM {node} n LEFT JOIN {support_ticket} t ON n.nid = t.nid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid WHERE (c.status = ". COMMENT_PUBLISHED ." OR c.status IS NULL) AND n.status = 1 AND n.type = 'support_ticket' AND client = $client $state $priority_id $my_open";
    if (!user_access('view other users tickets') && !user_access('administer support') && !user_access('edit any ticket') && !user_access('delete any ticket')) {
      $sql .= " AND n.uid = $user->uid";
    }
*************** function support_page($client = NULL, $s
*** 2060,2066 ****
        $sql .= ", t.priority $order";
        break;
    }
!   $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) LEFT JOIN {support_ticket} t ON n.nid = t.nid WHERE n.status = 1 AND client = $client $state $my_open";
    $sql_count = db_rewrite_sql($sql_count);
    $result = pager_query($sql, 50, 0, $sql_count);
    $rows = array();
--- 2065,2071 ----
        $sql .= ", t.priority $order";
        break;
    }
!   $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) LEFT JOIN {support_ticket} t ON n.nid = t.nid WHERE n.status = 1 AND client = $client $state $priority_id $my_open";
    $sql_count = db_rewrite_sql($sql_count);
    $result = pager_query($sql, 50, 0, $sql_count);
    $rows = array();

Comments

rar’s picture

Oops - missed issue with drupal_goto called in support_module. This is an updated patch which moves relevent code above drupal_goto section.

diff -ap support/support.old ../modules/support/support.module 
*** support/support.old	Thu Jul  9 15:51:34 2009
--- ../modules/support/support.module	Mon Jul 13 06:29:48 2009
*************** function _support_truncate($text, $maxle
*** 1975,1989 ****
  function support_page($client = NULL, $state = NULL) {
    global $user;
  
    if (!$client) {
      if (isset($_SESSION['support_client']) && $client = support_client_load($_SESSION['support_client'])) {
!       drupal_goto("support/$client->path");
      }
      $clients = _support_available_clients();
      if (sizeof($clients)) {
        foreach ($clients as $key => $name) {
          $client = support_client_load($key);
!         drupal_goto("support/$client->path");
        }
      }
    }
--- 1975,1995 ----
  function support_page($client = NULL, $state = NULL) {
    global $user;
  
+   $pid = empty($_REQUEST['pid'])?'':(int) $_REQUEST['pid'];
+   if (is_int($pid)) { 
+     $priority_id = " AND t.priority = $pid ";
+     $priority_q = "pid=$pid";
+   }
+ 
    if (!$client) {
      if (isset($_SESSION['support_client']) && $client = support_client_load($_SESSION['support_client'])) {
!       drupal_goto("support/$client->path","$priority_q");
      }
      $clients = _support_available_clients();
      if (sizeof($clients)) {
        foreach ($clients as $key => $name) {
          $client = support_client_load($key);
!         drupal_goto("support/$client->path","$priority_q");
        }
      }
    }
*************** function support_page($client = NULL, $s
*** 1992,1998 ****
        $_SESSION['support_client'] = $client;
      }
      else {
!       drupal_set_message(t('Client does not exist or is not enabled.'), 'error');
        if (isset($_SESSION['support_client'])) {
          unset($_SESSION['support_client']);
        }
--- 1998,2004 ----
        $_SESSION['support_client'] = $client;
      }
      else {
!       drupal_set_message(t("Client $client does not exist or is not enabled."), 'error');
        if (isset($_SESSION['support_client'])) {
          unset($_SESSION['support_client']);
        }
*************** function support_page($client = NULL, $s
*** 2032,2038 ****
      $state = $state ? "AND t.state = $state" : '';
    }
  
!   $sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count, t.state, t.priority, t.assigned FROM {node} n LEFT JOIN {support_ticket} t ON n.nid = t.nid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid WHERE (c.status = ". COMMENT_PUBLISHED ." OR c.status IS NULL) AND n.status = 1 AND n.type = 'support_ticket' AND client = $client $state $my_open";
    if (!user_access('view other users tickets') && !user_access('administer support') && !user_access('edit any ticket') && !user_access('delete any ticket')) {
      $sql .= " AND n.uid = $user->uid";
    }
--- 2038,2044 ----
      $state = $state ? "AND t.state = $state" : '';
    }
  
!   $sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count, t.state, t.priority, t.assigned FROM {node} n LEFT JOIN {support_ticket} t ON n.nid = t.nid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid WHERE (c.status = ". COMMENT_PUBLISHED ." OR c.status IS NULL) AND n.status = 1 AND n.type = 'support_ticket' AND client = $client $state $priority_id $my_open";
    if (!user_access('view other users tickets') && !user_access('administer support') && !user_access('edit any ticket') && !user_access('delete any ticket')) {
      $sql .= " AND n.uid = $user->uid";
    }
*************** function support_page($client = NULL, $s
*** 2060,2066 ****
        $sql .= ", t.priority $order";
        break;
    }
!   $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) LEFT JOIN {support_ticket} t ON n.nid = t.nid WHERE n.status = 1 AND client = $client $state $my_open";
    $sql_count = db_rewrite_sql($sql_count);
    $result = pager_query($sql, 50, 0, $sql_count);
    $rows = array();
--- 2066,2072 ----
        $sql .= ", t.priority $order";
        break;
    }
!   $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) LEFT JOIN {support_ticket} t ON n.nid = t.nid WHERE n.status = 1 AND client = $client $state $priority_id $my_open";
    $sql_count = db_rewrite_sql($sql_count);
    $result = pager_query($sql, 50, 0, $sql_count);
    $rows = array();
jeremy’s picture

Status: Active » Needs work

I don't recognize the format of your patch. Please follow these instructions and attach it as a file.

How exactly would this feature be used? I don't see an API here...?

jeremy’s picture

Status: Needs work » Closed (fixed)

No further feedback, closing.