Go to the documentation of this file.00001 <?php
00024 class views_plugin_row extends views_plugin {
00028 function init(&$view, &$display, $options = NULL) {
00029 $this->view = &$view;
00030 $this->display = &$display;
00031
00032
00033 $this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('row_options'));
00034 }
00035
00036 function uses_fields() {
00037 return !empty($this->definition['uses fields']);
00038 }
00039
00040
00041 function option_definition() {
00042 $options = parent::option_definition();
00043 if (isset($this->base_table)) {
00044 $options['relationship'] = array('default' => 'none');
00045 }
00046
00047 return $options;
00048 }
00049
00053 function options_form(&$form, &$form_state) {
00054 parent::options_form($form, $form_state);
00055 if (isset($this->base_table)) {
00056 $view = &$form_state['view'];
00057
00058
00059
00060 $relationships = $view->display_handler->get_option('relationships');
00061 $relationship_options = array();
00062
00063 foreach ($relationships as $relationship) {
00064 $relationship_handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship');
00065
00066
00067 $data = views_fetch_data($relationship['table']);
00068 $base = $data[$relationship['field']]['relationship']['base'];
00069 if ($base == $this->base_table) {
00070 $relationship_handler->init($view, $relationship);
00071 $relationship_options[$relationship['id']] = $relationship_handler->label();
00072 }
00073 }
00074
00075 if (!empty($relationship_options)) {
00076 $relationship_options = array_merge(array('none' => t('Do not use a relationship')), $relationship_options);
00077 $rel = empty($this->options['relationship']) ? 'none' : $this->options['relationship'];
00078 if (empty($relationship_options[$rel])) {
00079
00080 $rel = key($relationship_options);
00081 }
00082
00083 $form['relationship'] = array(
00084 '#type' => 'select',
00085 '#title' => t('Relationship'),
00086 '#options' => $relationship_options,
00087 '#default_value' => $rel,
00088 );
00089 }
00090 else {
00091 $form['relationship'] = array(
00092 '#type' => 'value',
00093 '#value' => 'none',
00094 );
00095 }
00096 }
00097 }
00098
00102 function options_validate(&$form, &$form_state) { }
00103
00108 function options_submit(&$form, &$form_state) { }
00109
00110 function query() {
00111 if (isset($this->base_table)) {
00112 if (isset($this->options['relationship']) && isset($this->view->relationship[$this->options['relationship']])) {
00113 $relationship = $this->view->relationship[$this->options['relationship']];
00114 $this->field_alias = $this->view->query->add_field($relationship->alias, $this->base_field);
00115 }
00116 else {
00117 $this->field_alias = $this->view->query->add_field($this->base_table, $this->base_field);
00118 }
00119 }
00120 }
00121
00128 function pre_render($result) { }
00129
00134 function render($row) {
00135 return theme($this->theme_functions(),
00136 array(
00137 'view' => $this->view,
00138 'options' => $this->options,
00139 'row' => $row,
00140 'field_alias' => isset($this->field_alias) ? $this->field_alias : '',
00141 ));
00142 }
00143 }
00144