You are here

function support_substatus_nodeapi in Support Ticketing System 6

Implementation of hook_nodeapi().

File

support_substatus/support_substatus.module, line 66
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_nodeapi(&$node, $op, $teaser, $page) {
  if ($node->type == 'support_ticket') {
    switch ($op) {

      // Notifications are sent before hook_nodeapi insert/update is invoked, so
      // we cache the value from op_presave.
      case 'presave':
        $substatus = isset($node->substatus) ? (int) $node->substatus : 0;
        if ($substatus) {
          _support_substatus_notification_static($substatus);
        }
        break;
      case 'view':
        if (user_access('view support substatus') && _support_substatus_client_active($node->client)) {
          if ($substatus = support_substatus_load_nid($node->nid)) {
            $node->content['support-substatus'] = array(
              '#value' => "<div class='support-priority'>Status: " . check_plain($substatus->substatus) . '</div>',
              '#weight' => -1,
            );
          }
        }
        break;
      case 'load':
        $node->substatus = support_substatus_load_nid($node->nid);
        break;
      case 'insert':
      case 'update':
        db_query("UPDATE {support_substatus_ticket} SET subid = %d WHERE type = 'node' AND id = %d", $node->substatus, $node->nid);
        if (!db_affected_rows()) {
          db_query("INSERT INTO {support_substatus_ticket} (subid, type, id, nid, current) VALUES(%d, 'node', %d, %d, %d)", $node->substatus, $node->nid, $node->nid);
        }
        _support_substatus_set_current($node->nid);
        break;
      case 'delete':
        db_query("DELETE FROM {support_substatus_ticket} WHERE nid = %d", $node->nid);
        break;
    }
  }
}