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