commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / views / modules / search / views_handler_field_search_score.inc
1 <?php
2
3 /**
4 * @file
5 * Definition of views_handler_field_search_score.
6 */
7
8 /**
9 * Field handler to provide simple renderer that allows linking to a node.
10 *
11 * @ingroup views_field_handlers
12 */
13 class views_handler_field_search_score extends views_handler_field_numeric {
14 function option_definition() {
15 $options = parent::option_definition();
16
17 $options['alternate_sort'] = array('default' => '');
18 $options['alternate_order'] = array('default' => 'asc');
19
20 return $options;
21 }
22
23 function options_form(&$form, &$form_state) {
24 $style_options = $this->view->display_handler->get_option('style_options');
25 if (isset($style_options['default']) && $style_options['default'] == $this->options['id']) {
26 $handlers = $this->view->display_handler->get_handlers('field');
27 $options = array('' => t('No alternate'));
28 foreach ($handlers as $id => $handler) {
29 $options[$id] = $handler->ui_name();
30 }
31
32 $form['alternate_sort'] = array(
33 '#type' => 'select',
34 '#title' => t('Alternative sort'),
35 '#description' => t('Pick an alternative default table sort field to use when the search score field is unavailable.'),
36 '#options' => $options,
37 '#default_value' => $this->options['alternate_sort'],
38 );
39
40 $form['alternate_order'] = array(
41 '#type' => 'select',
42 '#title' => t('Alternate sort order'),
43 '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')),
44 '#default_value' => $this->options['alternate_order'],
45 );
46 }
47
48 parent::options_form($form, $form_state);
49 }
50
51 function query() {
52 // Check to see if the search filter added 'score' to the table.
53 // Our filter stores it as $handler->search_score -- and we also
54 // need to check its relationship to make sure that we're using the same
55 // one or obviously this won't work.
56 foreach ($this->view->filter as $handler) {
57 if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
58 $this->field_alias = $handler->search_score;
59 $this->table_alias = $handler->table_alias;
60 return;
61 }
62 }
63
64 // Hide this field if no search filter is in place.
65 $this->options['exclude'] = TRUE;
66 if (!empty($this->options['alternate_sort'])) {
67 if (isset($this->view->style_plugin->options['default']) && $this->view->style_plugin->options['default'] == $this->options['id']) {
68 // Since the style handler initiates fields, we plug these values right into the active handler.
69 $this->view->style_plugin->options['default'] = $this->options['alternate_sort'];
70 $this->view->style_plugin->options['order'] = $this->options['alternate_order'];
71 }
72 }
73 }
74
75 function render($values) {
76 // Only render if we exist.
77 if (isset($this->table_alias)) {
78 return parent::render($values);
79 }
80 }
81 }