You are here

function template_preprocess_views_simpleads in SimpleAds 7.2

Same name and namespace in other branches
  1. 7 includes/simpleads.theme.inc \template_preprocess_views_simpleads()

Preprocess for SimpleAds Views template. views-simpleads.tpl.php

File

includes/theme.inc, line 94
SimpleAds theme.

Code

function template_preprocess_views_simpleads(&$vars) {
  $view = $vars['view'];
  $rows = $vars['rows'];
  $style = $view->style_plugin;
  $options = $style->options;
  if ($options['plugin'] == 'jquery.cycle') {
    $jquery_cycle = libraries_get_path($options['plugin']);
    drupal_add_js($jquery_cycle . '/jquery.cycle.all.js');
    drupal_add_js(drupal_get_path('module', 'simpleads') . '/js/simpleads.cycle.js');
  }
  $vars['classes_array'] = array();
  $vars['classes'] = array();
  $vars['node_id'] = array();
  $vars['type'] = array();
  $vars['entity'] = array();

  // View options
  $vars['options'] = $options;
  $default_row_class = isset($options['default_row_class']) ? $options['default_row_class'] : FALSE;
  $row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : FALSE;

  // Set up striping values.
  $count = 0;
  $max = count($rows);
  foreach ($rows as $id => $row) {
    $count++;
    $vars['classes'][$id][] = 'simpleads-item';
    $vars['classes'][$id][] = 'simpleads-item-' . $count;
    $vars['node_id'][$id] = $view->result[$id]->nid;

    // Get entity language
    $language = isset($view->result[$id]->_field_data['nid']['entity']->language) ? $view->result[$id]->_field_data['nid']['entity']->language : LANGUAGE_NONE;
    $vars['type'][$id] = $view->result[$id]->_field_data['nid']['entity']->field_ad_type[$language][0]['value'];
    $vars['entity'][$id] = $view->result[$id]->_field_data['nid']['entity'];
    if ($row_class_special) {
      $vars['classes'][$id][] = 'simpleads-item-' . ($count % 2 ? 'odd' : 'even');
    }
    if ($count == 1) {
      $vars['classes'][$id][] = 'first';
    }
    if ($count == $max) {
      $vars['classes'][$id][] = 'last';
    }
    if ($row_class = $view->style_plugin
      ->get_row_class($id)) {
      $vars['classes'][$id][] = $row_class;
    }

    // Flatten the classes to a string for each row for the template file.
    $vars['classes_array'][$id] = isset($vars['classes'][$id]) ? implode(' ', $vars['classes'][$id]) : '';
  }
}