You are here

function template_preprocess_views_showcase_view in Views Showcase 7

Same name and namespace in other branches
  1. 6.2 views_showcase.module \template_preprocess_views_showcase_view()
  2. 6 views_showcase.module \template_preprocess_views_showcase_view()

Implementation of template preprocess for the view.

File

./views_showcase.module, line 20
The implementation of Views Showcase module.

Code

function template_preprocess_views_showcase_view(&$vars) {
  $view = $vars['view'];
  $options = $view->style_plugin->options;

  // Values to pass to the template
  $vars['skin'] = $options['skin'];
  $vars['views_showcase_id'] = 'views-showcase-' . $view->name . '-' . $view->current_display;

  // Passing the display title, translated if i18nviews is enabled
  if (isset($view->display[$view->current_display]->display_options['title'])) {
    $untranslated_title = $view->display[$view->current_display]->display_options['title'];

    // For i18nviews integration
    $i18nstrings_context = 'views:' . $view->name . ':' . $view->current_display . ':title';
  }
  else {
    $untranslated_title = $view->display['default']->display_options['title'];

    // For i18nviews integration
    $i18nstrings_context = 'views:' . $view->name . ':default:title';
  }
  if (function_exists('i18nstrings')) {
    $vars['display_title'] = i18nstrings($i18nstrings_context, $untranslated_title);
  }
  else {
    $vars['display_title'] = $untranslated_title;
  }
  drupal_add_js(array(
    'views_showcase' => array(
      'easing' => $options['easing'],
      'cycle' => $options['cycle'],
      'sync' => $options['sync'],
      'timeout' => $options['timeout'],
      'listPause' => $options['listpause'],
      'pause' => $options['pause'],
    ),
  ), 'setting');
  $libs = views_showcase_get_libraries();
  drupal_add_js($libs['cycle']);
  if (!empty($options['easing'])) {
    drupal_add_js($libs['easing']);
  }
  drupal_add_js(drupal_get_path('module', 'views_showcase') . '/js/views_showcase.js', 'file');
  drupal_add_css(drupal_get_path('module', 'views_showcase') . '/css/views_showcase.css', array(
    'type' => 'file',
    'weight' => 5,
    'group' => CSS_THEME,
  ));
  $is_row_odd = TRUE;

  //Looping through the rows returned by the view to pass them in a proper structure to the template
  foreach ($view->result as $row_index => $row_to_render) {

    //Adding classes
    $classes = array();
    $classes[] = 'views-row';
    $classes[] = 'views-row-' . ($row_index + 1);
    if ($is_row_odd) {
      $classes[] = 'views-row-odd';
    }
    else {
      $classes[] = 'views-row-even';
    }
    if ($row_index === 0) {
      $classes[] = 'views-row-first';
    }
    if ($row_index === count($view->result) - 1) {
      $classes[] = 'views-row-last';
    }
    $nav_box_classes = $classes;
    $nav_box_classes[] = 'views-showcase-pager-item';
    $nav_box_classes = implode(' ', $nav_box_classes);
    $big_box_classes = $classes;
    $big_box_classes[] = 'views-showcase-item';
    $big_box_classes = implode(' ', $big_box_classes);
    $vars['structured_rows'][$row_index]['nav_box_classes'] = $nav_box_classes;
    $vars['structured_rows'][$row_index]['big_box_classes'] = $big_box_classes;
    $vars['structured_rows'][$row_index]['anchor_name'] = 'showcase-' . $vars['views_showcase_id'] . '-' . $row_index;
    $is_row_odd = !$is_row_odd;

    //Looping through the fields of each returned row
    foreach ($view->field as $id => $field) {

      // Render this even if set to exclude so it can be used elsewhere.
      $field_output = $view->field[$id]
        ->theme($row_to_render);
      if (empty($field->options['exclude'])) {
        $object = new stdClass();
        $object->content = $field_output;
        $object->handler =& $view->field[$id];
        $object->element_type = $object->handler
          ->element_type();

        //$object->class = views_css_safe($id);
        $object->label = check_plain($view->field[$id]
          ->label());

        //First assume this field doesn't appear anywhere
        $object->big_box = FALSE;
        $object->navigation_box = FALSE;
        $object->link_anchor = FALSE;

        //Setting the flags for each field in the row according to the what was chosen in the settings
        if (isset($options['showcase_display_options']['big_box_field'][$id]) && $options['showcase_display_options']['big_box_field'][$id] != '0') {
          $object->big_box = TRUE;
        }
        if (isset($options['showcase_display_options']['link_anchor_field'][$id]) && $options['showcase_display_options']['link_anchor_field'][$id] != '0') {
          $object->link_anchor = TRUE;
        }
        if (isset($options['showcase_display_options']['navigation_box_field'][$id]) && $options['showcase_display_options']['navigation_box_field'][$id] != '0') {
          $object->navigation_box = TRUE;
        }

        //Now send the structured row objects to the template
        $vars['structured_rows'][$row_index][$id] = $object;
      }
    }
  }
}