Commit dd4326da authored by quicksketch's avatar quicksketch

#780450: FileField Meta handlers broken or need work.

parent 95ff6464
...@@ -125,12 +125,13 @@ function theme_filefield_meta_duration($duration) { ...@@ -125,12 +125,13 @@ function theme_filefield_meta_duration($duration) {
* Formats audio sample rate. * Formats audio sample rate.
*/ */
function theme_filefield_meta_samplerate($samplerate) { function theme_filefield_meta_samplerate($samplerate) {
return sprintf("%.1f kHz", $samplerate/1000); return t('@sampleratekHz', array('@samplerate' => (int) ($samplerate/1000)));
} }
/** /**
* Formats audio bit rate. * Formats audio bit rate.
*/ */
function theme_filefield_meta_bitrate($bitrate) { function theme_filefield_meta_bitrate($bitrate) {
return sprintf("%d Kbps", $bitrate/1000); dsm($bitrate);
return t('@bitrateKbps', array('@bitrate' => (int) ($bitrate/1000)));
} }
...@@ -87,7 +87,7 @@ function filefield_meta_views_data() { ...@@ -87,7 +87,7 @@ function filefield_meta_views_data() {
'title' => t('Audio format'), 'title' => t('Audio format'),
'help' => t('The audio format.'), 'help' => t('The audio format.'),
'field' => array( 'field' => array(
'handler' => 'views_handler_field_string', 'handler' => 'views_handler_field',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
...@@ -103,7 +103,7 @@ function filefield_meta_views_data() { ...@@ -103,7 +103,7 @@ function filefield_meta_views_data() {
'title' => t('Audio sample rate'), 'title' => t('Audio sample rate'),
'help' => t('The sample rate of the audio.'), 'help' => t('The sample rate of the audio.'),
'field' => array( 'field' => array(
'handler' => 'views_handler_field_numeric', 'handler' => 'filefield_meta_handler_field_samplerate',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
...@@ -119,7 +119,7 @@ function filefield_meta_views_data() { ...@@ -119,7 +119,7 @@ function filefield_meta_views_data() {
'title' => t('Audio channel mode'), 'title' => t('Audio channel mode'),
'help' => t('The number of channels in the audio, by name (stereo or mono).'), 'help' => t('The number of channels in the audio, by name (stereo or mono).'),
'field' => array( 'field' => array(
'handler' => 'views_handler_field_string', 'handler' => 'views_handler_field',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
...@@ -135,7 +135,7 @@ function filefield_meta_views_data() { ...@@ -135,7 +135,7 @@ function filefield_meta_views_data() {
'title' => t('Audio bitrate'), 'title' => t('Audio bitrate'),
'help' => t('The audio bitrate.'), 'help' => t('The audio bitrate.'),
'field' => array( 'field' => array(
'handler' => 'views_handler_field_numeric', 'handler' => 'filefield_meta_handler_field_bitrate',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
...@@ -151,14 +151,14 @@ function filefield_meta_views_data() { ...@@ -151,14 +151,14 @@ function filefield_meta_views_data() {
'title' => t('Audio bitrate mode'), 'title' => t('Audio bitrate mode'),
'help' => t('The kind of audio bitrate, such as VBR. Usually empty.'), 'help' => t('The kind of audio bitrate, such as VBR. Usually empty.'),
'field' => array( 'field' => array(
'handler' => 'views_handler_field_numeric', 'handler' => 'views_handler_field',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort', 'handler' => 'views_handler_sort',
), ),
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_numeric', 'handler' => 'views_handler_filter_string',
), ),
); );
...@@ -175,9 +175,15 @@ function filefield_meta_views_handlers() { ...@@ -175,9 +175,15 @@ function filefield_meta_views_handlers() {
), ),
'handlers' => array( 'handlers' => array(
// field handlers // field handlers
'filefield_meta_handler_field_bitrate' => array(
'parent' => 'views_handler_field_numeric',
),
'filefield_meta_handler_field_duration' => array( 'filefield_meta_handler_field_duration' => array(
'parent' => 'views_handler_field_numeric', 'parent' => 'views_handler_field_numeric',
), ),
'filefield_meta_handler_field_samplerate' => array(
'parent' => 'views_handler_field_numeric',
),
), ),
); );
} }
......
<?php
// $Id$
/**
* @file
* A special handler that properly formats bit rate fields as Kbps.
*/
/**
* Render a field as a readable value in hours, minutes, and seconds.
*
* @ingroup views_field_handlers
*/
class filefield_meta_handler_field_bitrate extends views_handler_field_numeric {
function option_definition() {
$options = parent::option_definition();
$options['format'] = array('default' => 'default', 'translatable' => TRUE);
// Remove the separator options since we don't need them.
unset($options['separator']);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// Remove the separator and alter options since we don't need them.
unset($form['separator']);
$form['prefix']['#weight'] = 10;
$form['suffix']['#weight'] = 10;
$form['format'] = array(
'#type' => 'select',
'#title' => t('Format'),
'#default_value' => $this->options['format'],
'#options' => array(
'default' => t('Default (Mbps or Kbps)'),
'raw' => t('Raw numberic value'),
),
);
}
function render($values) {
$value = $values->{$this->field_alias};
// Check to see if hiding should happen before adding prefix and suffix.
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
return '';
}
switch ($this->options['format']) {
case 'raw':
$output = $value;
break;
default:
$output = theme('filefield_meta_bitrate', $value);
}
return check_plain($this->options['prefix']) . $output . check_plain($this->options['suffix']);
}
}
...@@ -17,9 +17,8 @@ class filefield_meta_handler_field_duration extends views_handler_field_numeric ...@@ -17,9 +17,8 @@ class filefield_meta_handler_field_duration extends views_handler_field_numeric
$options['format'] = array('default' => 'default', 'translatable' => TRUE); $options['format'] = array('default' => 'default', 'translatable' => TRUE);
// Remove the separator and alter options since we don't need them. // Remove the separator options since we don't need them.
unset($options['separator']); unset($options['separator']);
unset($options['alter']);
return $options; return $options;
} }
...@@ -27,9 +26,8 @@ class filefield_meta_handler_field_duration extends views_handler_field_numeric ...@@ -27,9 +26,8 @@ class filefield_meta_handler_field_duration extends views_handler_field_numeric
function options_form(&$form, &$form_state) { function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
// Remove the separator and alter options since we don't need them. // Remove the separator options since we don't need them.
unset($form['separator']); unset($form['separator']);
unset($form['alter']);
$form['prefix']['#weight'] = 10; $form['prefix']['#weight'] = 10;
$form['suffix']['#weight'] = 10; $form['suffix']['#weight'] = 10;
...@@ -49,23 +47,29 @@ class filefield_meta_handler_field_duration extends views_handler_field_numeric ...@@ -49,23 +47,29 @@ class filefield_meta_handler_field_duration extends views_handler_field_numeric
function render($values) { function render($values) {
$value = $values->{$this->field_alias}; $value = $values->{$this->field_alias};
switch ($this->options['format']) { switch ($this->options['format']) {
case 'hours': case 'hours':
$output = date('g', (int) $value); $value = date('g', (int) $value);
break; break;
case 'minutes': case 'minutes':
$output = date('i', (int) $value); $value = date('i', (int) $value);
break; break;
case 'seconds': case 'seconds':
$output = date('s', (int) $value); $value = date('s', (int) $value);
break; break;
case 'total': case 'total':
$output = $value; $value = $value;
break; break;
default: default:
$output = theme('filefield_meta_duration', $value); $output = theme('filefield_meta_duration', $value);
} }
// Check to see if hiding should happen before adding prefix and suffix.
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
return '';
}
return check_plain($this->options['prefix']) . $output . check_plain($this->options['suffix']); return check_plain($this->options['prefix']) . $output . check_plain($this->options['suffix']);
} }
} }
<?php
// $Id$
/**
* @file
* A special handler that properly formats bit rate fields as kHz.
*/
/**
* Render a field as a readable value in hours, minutes, and seconds.
*
* @ingroup views_field_handlers
*/
class filefield_meta_handler_field_samplerate extends views_handler_field_numeric {
function option_definition() {
$options = parent::option_definition();
$options['format'] = array('default' => 'default', 'translatable' => TRUE);
// Remove the separator options since we don't need them.
unset($options['separator']);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// Remove the separator options since we don't need them.
unset($form['separator']);
$form['prefix']['#weight'] = 10;
$form['suffix']['#weight'] = 10;
$form['format'] = array(
'#type' => 'select',
'#title' => t('Format'),
'#default_value' => $this->options['format'],
'#options' => array(
'default' => t('Default (kHz)'),
'raw' => t('Raw numberic value'),
),
);
}
function render($values) {
$value = $values->{$this->field_alias};
// Check to see if hiding should happen before adding prefix and suffix.
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
return '';
}
switch ($this->options['format']) {
case 'raw':
$output = $value;
break;
default:
$output = theme('filefield_meta_samplerate', $value);
}
return check_plain($this->options['prefix']) . $output . check_plain($this->options['suffix']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment