You are here

function support_overview_page_user in Support Ticketing System 7

Same name and namespace in other branches
  1. 6 support_overview/support_overview.module \support_overview_page_user()
1 call to support_overview_page_user()
support_overview_page_users in support_overview/support_overview.module
1 string reference to 'support_overview_page_user'
support_overview_menu in support_overview/support_overview.module
Implements hook_menu().

File

support_overview/support_overview.module, line 448
support_overview.module

Code

function support_overview_page_user($account, $all = FALSE, $page = TRUE) {
  global $user;
  $output = '';
  if ($page) {
    drupal_add_css(drupal_get_path('module', 'support_overview') . '/support-overview.css');
    $output = '<div class="support-overview">';
    if ($user->uid == $account->uid) {
      drupal_set_title(t('My ticket overview'));
    }
    else {
      drupal_set_title(t("@username's ticket overview", array(
        '@username' => $account->name,
      )));
    }
    $breadcrumb = array();
    $breadcrumb[] = l(t('Home'), NULL);
    $breadcrumb[] = l($account->name, "user/{$account->uid}");
    drupal_set_breadcrumb($breadcrumb);
  }
  $enabled_clients = variable_get('support_overview_clients', array());
  $all_clients = _support_available_clients();
  if ($all || !is_array($enabled_clients) || empty($enabled_clients)) {
    $enabled_clients = array();
    foreach ($all_clients as $clid => $client) {
      $enabled_clients[] = $clid;
    }
    $all = TRUE;
  }
  $header = array(
    t('Client'),
    t('Tickets'),
  );
  $rows = array();
  $current_row = 0;
  foreach ($enabled_clients as $clid) {
    if (isset($all_clients[$clid])) {
      $total_sql = db_select('support_ticket')
        ->condition('client', $clid)
        ->condition('assigned', $account->uid);
      $total_sql
        ->addExpression('COUNT(nid)');
      $enabled_states = variable_get('support_overview_states', array());

      // [0] == 'All'
      if (!empty($enabled_states) && !isset($enabled_states[0])) {
        $total_sql
          ->condition('state', $enabled_states);
      }
      $count = $total_sql
        ->execute()
        ->fetchField();
      if ($count) {
        $client = support_client_load($clid);
        $rows[$current_row][] = '<a href="' . url(support_queue_url($client)) . '" class="support-overview-title">' . check_plain($client->name) . '</a>';
        $latest_sql = db_select('node', 'n');
        $latest_sql
          ->leftJoin('support_ticket', 't', 'n.nid = t.nid');
        $latest_sql
          ->innerJoin('node_comment_statistics', 'l', 'n.nid = l.nid');
        $latest_sql
          ->addExpression('GREATEST(n.changed, l.last_comment_timestamp)', 'last_update');
        $latest_sql
          ->addField('n', 'nid');
        $latest_sql
          ->condition('t.client', $clid);
        $latest_sql
          ->condition('assigned', $account->uid);
        $latest_sql
          ->range(0, 1);

        // [0] == 'All'
        if (!empty($enabled_states) && !isset($enabled_states[0])) {
          $latest_sql
            ->condition('state', $enabled_states);
        }
        $oldest_sql = clone $latest_sql;
        $latest_sql
          ->orderBy('last_update', 'DESC');
        $oldest_sql
          ->orderBy('last_update', 'ASC');
        $latest = $latest_sql
          ->execute()
          ->fetch();
        $latest_alert = _support_overview_alert($latest->last_update);
        $node = node_load($latest->nid);
        $latest_update = t('most recent: !time ago, "!title"', array(
          '!time' => format_interval(time() - $latest->last_update),
          '!title' => l($node->title, "node/{$latest->nid}"),
        ));
        $oldest_alert = '';
        if ($count > 1) {
          $oldest = $oldest_sql
            ->execute()
            ->fetch();
          $oldest_alert = _support_overview_alert($oldest->last_update);
          $node = node_load($oldest->nid);
          $oldest_update = t('oldest: !time ago, "!title"', array(
            '!time' => format_interval(time() - $oldest->last_update),
            '!title' => l($node->title, "node/{$oldest->nid}"),
          ));
        }
        else {
          $oldest_update = '';
        }
        $rows[$current_row][] = t('!total !latest !oldest', array(
          '!total' => "<span class='support-overview-total'>{$count}</span>",
          '!latest' => "<div class='support-overview-latest {$latest_alert}'>{$latest_update}</div>",
          '!oldest' => "<div class='support-overview-oldest {$oldest_alert}'>{$oldest_update}</div>",
        ));
      }
      $current_row++;
    }
  }
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
  if ($page) {
    $output .= '<div class="support-overview-link">' . l($all ? t('selected clients') : t('all clients'), $all ? "support/overview/user/{$account->uid}" : "support/overview/user/{$account->uid}/all") . '</div>';
    $output .= '</div>';
  }
  return $output;
}