You are here

function template_preprocess_tablesorter_view in Tablesorter 7

Preprocessor function for the tablesorter style.

File

./tablesorter.module, line 197
Tablesorter.

Code

function template_preprocess_tablesorter_view(&$vars) {
  $view = $vars['view'];
  tablesorter_attach($vars);
  $result = $vars['result'] = $vars['rows'];
  $vars['rows'] = array();
  $vars['col_count'] = 0;
  $options = $view->style_plugin->options;
  $handler = $view->style_plugin;
  $fields =& $view->field;
  $columns = $handler
    ->sanitize_columns($options['columns'], $fields);

  // Fields must be rendered in order as of Views 2.3
  // so we will pre-render everything.
  $renders = $handler
    ->render_fields($result);
  foreach ($columns as $field => $column) {

    // Render the header labels.
    if ($field == $column && empty($fields[$field]->options['exclude'])) {
      $label = !empty($fields[$field]) ? check_plain($fields[$field]
        ->label()) : '';
      $vars['header'][$field] = $label;
      $vars['col_count']++;
    }

    // Render each field into its appropriate column.
    foreach ($result as $num => $row) {
      if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) {
        $field_output = $renders[$num][$field];
        if (!isset($vars['rows'][$num][$column])) {
          $vars['rows'][$num][$column] = '';
        }

        // Don't bother with separators and stuff if the field does not show up.
        if ($field_output === '') {
          continue;
        }

        // Place the field into the column, along with an optional separator.
        if ($vars['rows'][$num][$column] !== '') {
          if (!empty($options['info'][$column]['separator'])) {
            $vars['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']);
          }
        }
        $vars['rows'][$num][$column] .= $field_output;
      }
    }
  }
  $count = 0;
  foreach ($vars['rows'] as $num => $row) {
    $vars['row_classes'][$num][] = $count++ % 2 == 0 ? 'odd' : 'even';
  }
  $vars['row_classes'][0][] = 'views-row-first';
  $vars['row_classes'][count($vars['row_classes']) - 1][] = 'views-row-last';
  $vars['class'] = 'tablesorter';
  if (!empty($options['sticky'])) {
    drupal_add_js('misc/tableheader.js');
    $vars['class'] .= " sticky-enabled";
  }
  $vars['class'] .= ' cols-' . count($vars['rows']);
  $vars['tvpager'] = $options['elements']['tablesorter_views_pager'];
}