Go to the documentation of this file.00001 <?php
00035 class views_handler_relationship extends views_handler {
00040 function init(&$view, &$options) {
00041 parent::init($view, $options);
00042 if (isset($this->definition['relationship table'])) {
00043 $this->table = $this->definition['relationship table'];
00044 }
00045 if (isset($this->definition['relationship field'])) {
00046
00047
00048 $this->real_field = $this->field = $this->definition['relationship field'];
00049 }
00050 }
00051
00055 function label() {
00056 if (!isset($this->options['label'])) {
00057 return $this->ui_name();
00058 }
00059 return $this->options['label'];
00060 }
00061
00062 function option_definition() {
00063 $options = parent::option_definition();
00064
00065
00066
00067 if (!empty($this->definition['label'])) {
00068 $label = $this->definition['label'];
00069 }
00070 else {
00071 $label = !empty($this->definition['field']) ? $this->definition['field'] : $this->definition['base field'];
00072 }
00073
00074 $options['label'] = array('default' => $label, 'translatable' => TRUE);
00075 $options['required'] = array('default' => FALSE);
00076
00077 return $options;
00078 }
00079
00084 function options_form(&$form, &$form_state) {
00085 parent::options_form($form, $form_state);
00086 $form['label'] = array(
00087 '#type' => 'textfield',
00088 '#title' => t('Identifier'),
00089 '#default_value' => isset($this->options['label']) ? $this->options['label'] : '',
00090 '#description' => t('Edit the administrative label displayed when referencing this relationship from filters, etc.'),
00091 '#required' => TRUE,
00092 );
00093
00094 $form['required'] = array(
00095 '#type' => 'checkbox',
00096 '#title' => t('Require this relationship'),
00097 '#description' => t('Enable to hide items that do not contain this relationship'),
00098 '#default_value' => !empty($this->options['required']),
00099 );
00100 }
00101
00105 function query() {
00106
00107 $table_data = views_fetch_data($this->definition['base']);
00108 $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
00109
00110 $this->ensure_my_table();
00111
00112 $def = $this->definition;
00113 $def['table'] = $this->definition['base'];
00114 $def['field'] = $base_field;
00115 $def['left_table'] = $this->table_alias;
00116 $def['left_field'] = $this->real_field;
00117 if (!empty($this->options['required'])) {
00118 $def['type'] = 'INNER';
00119 }
00120
00121 if (!empty($this->definition['extra'])) {
00122 $def['extra'] = $this->definition['extra'];
00123 }
00124
00125 if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
00126 $join = new $def['join_handler'];
00127 }
00128 else {
00129 $join = new views_join();
00130 }
00131
00132 $join->definition = $def;
00133 $join->options = $this->options;
00134 $join->construct();
00135 $join->adjusted = TRUE;
00136
00137
00138 $alias = $def['table'] . '_' . $this->table;
00139
00140 $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
00141
00142
00143 if (empty($this->query->options['disable_sql_rewrite']) && isset($table_data['table']['base']['access query tag'])) {
00144 $access_tag = $table_data['table']['base']['access query tag'];
00145 $this->query->add_tag($access_tag);
00146 }
00147 }
00148
00152 function use_group_by() {
00153 return FALSE;
00154 }
00155 }
00156
00162 class views_handler_relationship_broken extends views_handler_relationship {
00163 function ui_name($short = FALSE) {
00164 return t('Broken/missing handler');
00165 }
00166
00167 function ensure_my_table() { }
00168 function query() { }
00169 function options_form(&$form, &$form_state) {
00170 $form['markup'] = array(
00171 '#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
00172 );
00173 }
00174
00178 function broken() { return TRUE; }
00179 }
00180