You are here

function support_substatus_comment in Support Ticketing System 6

File

support_substatus/support_substatus.module, line 113
Support Substatus -- allows per-status sub-status values, so for example a "pending" ticket can be further marked with "needs review", etc. @author Jeremy Andrews <jeremy@tag1consulting.com> @package Support

Code

function support_substatus_comment(&$comment, $op) {
  if (is_array($comment)) {
    $node = node_load($comment['nid']);
    $cid = $comment['cid'];
  }
  else {
    $node = node_load($comment->nid);
    $cid = $comment->cid;
  }
  if ($node->type == 'support_ticket') {
    switch ($op) {

      // Notifications are sent before hook_comment insert/update is invoked, so
      // we cache the value from op_validate.
      case 'validate':
        $substatus = isset($comment['substatus']) ? (int) $comment['substatus'] : 0;
        if ($substatus) {
          _support_substatus_notification_static($substatus);
        }
        break;
      case 'view':
        if (user_access('view support substatus') && _support_substatus_client_active($node->client)) {
          static $old_substatus = 0;
          if (!$old_substatus) {
            $ss = support_substatus_load_nid($node->nid);
            if (is_object($ss) && isset($ss->substatus)) {
              $old_substatus = $ss->substatus;
            }
          }
          $substatus = support_substatus_load_nid($node->nid, $cid);
          if ($new_substatus = check_plain($substatus->substatus)) {
            if ($new_substatus != $old_substatus) {
              $comment->comment = "<div class='support-priority'>Status: {$old_substatus} -> {$new_substatus}</div>" . $comment->comment;
            }
            else {
              if ($new_substatus) {
                $comment->comment = "<div class='support-priority'>Status: {$new_substatus}</div>" . $comment->comment;
              }
            }
            $old_substatus = $new_substatus;
          }
          else {
            if ($old_substatus) {
              $comment->comment = "<div class='support-priority'>Status: {$old_substatus}</div>" . $comment->comment;
            }
          }
        }
        break;
      case 'insert':
      case 'update':
        db_query("UPDATE {support_substatus_ticket} SET subid = %d, nid = %d WHERE type = 'comment' AND id = %d", $comment['substatus'], $comment['nid'], $comment['cid']);
        if (!db_affected_rows()) {
          @db_query("INSERT INTO {support_substatus_ticket} (subid, type, id, nid) VALUES(%d, 'comment', %d, %d)", $comment['substatus'], $comment['cid'], $comment['nid']);
        }
        _support_substatus_set_current($node->nid);
        break;
      case 'delete':
        db_query("DELETE FROM {support_substatus_ticket} WHERE type = 'comment' AND id = %d", $comment->cid);
        _support_substatus_set_current($comment->nid);
        break;
    }
  }
}