You are here

function theme_casetracker_case_summary in Case Tracker 7

Same name and namespace in other branches
  1. 5 casetracker.module \theme_casetracker_case_summary()
  2. 6 casetracker.module \theme_casetracker_case_summary()

Theme the case summary shown at the beginning of a case's node.

Parameters

$case: The node object of the case being viewed.

$project: The node object of the project this case belongs to.

1 theme call to theme_casetracker_case_summary()
casetracker_node_view in ./casetracker.module
Implements hook_node_view().

File

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

Code

function theme_casetracker_case_summary($variables) {
  $project = $variables['project'];
  $case = $variables['case'];
  $last_comment = db_select('node_comment_statistics', 'n')
    ->fields('n', array(
    'last_comment_timestamp',
  ))
    ->condition('n.nid', $case->nid)
    ->execute()
    ->fetchField();
  $rows = array();

  // On node preview the form logic can't translate assign_to back to a uid for
  // us so we need to be able handle it either way.
  $assign_to = NULL;
  if (is_numeric($case->casetracker->assign_to)) {
    $assign_to = user_load($case->casetracker->assign_to);
  }
  elseif ($case->casetracker->assign_to && $case->casetracker->assign_to != t('Unassigned')) {
    $assign_to = reset(user_load_multiple(array(), array(
      'name' => $case->casetracker->assign_to,
    )));
  }
  if (empty($assign_to) || $assign_to->uid == 0) {
    $rows[] = array(
      t('Assigned to:'),
      '<em>' . t('Unassigned') . '</em>',
    );
  }
  else {
    $rows[] = array(
      t('Assigned to:'),
      theme('username', array(
        'account' => $assign_to,
      )),
    );
  }
  $rows[] = array(
    t('Created:'),
    t('!username at !date', array(
      '!username' => theme('username', array(
        'account' => $case,
      )),
      '!date' => format_date($case->created, 'medium'),
    )),
  );
  $rows[] = array(
    t('Status:'),
    t('<strong>@status</strong> (@type / Priority @priority)', array(
      '@status' => casetracker_case_state_load($case->casetracker->case_status_id, 'status'),
      '@type' => casetracker_case_state_load($case->casetracker->case_type_id, 'type'),
      '@priority' => casetracker_case_state_load($case->casetracker->case_priority_id, 'priority'),
    )),
  );

  // On node preview a case may not have a nid, so we use some placeholder text.
  $case_id = isset($case->nid) ? $case->nid : t("NEW");
  $rows[] = array(
    t('Case ID:'),
    l($project->title, 'node/' . $case->casetracker->pid) . ': ' . $project->nid . '-' . $case_id,
  );
  if ($last_comment && $last_comment != $case->created) {
    $rows[] = array(
      t('Last modified:'),
      format_date($last_comment, 'medium'),
    );
  }
  $output = '<div class="case">';
  $output .= theme('table', array(
    'header' => NULL,
    'rows' => $rows,
    'attributes' => array(
      'class' => 'summary',
    ),
  ));
  $output .= '</div>';
  return $output;
}