• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/search/views_handler_field_search_score.inc

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     // Check to see if the search filter added 'score' to the table.
00047     // Our filter stores it as $handler->search_score -- and we also
00048     // need to check its relationship to make sure that we're using the same
00049     // one or obviously this won't work.
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     // Hide this field if no search filter is in place.
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         // Since the style handler initiates fields, we plug these values right into the active handler.
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     // Only render if we exist.
00071     if (isset($this->table_alias)) {
00072       return parent::render($values);
00073     }
00074   }
00075 
00076 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1