You are here

function template_preprocess_views_maintenance_views_table in Views Maintenance 7

Same name and namespace in other branches
  1. 6 theme/theme.inc \template_preprocess_views_maintenance_views_table()

Prepares views info for output and includes required CSS/JS.

Parameters

array $vars:

File

theme/theme.inc, line 122
Preprocessing and theming functions for Views Maintenance.

Code

function template_preprocess_views_maintenance_views_table(&$vars) {

  // Add primary views table header.
  $vars['views_header'] = array(
    array(
      'data' => ' ',
      'class' => 'views-mnt-view-toggle-all',
    ),
    array(
      'data' => t('View name'),
      'field' => 'name',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Type'),
      'field' => 'type',
    ),
    array(
      'data' => t('Storage'),
      'field' => 'storage',
    ),
    array(
      'data' => t('Status'),
      'field' => 'status',
    ),
    array(
      'data' => t('Actions'),
      'class' => 'views-mnt-view-links',
    ),
  );

  // Add headers for display tables.
  $vars['displays_header'] = array(
    t('Name'),
    t('Type'),
    t('Status'),
    t('Use case'),
    t('Description'),
    t('Actions'),
  );

  // Theme thead.
  $vars['thead'] = theme('views_maintenance_views_thead', array(
    'header' => $vars['views_header'],
  ));
  if (isset($vars['views']) && is_array($vars['views'])) {

    // Sort views before replacing storage and status with themed values.
    _views_maintenance_views_sort($vars['views'], $vars['views_header']);

    // Convert display status info to table and prepare view info for printing.
    foreach ($vars['views'] as $view_id => &$view_info) {
      $rows = array();
      foreach ($view_info['displays'] as $display_id => $display_info) {

        // Convert associative arrays to table rows.
        $first = TRUE;
        foreach ($display_info['use_cases'] as $use_case) {

          // Description can be an array or HTML string.
          $description = '';
          if (!empty($use_case['description'])) {
            $description = theme('item_list', array(
              'items' => array(
                $use_case['description'],
              ),
            ));
          }
          $use_case_row = array(
            theme('views_maintenance_display_status', array(
              'status' => $use_case['status'],
            )),
            isset($use_case['type']) ? $use_case['type'] : '',
            $description,
            !empty($use_case['links']) ? theme('item_list', array(
              'items' => $use_case['links'],
            )) : '',
          );
          if ($first) {

            // Add name and type to the first row of this display.
            array_unshift($use_case_row, array(
              'data' => check_plain($display_info['name']),
              'rowspan' => count($display_info['use_cases']),
              'class' => array(
                'views-mnt-display-name',
              ),
            ), array(
              'data' => check_plain($display_info['type']),
              'rowspan' => count($display_info['use_cases']),
              'class' => array(
                'views-mnt-display-type',
              ),
            ));
            $first = FALSE;
          }
          $rows[] = $use_case_row;
        }
      }
      $view_info['name'] = check_plain($view_info['name']);

      // Save displays table.
      $view_info['rows'] = $rows;
      $view_info['table'] = theme('table', array(
        'header' => $vars['displays_header'],
        'rows' => $view_info['rows'],
        'attributes' => array(
          'class' => array(
            'views-mnt-display-table',
          ),
        ),
      ));

      // Convert links array to string.
      $view_info['links'] = implode(' | ', $view_info['links']);

      // Theme view status and storage.
      $view_info['status'] = theme('views_maintenance_view_status', array(
        'status' => $view_info['status'],
      ));
      $view_info['storage'] = theme('views_maintenance_view_storage', array(
        'type' => $view_info['storage'],
      ));

      // Filter view description.
      $view_info['description'] = trim($view_info['description']) != '' ? check_plain($view_info['description']) : NULL;
    }
  }

  // Include required JS and CSS.
  $module_path = drupal_get_path('module', 'views_maintenance');
  drupal_add_css($module_path . '/css/views-maintenance-admin.css');
  drupal_add_js($module_path . '/js/views-maintenance-admin.js');
}