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