Commit 86ed07d8 authored by merlinofchaos's avatar merlinofchaos

Add basic support for summary styles; they don't quite work yet because view...

Add basic support for summary styles; they don't quite work yet because view URL knowledge isn't implemented.
parent 40b6f2f1
......@@ -91,14 +91,14 @@ class views_join {
*/
class views_handler extends views_object {
/**
* Seed the handler with necessary data.
* init the handler with necessary data.
* @param $view
* The $view object this handler is attached to.
* @param $data
* The item from the database; the actual contents of this will vary
* based upon the type of handler.
*/
function seed(&$view, &$data) {
function init(&$view, &$data) {
$this->view = &$view;
$this->data = &$data;
......@@ -477,7 +477,7 @@ class views_handler_argument extends views_handler {
$this->query->set_count_field($this->table_alias, $this->real_field);
}
return $count_alias;
$this->count_alias = $count_alias;
}
/**
......@@ -502,7 +502,7 @@ class views_handler_argument extends views_handler {
*/
function summary_link($data, $url) {
$value = $data->{$this->base_alias};
return l($data->{$this->name_alias}, "$url/$value");
return url("$url/$value");
}
/**
......@@ -551,11 +551,22 @@ class views_handler_argument extends views_handler {
$this->view->build_info['summary'] = TRUE;
$this->view->build_info['summary_level'] = $this->data->position;
// Change the display style to the summary style for this
// argument.
$this->view->style_plugin = isset($this->options['style_plugin']) ? $this->options['style_plugin'] : 'default_summary';
// Give it the style's options, too.
// @todo
// Clear out the normal primary field and whatever else may have
// been added and let the summary do the work.
$this->query->clear_fields();
$this->summary_query();
// Allow the new style to add additional fields if it wants.
// @todo
// Cut 'summary' out of our action to see how, if at all, we should
// sort.
$order = trim(str_replace($action, 'summary', ''));
......@@ -564,9 +575,10 @@ class views_handler_argument extends views_handler {
}
// DISTINCT can cause the summaries to fail.
// TODO: This may not be true anymore.
// @todo: This may not be true anymore.
// $this->query->no_distinct = TRUE;
// Summaries have their own sorting and fields, so tell the View not
// to build these.
$this->view->build_sort = $this->view->build_fields = FALSE;
......
......@@ -36,7 +36,7 @@ function views_views_plugins() {
'title' => t('Default'),
'help' => t('Displays rows one after another.'),
'handler' => 'views_style_plugin_default',
'theme' => 'views_view_rows',
'theme' => 'views_view_summary',
),
'list' => array(
'title' => t('List'),
......@@ -50,6 +50,13 @@ function views_views_plugins() {
'handler' => 'views_style_plugin_table',
'theme' => 'views_view_table',
),
'default_summary' => array(
'summary' => TRUE, // only shows up as a summary style
'title' => t('Default'),
'help' => t('Displays the default summary view'),
'handler' => 'views_style_plugin_summary',
'theme' => 'views_view_summary',
),
),
'row' => array(
'fields' => array(
......@@ -58,11 +65,28 @@ function views_views_plugins() {
'handler' => 'views_row_plugin',
'theme' => 'views_view_row',
),
'fields_summary' => array(
'title' => t('Summary'),
'help' => t('Displays the link to the argument and the node count.'),
'handler' => 'views_row_plugin_summary',
'theme' => 'views_view_row_summary',
),
),
);
}
/**
* @defgroup views_display_plugins Views' display plugins
* @{
* Display plugins control how Views interact with the rest of Drupal.
*
* They can handle creating Views from a Drupal page hook; they can
* handle creating Views from a Drupal block hook. They can also
* handle creating Views from an external module source, such as
* a Panels pane, or an insert view, or a CCK field type.
*/
/**
* The default display plugin handler. Display plugins handle options and
* basic mechanisms for different output methods.
......@@ -77,10 +101,8 @@ class views_display_plugin extends views_object {
/**
* Fill this plugin in with the view, display, etc.
*
* @todo LG: This function needs to be renamed to something that sounds less like a randomizer.
*/
function seed(&$view, &$display) {
function init(&$view, &$display) {
$this->view = $view;
$this->display = $display;
}
......@@ -137,7 +159,7 @@ class views_display_plugin extends views_object {
/**
* Render the view's title for display
* TODO: Necessary? Hm.
* @todo: Necessary? Hm.
*/
function render_title() { }
......@@ -174,8 +196,6 @@ class views_display_plugin extends views_object {
* Render this display.
*/
function render() {
// TODO: Remove this when the 'file' tag on theme registry is fixed.
// include_once drupal_get_path('module', 'views') . '/theme/theme.inc';
$themes = array(
'views_view__' . $this->display->id . '__' . $this->view->name,
'views_view__' . $this->display->id,
......@@ -276,6 +296,22 @@ class views_display_plugin_block extends views_display_plugin {
}
}
/**
* @}
*/
/**
* @defgroup views_style_plugins Views' style plugins
* @{
* Style plugins control how a view is rendered. For example, they
* can choose to display a collection of fields, node_view() output,
* table output, or any kind of crazy output they want.
*
* Many style plugins can have an optional 'row' plugin, that displays
* a single record. Not all style plugins can utilize this, so it is
* up to the plugin to set this up and call through to the row plugin.
*/
/**
* Base class to define a style plugin handler.
*/
......@@ -283,7 +319,7 @@ class views_style_plugin extends views_object {
var $needs_fields = FALSE;
var $needs_headers = FALSE;
function seed(&$view, &$display) {
function init(&$view, &$display) {
$this->view = $view;
$this->display = $display;
$this->options = $display->style_options;
......@@ -308,6 +344,10 @@ class views_style_plugin extends views_object {
function render($rows) { }
}
/**
* Default style plugin to render rows one after another with no
* decorations.
*/
class views_style_plugin_default extends views_style_plugin {
// TEMP HACK
var $row_plugin = 'views_row_plugin';
......@@ -319,18 +359,59 @@ class views_style_plugin_default extends views_style_plugin {
* Render the given style.
*/
function render() {
// TODO: This needs to be able to support either a database resource OR
// @todo: This needs to be able to support either a database resource OR
// an array, because our input format doesn't actually have to be from
// a query.
$plugin = new views_row_plugin;
$plugin = new $this->row_plugin;
$rows = '';
while ($row = db_fetch_object($this->view->result)) {
// @todo: Include separator as an option.
$rows .= $plugin->render($this->view, $row);
}
return theme(array('views_view_rows__' . $this->view->name, 'views_view_rows'), $this->view, $rows);
}
}
/**
* The default style plugin for summaries.
*/
class views_style_plugin_summary extends views_style_plugin {
// TEMP HACK
var $row_plugin = 'views_row_plugin_summary';
function options_form(&$form) {
// provide an option form to select from our list of node renderers
}
/**
* Render the given style.
*/
function render() {
// @todo: This needs to be able to support either a database resource OR
// an array, because our input format doesn't actually have to be from
// a query.
$plugin = new $this->row_plugin;
$rows = array();
while ($row = db_fetch_object($this->view->result)) {
// @todo: Include separator as an option.
$rows[] = $plugin->render($this->view, $row);
}
return theme(array('views_view_summary__' . $this->view->name, 'views_view_summary'), $this->view, $rows);
}
}
/**
* @}
*/
/**
* @defgroup views_row_plugins Views' row plugins
* @{
*
* Row plugins control how Views outputs an individual record. They are
* tightly coupled to style plugins, in that a style plugin is what calls
* the row plugin.
*/
/**
* Default plugin to view a single row of a table. This is really just a wrapper around
* a theme function.
......@@ -340,3 +421,17 @@ class views_row_plugin extends views_object {
return theme(array('views_view_row__' . $view->name, 'views_view_row'), $view, $row);
}
}
/**
* Default plugin to view a single row of a table. This is really just a wrapper around
* a theme function.
*/
class views_row_plugin_summary extends views_object {
function render(&$view, $row) {
return theme(array('views_view_row_summary__' . $view->name, 'views_view_row_summary'), $view, $row);
}
}
/**
* @}
*/
......@@ -67,7 +67,7 @@ class views_query {
$this->primary_field = $primary_field;
$this->relationships[$primary_table] = array('link' => NULL, 'table' => $primary_table, 'alias' => $primary_table);
// Seed the table queue with our primary table.
// init the table queue with our primary table.
$this->table_queue[$primary_table] = array(
'alias' => $primary_table,
'table' => $primary_table,
......@@ -75,7 +75,7 @@ class views_query {
'join' => NULL,
);
// Seed the tables with our primary table
// init the tables with our primary table
$this->tables[$primary_table][$primary_table] = array(
'count' => 1,
'alias' => $primary_table,
......@@ -668,7 +668,7 @@ class views_query {
// If it's not a count query, add our fields
$fields_array = $get_count ? array($this->count_field) : $this->fields;
foreach ($fields_array as $field) {
if ($fields) { // TODO: LG: This would be cleaner as an array that gets imploded.
if ($fields) { // @todo: LG: This would be cleaner as an array that gets imploded.
$fields .= ",\n ";
}
$string = '';
......
......@@ -117,7 +117,7 @@ class view extends views_db_object {
$display_id = $this->current_display;
}
// TODO: Fix this:
// @todo: Fix this:
return $this->field;
}
......@@ -159,8 +159,8 @@ class view extends views_db_object {
return FALSE;
}
// Seed the new display handler with data.
$this->display_handler->seed($this, $display_data);
// init the new display handler with data.
$this->display_handler->init($this, $display_data);
// If this is NOT the default display handler, let it know which is
// since it may well utilize some data from the default.
......@@ -168,22 +168,28 @@ class view extends views_db_object {
$this->display_handler->default_display = $this->display[$this->default_display];
}
// Find and initialize the style plugin. Note that arguments may have changed
// which style plugin we use, so check the view object first, then ask
// the display handler.
return TRUE;
}
/**
* Find and initialize the style plugin.
*
* Note that arguments may have changed which style plugin we use, so
* check the view object first, then ask the display handler.
*/
function init_style() {
if (!isset($this->style_plugin)) {
$this->style_plugin = $display_data->style_plugin;
$this->style_plugin = $this->display[$this->current_display]->style_plugin;
}
dsm("Init_style: $this->style_plugin");
$this->style_handler = views_get_plugin('style', $this->style_plugin);
if (empty($this->style_handler)) {
return FALSE;
}
// Seed the new display handler with data.
$this->style_handler->seed($this, $display_data);
return TRUE;
// init the new display handler with data.
$this->style_handler->init($this, $this->display[$this->current_display]);
}
/**
......@@ -209,7 +215,7 @@ class view extends views_db_object {
}
// Attempt to load from cache.
// TODO: Load a build_info from cache.
// @todo: Load a build_info from cache.
......@@ -224,30 +230,32 @@ class view extends views_db_object {
// Call a module hook and see if it wants to present us with a
// pre-built query or instruct us not to build the query for
// some reason.
// TODO: Implement this.
// @todo: Implement this.
// Run through our handlers and ensure they have necessary information.
$this->seed_handlers();
$this->init_handlers();
// Build all the filters.
$this->_build('filter');
// Initially, we want to build sorts and fields. This can change, though,
// if we get a summary view.
$this->build_sort = $this->build_fields = TRUE;
$argument_title = '';
// build arguments.
foreach ($this->argument as $id => $arg) {
unset ($argument); // TODO: LG: Is this necessary, or is this because of the non-bug with reference reassignment?
unset ($argument); // @todo: LG: Is this necessary, or is this because of the non-bug with reference reassignment?
$argument = &$this->argument[$id];
if (!is_object($argument->handler)) {
// TODO: Set some kind of warning.
// @todo: Set some kind of warning.
continue;
}
if (isset($this->args[$id]) && $argument->handler->validate($this->args[$id])) {
// handle argument that is present.
// TODO: Do we want to put in argument placeholders here
// @todo: Do we want to put in argument placeholders here
// So that we can try to cache queries with arguments too?
$argument->handler->argument = $this->args[$id];
$argument->handler->query();
......@@ -265,7 +273,7 @@ class view extends views_db_object {
}
}
// TODO: if $argument_title is set, get the argument and
// @todo: if $argument_title is set, get the argument and
// set it in the build info.
// Build our sort criteria if we were instructed to do so.
......@@ -273,7 +281,7 @@ class view extends views_db_object {
$this->_build('sort');
}
// TODO: Test display to see if it needs fields.
// @todo: Test display to see if it needs fields.
if (!empty($this->build_fields)) {
$this->_build('field');
}
......@@ -291,7 +299,7 @@ class view extends views_db_object {
function _build($key) {
$array = &$this->$key;
foreach ($array as $id => $data) {
// TODO: we should report an error here if this is not an object.
// @todo: we should report an error here if this is not an object.
if (is_object($array[$id]->handler)) {
$array[$id]->handler->query();
}
......@@ -301,12 +309,12 @@ class view extends views_db_object {
/**
* Acquire and attach all of the handlers.
*/
function seed_handlers() {
if (empty($this->seeded)) {
function init_handlers() {
if (empty($this->inited)) {
foreach ($this->objects() as $key) {
$this->_seed_handler($key);
$this->_init_handler($key);
}
$this->seeded = TRUE;
$this->inited = TRUE;
}
}
......@@ -316,11 +324,11 @@ class view extends views_db_object {
* @param $key
* One of 'argument', 'field', 'sort', 'filter', 'relationship'
*/
function _seed_handler($key) {
function _init_handler($key) {
foreach ($this->$key as $data) {
$handler = views_get_handler($data->tablename, $data->field, $key);
if (is_object($handler)) {
$handler->seed($this, $data);
$handler->init($this, $data);
$data->handler = $handler;
}
}
......@@ -343,7 +351,7 @@ class view extends views_db_object {
$query = db_rewrite_sql($this->build_info['query'], $this->base_table, $this->base_field);
$args = $this->build_info['query_args'];
// TODO: Fill in execution defaults if they are not set.
// @todo: Fill in execution defaults if they are not set.
// use_pager, page_size, offset
$items = array();
......@@ -370,18 +378,18 @@ class view extends views_db_object {
*/
function render($display_id = NULL) {
// Check for cached output.
// TODO: Implement this
// @todo: Implement this
// Make sure the query has already executed.
if (empty($this->executed)) { // TODO: Remove this, since ->execute() is already doing it for us.
$this->execute($display_id);
}
// Check to see if the build failed.
if (empty($this->result)) {
return;
}
// Initialize the style plugin.
$this->init_style();
return $this->display_handler->render();
}
......@@ -433,11 +441,15 @@ class view extends views_db_object {
/**
* Get the view's current title. This can change depending upon how it
* was built.
*
* @todo: Implement this.
*/
function get_title($context) { }
/**
* Get the URL for the current view.
*
* @todo: Implement this.
*/
function get_url($args = NULL) { }
......@@ -501,7 +513,7 @@ class view extends views_db_object {
* since it's bound to confuse someone else as much as it did/does me. :-)
*/
function load_views($where, $join = '') {
// TODO: Integrate this in with caching.
// @todo: Integrate this in with caching.
$result = db_query("SELECT DISTINCT v.* FROM {views_view} v $join WHERE $where");
$views = array();
......@@ -543,7 +555,7 @@ class view extends views_db_object {
while ($data = db_fetch_object($result)) {
$object = new $object_name(FALSE);
$object->load_row($data);
array_push($this->$key, $object); // TODO: Why is this array_push instead of just []?
array_push($this->$key, $object); // @todo: Why is this array_push instead of just []?
}
}
......
......@@ -90,10 +90,10 @@ function node_views_data() {
*/
class views_handler_field_node extends views_handler_field {
/**
* Override seed function to provide generic option to link to node.
* Override init function to provide generic option to link to node.
*/
function seed(&$view, &$data) {
parent::seed($view, $data);
function init(&$view, &$data) {
parent::init($view, $data);
if (isset($data->options['link_to_node']) && $view->base_table != 'node') {
$this->additional_fields[] = $nid;
$this->nid_field = 'node_nid';
......
......@@ -50,7 +50,6 @@ function template_preprocess_views_view_row(&$vars) {
// CSS classes should be.
$vars['fields'][$field->handler->field_alias] = views_css_safe($field->handler->field_alias);
}
// Collect all of the fields in the record, then display them in the template.
}
/**
......@@ -63,3 +62,17 @@ function template_preprocess_views_view_row(&$vars) {
function theme_views_view_field($view, $field, $row) {
return $field->handler->render($row);
}
/**
* Preprocess theme function to print a single record from a row, with fields
*/
function template_preprocess_views_view_row_summary(&$vars) {
$view = $vars['view'];
$row = $vars['row'];
$argument = $view->argument[$view->build_info['summary_level']]->handler;
$vars['link'] = check_plain($row->{$argument->name_alias});
$vars['url'] = $argument->summary_link($row, $view->get_url());
$vars['count'] = intval($row->{$argument->count_alias});
}
<?php
// $Id$
/**
* @file views-view-row.tpl.php
* Default simple view template to display a list of rows.
*/
?>
<a href="<?php print $url; ?>"><?php print $link; ?></a> (<?php print $count?>)
<?php
// $Id$
/**
* @file views-view-rows.tpl.php
* Default simple view template to display a list of summary lines
*/
?>
<div class="item-list">
<ul>
<?php foreach ($rows as $row): ?>
<li><?php print $row?></li>
<?php endforeach; ?>
</ul>
</div>
......@@ -97,7 +97,7 @@ function views_menu() {
*/
function views_arg_load($value, $name, $index) {
if ($view = views_get_view($name)) {
$view->seed_handlers();
$view->init_handlers();
if (isset($view->argument[$index - 1])) {
return $view->argument[$index - 1]->handler->validate($value);
}
......@@ -651,7 +651,7 @@ function views_get_block_views() {
$result = array();
foreach ($views as $view) {
$view->seed_handlers();
$view->init_handlers();
foreach ($view->display as $display) {
if ($display->handler && $display->handler->uses_hook_menu) {
$result[] = array($view, $display->id);
......
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