Projet

Général

Profil

Paste
Télécharger (1,44 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / votingapi / views / votingapi_views_handler_field_value.inc @ 7942932f

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
  /**
39
   * Called to determine what to tell the clicksorter.
40
   */
41
  function click_sort($order) {
42
    $this->query->add_orderby(NULL, "COALESCE($this->table_alias.$this->field, 0)", $order, $this->table_alias . '_' . $this->field . '_coalesced');
43
  }
44

    
45
  function render($values) {
46
    $value = $values->{$this->field_alias};
47
    $function = $this->options['appearance'];
48
    if (!empty($function) && function_exists($function)) {
49
      return $function($value, $this, $values);
50
    }
51
    else {
52
      return parent::render($values);
53
    }
54
  }
55
}