Add basic support for summary styles; they don't quite work yet because view URL...
[project/views.git] / theme / theme.inc
1 <?php
2 // $Id$
3
4 /**
5 * Preprocess the primary theme implementation for a view.
6 */
7 function template_preprocess_views_view(&$vars) {
8 $view = $vars['view'];
9
10 $vars['rows'] = $view->style_handler->render($view->result);
11 $vars['css_name'] = views_css_safe($view->name);
12
13 if (!$vars['rows']) {
14 $vars['empty'] = $view->display_handler->render_empty();
15 }
16 else {
17 $vars['empty'] = '';
18 }
19
20 $vars['filters'] = $view->display_handler->render_filters();
21 $vars['header'] = $view->display_handler->render_header();
22 $vars['footer'] = $view->display_handler->render_footer();
23 $vars['more'] = $view->display_handler->render_more_link();
24 $vars['feed_icon'] = $view->display_handler->render_feed_icon();
25
26 $vars['pager'] = '';
27 if (!empty($view->use_pager)) {
28 $vars['pager'] = theme('pager', array(), $view->page_size, $view->page_element);
29 }
30
31 }
32
33 /**
34 * Preprocess theme function to print a single record from a row, with fields
35 */
36 function template_preprocess_views_view_row(&$vars) {
37 $view = $vars['view'];
38
39 // Loop through the fields for this view.
40 foreach ($view->get_fields($view->current_display) as $field) {
41 $themes = array(
42 'views_view_field__' . $view->name . '__' . $field->handler->field_alias,
43 'views_view_field__' . $view->name,
44 'views_view_field__' . $field->handler->field_alias,
45 'views_view_field',
46 );
47 // Add the field into a variable named after the field. field_alias will be unique.
48 $vars[$field->handler->field_alias] = theme($themes, $view, $field, $vars['row']);
49 // Create a second variable so we can easily find what fields we have and what the
50 // CSS classes should be.
51 $vars['fields'][$field->handler->field_alias] = views_css_safe($field->handler->field_alias);
52 }
53 }
54
55 /**
56 * Display a single views field.
57 *
58 * Interesting bits of info:
59 * $field->field_alias says what the raw value in $row will be. Reach it like
60 * this: @code { $row->{$field->field_alias} @endcode
61 */
62 function theme_views_view_field($view, $field, $row) {
63 return $field->handler->render($row);
64 }
65
66 /**
67 * Preprocess theme function to print a single record from a row, with fields
68 */
69 function template_preprocess_views_view_row_summary(&$vars) {
70 $view = $vars['view'];
71 $row = $vars['row'];
72 $argument = $view->argument[$view->build_info['summary_level']]->handler;
73
74 $vars['link'] = check_plain($row->{$argument->name_alias});
75 $vars['url'] = $argument->summary_link($row, $view->get_url());
76 $vars['count'] = intval($row->{$argument->count_alias});
77 }
78