Commit cb1b8e01 authored by merlinofchaos's avatar merlinofchaos

#248999: (by eaton) Grid style that uses a simple table to display a grid in X columns.

parent 20aff9d4
......@@ -74,3 +74,7 @@ div.view:hover div.views-hide {
margin-top: -1.5em;
}
/* Remove the border on tbody that system puts in */
.views-view-grid tbody {
border-top: none;
}
\ No newline at end of file
......@@ -86,6 +86,15 @@ function views_views_plugins() {
'uses options' => TRUE,
'type' => 'normal',
),
'grid' => array(
'title' => t('Grid'),
'help' => t('Displays rows in a grid.'),
'handler' => 'views_plugin_style_grid',
'theme' => 'views_view_grid',
'uses row plugin' => TRUE,
'uses options' => TRUE,
'type' => 'normal',
),
'table' => array(
'title' => t('Table'),
'help' => t('Displays rows in a table.'),
......@@ -2405,17 +2414,6 @@ class views_plugin_style extends views_plugin {
* @param $rows
* The full results of the query, loaded into an array of objects.
*/
function render($rows) { }
}
/**
* Default style plugin to render rows one after another with no
* decorations.
*/
class views_plugin_style_default extends views_plugin_style {
/**
* Render the given style.
*/
function render() {
if (empty($this->row_plugin)) {
vpr('views_plugin_style_default: Missing row plugin');
......@@ -2423,14 +2421,22 @@ class views_plugin_style_default extends views_plugin_style {
}
$rows = array();
foreach ($this->view->result as $row) {
// @todo: Include separator as an option.
$rows[] = $this->row_plugin->render($row);
}
// $theme = views_theme_functions('views_view_unformatted', $this->view, $this->display);
return theme($this->theme_functions(), $this->view, $this->options, $rows);
}
}
/**
* Default style plugin to render rows one after another with no
* decorations.
*/
class views_plugin_style_default extends views_plugin_style {
function options_form(&$form, &$form_state) {
// @todo -- separator option
}
}
/**
* Style plugin to render each item in an ordered or unordered list
*/
......@@ -2455,22 +2461,30 @@ class views_plugin_style_list extends views_plugin_style {
'#default_value' => $this->options['type'],
);
}
}
/**
* Style plugin to render each item in a grid cell.
*/
class views_plugin_style_grid extends views_plugin_style {
/**
* Render the list style.
* Set default options
*/
function render() {
if (empty($this->row_plugin)) {
vpr('views_plugin_style_list: Missing row plugin');
return;
}
function options($display) {
return array(
'columns' => 4,
);
}
$rows = array();
foreach ($this->view->result as $row) {
$rows[] = $this->row_plugin->render($row);
}
// $theme = views_theme_functions('views_view_list', $this->view, $this->display);
return theme($this->theme_functions(), $this->view, $this->options, $rows);
/**
* Render the given style.
*/
function options_form(&$form, &$form_state) {
$form['columns'] = array(
'#type' => 'textfield',
'#title' => t('Number of columns'),
'#default_value' => $this->options['columns'],
);
}
}
......@@ -2704,7 +2718,6 @@ class views_plugin_style_table extends views_plugin_style {
* Render the table style.
*/
function render() {
// $theme = views_theme_functions('views_view_table', $this->view, $this->display);
return theme($this->theme_functions(), $this->view, $this->options, array());
}
}
......@@ -2797,16 +2810,12 @@ class views_plugin_style_summary extends views_plugin_style {
);
}
/**
* Render the given style.
*/
function render() {
$rows = array();
foreach ($this->view->result as $row) {
// @todo: Include separator as an option.
$rows[] = $row;
}
// $theme = views_theme_functions('views_view_summary', $this->view, $this->display);
return theme($this->theme_functions(), $this->view, $this->options, $rows);
}
}
......@@ -2869,7 +2878,6 @@ class views_plugin_style_rss extends views_plugin_style {
$rows .= $this->row_plugin->render($row);
}
// $theme = views_theme_functions('views_view_rss', $this->view, $this->display);
return theme($this->theme_functions(), $this->view, $this->options, $rows);
}
}
......
......@@ -261,6 +261,30 @@ function template_preprocess_views_view_table(&$vars) {
}
}
/**
* Display a view as a grid style.
*/
function template_preprocess_views_view_grid(&$vars) {
$view = $vars['view'];
$result = $view->result;
$options = $view->style_handler->options;
$handler = $view->style_handler;
$columns = $options['columns'];
$rows = array();
$row = array();
foreach($vars['rows'] as $count => $item) {
$row[] = $item;
if (($count + 1) % $columns == 0) {
$rows[] = $row;
$row = array();
}
}
$vars['rows'] = $rows;
}
/**
* Preprocess an RSS feed
*/
......
<?php
// $Id$
/**
* @file views-view-grid.tpl.php
* Default simple view template to display a rows in a grid.
*
* - $rows contains a nested array of rows. Each row contains an array of
* columns.
*
* @ingroup views_templates
*/
?>
<table class="views-view-grid">
<tbody>
<?php foreach ($rows as $row_number => $columns): ?>
<?php
$row_class = 'row-'. ($row_number + 1);
if ($row_number == 0) {
$row_class .= ' row-first';
}
elseif (count($rows) == ($row_number + 1)) {
$row_class .= ' row-last';
}
?>
<tr class="<?php print $row_class; ?>">
<?php foreach ($columns as $column_number => $item): ?>
<td class="<?php print 'col-'. ($column_number + 1); ?>">
<?php print $item; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment