Commit 0225248a authored by merlinofchaos's avatar merlinofchaos

More handlers for the node table, plus a bit more documentation stuffs

parent 86ed07d8
......@@ -297,6 +297,58 @@ class views_handler_field_date extends views_handler_field {
}
}
/**
* A handler to provide proper displays for dates.
*
* Allows for display of true/false, yes/no, on/off.
*/
class views_handler_field_boolean extends views_handler_field {
/**
* Constructor; calls to base object constructor.
*/
function construct($click_sortable = FALSE, $additional_fields = array()) {
parent::construct($click_sortable, $additional_fields);
}
function options_form(&$form) {
$form['type'] = array(
'#type' => 'select',
'#title' => t('Date format'),
'#options' => array(
'yes-no' => t('Yes/No'),
'true-false' => t('True/False'),
'on-off' => t('On/Off'),
),
'#default_value' => isset($this->options['type']) ? $this->options['type'] : 'yes-no',
);
$form['not'] = array(
'#type' => 'checkbox',
'#title' => t('Reverse'),
'#description' => t('If checked, true will be displayed as false.'),
'#default_value' => !empty($this->options['not']),
);
}
function render($values) {
$value = $values->{$this->field_alias};
if (!empty($this->options['not'])) {
$value = !$value;
}
$format = isset($this->options['type']) ? $this->options['type'] : 'yes';
switch ($format) {
case 'yes-no':
default:
return $value ? t('Yes') : t('No');
case 'true-false':
return $value ? t('True') : t('False');
case 'yes-no':
return $value ? t('On') : t('Off');
}
}
}
/**
* @}
*/
......@@ -428,6 +480,7 @@ class views_handler_filter extends views_handler {
* The basic argument works for very simple arguments such as nid and uid
*/
class views_handler_argument extends views_handler {
var $name_field = NULL;
/**
* Constructor
*/
......@@ -505,6 +558,16 @@ class views_handler_argument extends views_handler {
return url("$url/$value");
}
/**
* Provides the name to use for the summary. By default this is just
* the name field.
*
* @param $data
* The query results for the row.
*/
function summary_name($data) {
return check_plain($data->{$this->name_alias});
}
/**
* Provide a list of default behaviors for this argument if the argument
* is not present.
......
......@@ -451,7 +451,9 @@ class view extends views_db_object {
*
* @todo: Implement this.
*/
function get_url($args = NULL) { }
function get_url($args = NULL) {
return $_GET['q'];
}
/**
* Is this view cacheable?
......
<?php
// $Id$
/**
* @file
* Provides views data and handlers for node.module
* Provide views data and handlers for node.module
*/
/**
* @defgroup views_node_module node.module handlers
*
* Includes the tables 'node', 'node_revisions' and 'history'.
* @{
*/
/**
* Implementation of hook_views_data()
*/
function node_views_data() {
// Basic table information.
$data['node']['table'] = array(
'group' => t('Node'), // Fields will default to this group
// Advertise this table as a possible base table
'base' => array(
'field' => 'nid',
'title' => t('Node'),
),
// For other base tables, explain how we join
'join' => array(
'users' => array(
'handler' => 'views_join', // this is actually optional
'arguments' => array('node', 'users', 'uid', 'uid'),
),
),
// Provide output plugins specifically for this base type.
'plugins' => array(
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['node']['table']['group'] = t('Node');
// Advertise this table as a possible base table
$data['node']['table']['base'] = array(
'field' => 'nid',
'title' => t('Node'),
);
// For other base tables, explain how we join
$data['node']['table']['join'] = array(
'users' => array(
'handler' => 'views_join', // this is actually optional
'arguments' => array('node', 'users', 'uid', 'uid'),
),
'node_revisions' => array(
'arguments' => array('node', 'node_revisions', 'nid', 'nid'),
),
);
// Provide output plugins specifically for this base type.
$data['node']['table']['plugins'] = array(
'row' => array(
'node' => array(
'title' => t('Node'),
'help' => t('Display the node with standard node view.'),
'handler' => 'views_record_plugin_node_view',
'handler' => 'views_row_plugin_node_view',
),
),
);
// ----------------------------------------------------------------
// Fields
// title
$data['node']['title']['field'] = array(
'field' => 'title', // the real field
'group' => t('Node'), // The group it appears in on the UI,
$data['node']['title'] = array(
'title' => t('Title'), // The item it appears as on the UI,
'help' => t('The title of the node'), // The help that appears on the UI,
'handler' => 'views_handler_field_node',
'arguments' => array(TRUE),
'help' => t('The title of the node.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'field' => 'title', // the real field
'group' => t('Node'), // The group it appears in on the UI,
'handler' => 'views_handler_field_node',
'arguments' => array(TRUE), // arguments to the handler
),
);
// nid
$data['node']['nid'] = array(
'title' => t('Nid'),
'help' => t('The node ID of the node'), // The help that appears on the UI,
// Information for displaying the nid
'field' => array(
'handler' => 'views_handler_field_node',
'arguments' => array(TRUE),
),
// Information for accepting a nid as an argument
'argument' => array(
'handler' => 'views_handler_argument',
'arguments' => array('title'),
),
// Information for accepting a nid as a filter
'filter' => array(
'handler' => 'views_handler_filter',
),
// Information for sorting on a nid.
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// created field
$data['node']['created']['title'] = t('Post date'); // The item it appears as on the UI,
$data['node']['created']['help'] = t('The date the node was posted'); // The help that appears on the UI,
$data['node']['created']['field']['handler'] = 'views_handler_field_date';
$data['node']['created']['field']['arguments'] = array(TRUE);
$data['node']['created']['sort']['handler'] = 'views_handler_sort';
$data['node']['created'] = array(
'title' => t('Post date'), // The item it appears as on the UI,
'help' => t('The date the node was posted.'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_date',
'arguments' => array(TRUE),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// changed field
$data['node']['changed']['field'] = array(
$data['node']['changed'] = array(
'title' => t('Updated date'), // The item it appears as on the UI,
'help' => t('The date the node was last updated'), // The help that appears on the UI,
'handler' => 'views_handler_field_date',
'arguments' => array(TRUE),
'help' => t('The date the node was last updated.'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_date',
'arguments' => array(TRUE),
),
);
$data['node']['type']['field'] = array(
// Node type
$data['node']['type'] = array(
'title' => t('Type'), // The item it appears as on the UI,
'help' => t('The type of a node (for example, "blog entry", "forum post", "story", etc)'), // The help that appears on the UI,
'handler' => 'views_handler_field_node_type',
'arguments' => array(TRUE),
'field' => array(
'handler' => 'views_handler_field_node_type',
'arguments' => array(TRUE),
),
'argument' => array(
'handler' => 'views_handler_argument_node_type',
),
);
// published status
$data['node']['status'] = array(
'title' => t('Published'), // The item it appears as on the UI,
'help' => t('The published status of the node.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_boolean',
'arguments' => array(TRUE), // arguments to the handler
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// promote status
$data['node']['promote'] = array(
'title' => t('Promoted to front page'), // The item it appears as on the UI,
'help' => t('The front page of the node.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_boolean',
'arguments' => array(TRUE), // arguments to the handler
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// sticky
$data['node']['sticky'] = array(
'title' => t('Sticky'), // The item it appears as on the UI,
'help' => t('Whether or not the node is sticky.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_boolean',
'arguments' => array(TRUE), // arguments to the handler
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// ----------------------------------------------------------------------
// Node revisions table
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['node']['table']['group'] = t('Node');
// Advertise this table as a possible base table
$data['node']['table']['base'] = array(
'field' => 'vid',
'title' => t('Node revisions'),
);
// For other base tables, explain how we join
$data['node']['table']['join'] = array(
'node' => array(
'arguments' => array('node_revisions', 'node', 'vid', 'vid'),
),
'user' => array(
'arguments' => array('node_revisions', 'node', 'vid', 'vid'),
),
);
// Body field
$data['node_revisions']['body'] = array(
'title' => t('Body'), // The item it appears as on the UI,
'help' => t('The actual, full data in the body field.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'field' => 'body', // the real field
'group' => t('Node'), // The group it appears in on the UI,
'handler' => 'views_handler_field_markup',
'arguments' => array(FALSE, 'format'), // arguments to the handler
),
);
return $data;
}
......@@ -139,3 +261,43 @@ class views_handler_field_node_type extends views_handler_field_node {
return $this->render_link(check_plain($value), $values);
}
}
/**
* Argument handler to accept a node type.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_node_type extends views_handler_argument {
// No constructor is necessary.
function construct() {
parent::construct('type');
}
/**
* Override the behavior of summary_name(). Get the user friendly version
* of the node type.
*/
function summary_name($data) {
return $this->node_type($data->{$this->name_alias});
}
/**
* Override the behavior of title(). Get the user friendly version of the
* node type.
*/
function title() {
return $this->node_type($this->argument);
}
function node_type($type) {
$output = node_get_types('name', $type);
if (empty($output)) {
$output = t('Unknown node type');
}
return check_plain($output);
}
}
/**
* @}
*/
......@@ -71,8 +71,11 @@ function template_preprocess_views_view_row_summary(&$vars) {
$row = $vars['row'];
$argument = $view->argument[$view->build_info['summary_level']]->handler;
$vars['link'] = check_plain($row->{$argument->name_alias});
$vars['link'] = $argument->summary_name($row);
$vars['url'] = $argument->summary_link($row, $view->get_url());
$vars['count'] = intval($row->{$argument->count_alias});
}
/**
* @defgroup views_templates Views' template files
*/
<?php
// $Id$
/**
* @file views-view-row.tpl.php
* @file views-view-row-summary.tpl.php
* Default simple view template to display a list of rows.
*
* @ingroup views_templates
*/
?>
<a href="<?php print $url; ?>"><?php print $link; ?></a> (<?php print $count?>)
<?php
<?php
// $Id$
/**
* @file views-view-row.tpl.php
* Default simple view template to display a list of rows.
*
* @ingroup views_templates
*/
?>
<?php foreach ($fields as $name => $css): ?>
......
<?php
<?php
// $Id$
/**
* @file views-view-rows.tpl.php
* Default simple view template to display a list of rows.
*
* @ingroup views_templates
*/
?>
<?php print $rows ?>
\ No newline at end of file
<?php
// $Id$
/**
* @file views-view-rows.tpl.php
* @file views-view-summary.tpl.php
* Default simple view template to display a list of summary lines
*
* @ingroup views_templates
*/
?>
<div class="item-list">
......
<?php
<?php
// $Id$
/**
* @file views-view.tpl.php
* Main view template
*
* Variables available:
* - $header: The view header
* - $footer: The view footer
* - $rows: The results of the view query, if any
* - $empty: The empty text to display if the view is empty
* - $pager: The pager next/prev links to display, if any
* - $filters: Exposed filter form/info to display
* - $feed_icon: Feed icon to display, if any
*
* @ingroup views_templates
*/
?>
<div class="view view-<?php print $css_name; ?>">
......
......@@ -505,7 +505,7 @@ function &views_get_default_view($view_name) {
else {
// We may as well rebuild the cache while we're at it, since we need to pull all
// of the data anyway. We pick out the one we want along the way.
$cache = discover_default_views();
$cache = views_discover_default_views();
}
}
......
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