| 1 |
<?php
|
| 2 |
// $Id: views_plugin_row.inc,v 1.3 2009/04/11 17:18:58 merlinofchaos Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Contains the base row style plugin.
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* @defgroup views_row_plugins Views' row plugins
|
| 10 |
* @{
|
| 11 |
*
|
| 12 |
* Row plugins control how Views outputs an individual record. They are
|
| 13 |
* tightly coupled to style plugins, in that a style plugin is what calls
|
| 14 |
* the row plugin.
|
| 15 |
*
|
| 16 |
* @see hook_views_plugins
|
| 17 |
*/
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Default plugin to view a single row of a table. This is really just a wrapper around
|
| 21 |
* a theme function.
|
| 22 |
*
|
| 23 |
* @ingroup views_row_plugins
|
| 24 |
*/
|
| 25 |
class views_plugin_row extends views_plugin {
|
| 26 |
/**
|
| 27 |
* Initialize the row plugin.
|
| 28 |
*/
|
| 29 |
function init(&$view, &$display, $options = NULL) {
|
| 30 |
$this->view = &$view;
|
| 31 |
$this->display = &$display;
|
| 32 |
|
| 33 |
// Overlay incoming options on top of defaults
|
| 34 |
$this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('row_options'));
|
| 35 |
}
|
| 36 |
|
| 37 |
function uses_fields() {
|
| 38 |
return !empty($this->definition['uses fields']);
|
| 39 |
}
|
| 40 |
|
| 41 |
|
| 42 |
function option_definition() {
|
| 43 |
$options = parent::option_definition();
|
| 44 |
if (isset($this->base_table)) {
|
| 45 |
$options['relationship'] = array('default' => 'none');
|
| 46 |
}
|
| 47 |
|
| 48 |
return $options;
|
| 49 |
}
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Provide a form for setting options.
|
| 53 |
*/
|
| 54 |
function options_form(&$form, &$form_state) {
|
| 55 |
if (isset($this->base_table)) {
|
| 56 |
$view = &$form_state['view'];
|
| 57 |
|
| 58 |
// A whole bunch of code to figure out what relationships are valid for
|
| 59 |
// this item.
|
| 60 |
$relationships = $view->display_handler->get_option('relationships');
|
| 61 |
$relationship_options = array();
|
| 62 |
|
| 63 |
foreach ($relationships as $relationship) {
|
| 64 |
$relationship_handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship');
|
| 65 |
|
| 66 |
// If this relationship is valid for this type, add it to the list.
|
| 67 |
$data = views_fetch_data($relationship['table']);
|
| 68 |
$base = $data[$relationship['field']]['relationship']['base'];
|
| 69 |
if ($base == $this->base_table) {
|
| 70 |
$relationship_handler->init($view, $relationship);
|
| 71 |
$relationship_options[$relationship['id']] = $relationship_handler->label();
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
if (!empty($relationship_options)) {
|
| 76 |
$relationship_options = array_merge(array('none' => t('Do not use a relationship')), $relationship_options);
|
| 77 |
$rel = empty($this->options['relationship']) ? 'none' : $this->options['relationship'];
|
| 78 |
if (empty($relationship_options[$rel])) {
|
| 79 |
// Pick the first relationship.
|
| 80 |
$rel = key($relationship_options);
|
| 81 |
}
|
| 82 |
|
| 83 |
$form['relationship'] = array(
|
| 84 |
'#type' => 'select',
|
| 85 |
'#title' => t('Relationship'),
|
| 86 |
'#options' => $relationship_options,
|
| 87 |
'#default_value' => $rel,
|
| 88 |
);
|
| 89 |
}
|
| 90 |
else {
|
| 91 |
$form['relationship'] = array(
|
| 92 |
'#type' => 'value',
|
| 93 |
'#value' => 'none',
|
| 94 |
);
|
| 95 |
}
|
| 96 |
}
|
| 97 |
}
|
| 98 |
|
| 99 |
/**
|
| 100 |
* Validate the options form.
|
| 101 |
*/
|
| 102 |
function options_validate($form, &$form_state) { }
|
| 103 |
|
| 104 |
/**
|
| 105 |
* Perform any necessary changes to the form values prior to storage.
|
| 106 |
* There is no need for this function to actually store the data.
|
| 107 |
*/
|
| 108 |
function options_submit($form, &$form_state) { }
|
| 109 |
|
| 110 |
function query() {
|
| 111 |
if (isset($this->base_table) && isset($this->options['relationship']) && isset($this->view->relationship[$this->options['relationship']])) {
|
| 112 |
$relationship = $this->view->relationship[$this->options['relationship']];
|
| 113 |
$this->field_alias = $this->view->query->add_field($relationship->alias, $this->base_field);
|
| 114 |
}
|
| 115 |
else {
|
| 116 |
$this->field_alias = $this->view->base_field;
|
| 117 |
}
|
| 118 |
}
|
| 119 |
|
| 120 |
/**
|
| 121 |
* Allow the style to do stuff before each row is rendered.
|
| 122 |
*
|
| 123 |
* @param $result
|
| 124 |
* The full array of results from the query.
|
| 125 |
*/
|
| 126 |
function pre_render($result) { }
|
| 127 |
|
| 128 |
/**
|
| 129 |
* Render a row object. This usually passes through to a theme template
|
| 130 |
* of some form, but not always.
|
| 131 |
*/
|
| 132 |
function render($row) {
|
| 133 |
return theme($this->theme_functions(), $this->view, $this->options, $row, $this->field_alias);
|
| 134 |
}
|
| 135 |
}
|
| 136 |
|
| 137 |
/**
|
| 138 |
* @}
|
| 139 |
*/
|
| 140 |
|