00001 <?php
00007 class views_handler_field_search_score extends views_handler_field_numeric {
00008 function option_definition() {
00009 $options = parent::option_definition();
00010
00011 $options['alternate_sort'] = array('default' => '');
00012 $options['alternate_order'] = array('default' => 'asc');
00013
00014 return $options;
00015 }
00016
00017 function options_form(&$form, &$form_state) {
00018 $style_options = $this->view->display_handler->get_option('style_options');
00019 if (isset($style_options['default']) && $style_options['default'] == $this->options['id']) {
00020 $handlers = $this->view->display_handler->get_handlers('field');
00021 $options = array('' => t('No alternate'));
00022 foreach ($handlers as $id => $handler) {
00023 $options[$id] = $handler->ui_name();
00024 }
00025
00026 $form['alternate_sort'] = array(
00027 '#type' => 'select',
00028 '#title' => t('Alternative sort'),
00029 '#description' => t('Pick an alternative default table sort field to use when the search score field is unavailable.'),
00030 '#options' => $options,
00031 '#default_value' => $this->options['alternate_sort'],
00032 );
00033
00034 $form['alternate_order'] = array(
00035 '#type' => 'select',
00036 '#title' => t('Alternate sort order'),
00037 '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')),
00038 '#default_value' => $this->options['alternate_order'],
00039 );
00040 }
00041
00042 parent::options_form($form, $form_state);
00043 }
00044
00045 function query() {
00046
00047
00048
00049
00050 foreach ($this->view->filter as $handler) {
00051 if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
00052 $this->field_alias = $handler->search_score;
00053 $this->table_alias = $handler->table_alias;
00054 return;
00055 }
00056 }
00057
00058
00059 $this->options['exclude'] = TRUE;
00060 if (!empty($this->options['alternate_sort'])) {
00061 if (isset($this->view->style_plugin->options['default']) && $this->view->style_plugin->options['default'] == $this->options['id']) {
00062
00063 $this->view->style_plugin->options['default'] = $this->options['alternate_sort'];
00064 $this->view->style_plugin->options['order'] = $this->options['alternate_order'];
00065 }
00066 }
00067 }
00068
00069 function render($values) {
00070
00071 if (isset($this->table_alias)) {
00072 return parent::render($values);
00073 }
00074 }
00075
00076 }