You are here

function casetracker_comment_view in Case Tracker 7

Implements hook_comment_view().

File

./casetracker.module, line 484
Enables the handling of projects and their cases.

Code

function casetracker_comment_view($comment) {

  // Load the node here anyway -- it is almost certainly static cached already.
  $node = is_array($comment) ? node_load($comment['nid']) : node_load($comment->nid);

  // Bail if this is not a casetracker node.
  if (!casetracker_is_case($node->type)) {
    return;
  }

  // If this is a preview we won't have a cid yet.
  if (empty($comment->cid)) {
    $case_data['new'] = (object) $comment->casetracker;
    $case_data['new']->assign_to = casetracker_get_uid($case_data['new']->assign_to);
    $case = node_load($comment->nid);
    $case_data['old'] = drupal_clone($case->casetracker);
  }
  else {
    $results = db_select('casetracker_comment_status', 'c')
      ->fields('c', array(
      'cid',
      'pid',
      'title',
      'case_status_id',
      'assign_to',
      'case_priority_id',
      'case_type_id',
      'state',
    ))
      ->condition('c.cid', $comment->cid)
      ->execute();
    foreach ($results as $result) {
      $state = $result->state ? 'new' : 'old';
      $case_data[$state] = $result;
    }
  }
  $comment->content['comment_body'][0]['#markup'] = theme('casetracker_comment_changes', array(
    'old' => $case_data['old'],
    'new' => $case_data['new'],
  )) . $comment->content['comment_body'][0]['#markup'];
}