You are here

function _support_comment_insert_update in Support Ticketing System 7

2 calls to _support_comment_insert_update()
support_comment_insert in ./support.module
Implementation of hook_comment_insert().
support_comment_update in ./support.module
Implementation of hook_comment_update().

File

./support.module, line 1072
support.module

Code

function _support_comment_insert_update($comment) {
  if (isset($comment->assigned) && !is_numeric($comment->assigned)) {
    $assigned = db_query("SELECT uid FROM {users} WHERE name = :name", array(
      ':name' => $comment->assigned,
    ))
      ->fetchField();
    if ($assigned) {
      $comment->assigned = $assigned;
    }
    else {
      $comment->assigned = 0;
    }
  }
  $exists = db_select('support_ticket_comment', 't')
    ->fields('t')
    ->condition('t.cid', $comment->cid)
    ->execute()
    ->rowCount();
  if ($exists) {
    $update = db_update('support_ticket_comment')
      ->fields(array(
      'message_id' => isset($comment->message_id) ? $comment->message_id : '',
      'state' => $comment->state,
      'priority' => $comment->priority,
      'client' => $comment->client,
      'assigned' => $comment->assigned,
    ))
      ->condition('cid', $comment->cid)
      ->execute();
  }
  else {
    db_insert('support_ticket_comment')
      ->fields(array(
      'cid' => $comment->cid,
      'message_id' => isset($comment->message_id) ? $comment->message_id : '',
      'state' => $comment->state,
      'priority' => $comment->priority,
      'client' => $comment->client,
      'assigned' => $comment->assigned,
    ))
      ->execute();

    // The first update to a ticket is not preserved in the database.
    // Store it in an array allowing other modules to dectect/respond to
    // ticket changes.
    $comment->previous = new stdClass();
    $comment->previous->state = $comment->state;
    $comment->previous->priority = $comment->priority;
    $comment->previous->client = $comment->client;
    $comment->previous->assigned = $comment->assigned;
  }
  _support_comment_update_node($comment->nid);
}