You are here

function views_theme_wizard_type_generate_code_grouped in Views (for Drupal 7) 5

1 call to views_theme_wizard_type_generate_code_grouped()
views_theme_wizard_views_theme_wizard_types in ./views_theme_wizard.module

File

./views_theme_wizard.module, line 338

Code

function views_theme_wizard_type_generate_code_grouped($view, $options) {
  $group_field = $options['group_field'];
  $code = <<<EOT
function phptemplate_views_view_list_{<span class="php-variable">$view</span>-&gt;<span class="php-function-or-constant property member-of-variable">name</span>}(\$view, \$nodes, \$type) {
  \$fields = _views_get_fields();

  \$taken = array();

  // Group our nodes
  \$set = array();
  foreach (\$nodes as \$node) {
    \$set[\$node->{<span class="php-variable">$group_field</span>}][] = \$node;
  }

  // Set up the fields in nicely named chunks.
  foreach (\$view->field as \$id => \$field) {
    \$field_name = \$field['field'];
    if (isset(\$taken[\$field_name])) {
      \$field_name = \$field['queryname'];
    }
    \$taken[\$field_name] = true;
    \$field_names[\$id] = \$field_name;
  }

  // Set up some variables that won't change.
  \$base_vars = array(
    'view' => \$view,
    'view_type' => \$type,
  );

  \$output = '';
  foreach (\$set as \$label => \$nodes) {
    \$items = array();
    foreach (\$nodes as \$i => \$node) {
      \$vars = \$base_vars;
      \$vars['node'] = \$node;
      \$vars['count'] = \$i;
      \$vars['stripe'] = \$i % 2 ? 'even' : 'odd';
      foreach (\$view->field as \$id => \$field) {
        \$name = \$field_names[\$id];
        \$vars[\$name] = views_theme_field('views_handle_field', \$field['queryname'], \$fields, \$field, \$node, \$view);
        if (isset(\$field['label'])) {
          \$vars[\$name . '_label'] = \$field['label'];
        }
      }
      \$items[] = _phptemplate_callback('views-list-{<span class="php-variable">$view</span>-&gt;<span class="php-function-or-constant property member-of-variable">name</span>}', \$vars);
    }
    if (\$items) {
      \$output .= theme('item_list', \$items, \$label);
    }
  }
  return \$output;
}
EOT;
  return $code;
}