1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Provide a views handlers for votingapi data fields.
|
6
|
*/
|
7
|
|
8
|
class votingapi_views_handler_field_value extends views_handler_field_numeric {
|
9
|
function construct() {
|
10
|
parent::construct();
|
11
|
$this->definition['float'] = TRUE;
|
12
|
}
|
13
|
|
14
|
function option_definition() {
|
15
|
$options = parent::option_definition();
|
16
|
$options['appearance'] = array('default' => '');
|
17
|
return $options;
|
18
|
}
|
19
|
|
20
|
function options_form(&$form, &$form_state) {
|
21
|
parent::options_form($form, $form_state);
|
22
|
|
23
|
$appearances = module_invoke_all('votingapi_views_formatters', $this);
|
24
|
$options = array('' => t('Default appearance'));
|
25
|
$options += $appearances;
|
26
|
|
27
|
if (count($options) > 1) {
|
28
|
$form['appearance'] = array(
|
29
|
'#type' => 'select',
|
30
|
'#title' => t('Appearance'),
|
31
|
'#options' => $options,
|
32
|
'#default_value' => $this->options['appearance'],
|
33
|
'#weight' => -5,
|
34
|
);
|
35
|
}
|
36
|
}
|
37
|
|
38
|
function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
|
39
|
return 'div';
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* Called to determine what to tell the clicksorter.
|
44
|
*/
|
45
|
function click_sort($order) {
|
46
|
$this->query->add_orderby(NULL, "COALESCE($this->table_alias.$this->field, 0)", $order, $this->table_alias . '_' . $this->field . '_coalesced');
|
47
|
}
|
48
|
|
49
|
function render($values) {
|
50
|
$value = $values->{$this->field_alias};
|
51
|
$function = $this->options['appearance'];
|
52
|
if (!empty($function) && function_exists($function)) {
|
53
|
return $function($value, $this, $values);
|
54
|
}
|
55
|
else {
|
56
|
return parent::render($values);
|
57
|
}
|
58
|
}
|
59
|
}
|