[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/filefield/filefield_meta/includes/ -> filefield_meta_handler_field_duration.inc (source)

   1  <?php
   2  // $Id: filefield_meta_handler_field_duration.inc,v 1.3 2010/04/24 06:28:03 quicksketch Exp $
   3  
   4  /**
   5   * @file
   6   * A special handler that properly formats duration fields as minutes:seconds.
   7   */
   8  
   9  /**
  10   * Render a field as a readable value in hours, minutes, and seconds.
  11   *
  12   * @ingroup views_field_handlers
  13   */
  14  class filefield_meta_handler_field_duration extends views_handler_field_numeric {
  15    function option_definition() {
  16      $options = parent::option_definition();
  17  
  18      $options['format'] = array('default' => 'default', 'translatable' => TRUE);
  19  
  20      // Remove the separator options since we don't need them.
  21      unset($options['separator']);
  22  
  23      return $options;
  24    }
  25  
  26    function options_form(&$form, &$form_state) {
  27      parent::options_form($form, $form_state);
  28  
  29      // Remove the separator options since we don't need them.
  30      unset($form['separator']);
  31  
  32      $form['prefix']['#weight'] = 10;
  33      $form['suffix']['#weight'] = 10;
  34      $form['format'] = array(
  35        '#type' => 'select',
  36        '#title' => t('Time format'),
  37        '#default_value' => $this->options['format'],
  38        '#options' => array(
  39          'default' => t('Default (usually mm:ss)'),
  40          'hours' => t('Hours: h'),
  41          'minutes' => t('Minutes: mm'),
  42          'seconds' => t('Seconds: ss'),
  43          'total' => t('Total seconds'),
  44        ),
  45      );
  46    }
  47  
  48    function render($values) {
  49      $value = $values->{$this->field_alias};
  50  
  51      switch ($this->options['format']) {
  52        case 'hours':
  53          $value = date('g', (int) $value);
  54          break;
  55        case 'minutes':
  56          $value = date('i', (int) $value);
  57          break;
  58        case 'seconds':
  59          $value = date('s', (int) $value);
  60          break;
  61        case 'total':
  62          $value = $value;
  63          break;
  64        default:
  65          $output = theme('filefield_meta_duration', $value);
  66      }
  67  
  68      // Check to see if hiding should happen before adding prefix and suffix.
  69      if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
  70        return '';
  71      }
  72  
  73      return check_plain($this->options['prefix']) . $output . check_plain($this->options['suffix']);
  74    }
  75  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7