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