You are here

function theme_casetracker_comment_changes in Case Tracker 7

Same name and namespace in other branches
  1. 6 casetracker.module \theme_casetracker_comment_changes()

Displays the changes a comment has made to the case fields.

Parameters

$case_data: An array of both 'old' and 'new' objects that contains the before and after values this comment has changed.

1 theme call to theme_casetracker_comment_changes()
casetracker_comment_view in ./casetracker.module
Implements hook_comment_view().

File

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

Code

function theme_casetracker_comment_changes($variables) {
  $old = $variables['old'];
  $new = $variables['new'];
  $rows = array();
  $fields = array(
    'pid' => t('Project'),
    'title' => t('Title'),
    'case_status_id' => t('Status'),
    'assign_to' => t('Assigned'),
    'case_priority_id' => t('Priority'),
    'case_type_id' => t('Type'),
  );
  foreach ($fields as $field => $label) {
    if ($new->{$field} != $old->{$field}) {
      switch ($field) {
        case 'pid':
          $old_title = db_select('node', 'n')
            ->fields('n', array(
            'title',
          ))
            ->condition('n.nid', $old->pid)
            ->execute()
            ->fetchField();
          $new_title = db_select('node', 'n')
            ->fields('n', array(
            'title',
          ))
            ->condition('n.nid', $new->pid)
            ->execute()
            ->fetchField();
          $old->{$field} = l($old_title, "node/{$old->pid}");
          $new->{$field} = l($new_title, "node/{$new->pid}");
          break;
        case 'case_status_id':
          $old->{$field} = check_plain(casetracker_case_state_load($old->{$field}, 'status'));
          $new->{$field} = check_plain(casetracker_case_state_load($new->{$field}, 'status'));
          break;
        case 'assign_to':
          $old->{$field} = check_plain(casetracker_get_name($old->{$field}));
          $new->{$field} = check_plain(casetracker_get_name($new->{$field}));
          break;
        case 'case_priority_id':
          $old->{$field} = check_plain(casetracker_case_state_load($old->{$field}, 'priority'));
          $new->{$field} = check_plain(casetracker_case_state_load($new->{$field}, 'priority'));
          break;
        case 'case_type_id':
          $old->{$field} = check_plain(casetracker_case_state_load($old->{$field}, 'type'));
          $new->{$field} = check_plain(casetracker_case_state_load($new->{$field}, 'type'));
          break;
      }
      $rows[] = array(
        t('@label: !old » !new', array(
          '@label' => $label,
          '!old' => $old->{$field},
          '!new' => $new->{$field},
        )),
      );
    }
  }
  if (!empty($rows)) {
    return theme('table', array(
      'header' => NULL,
      'rows' => $rows,
      'attributes' => array(
        'class' => 'case_changes',
      ),
    ));
  }
}