video_views_handler_field_playtime_seconds.inc in Video 6.2
File
views/video_views_handler_field_playtime_seconds.inc
View source
<?php
class video_views_handler_field_playtime_seconds extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['time_type'] = array(
'default' => 'hms',
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['time_type'] = array(
'#title' => t('Show playtime as'),
'#type' => 'select',
'#options' => array(
'hms' => t('Hour:min:sec'),
'sec' => t('Seconds'),
),
'#default_value' => $this->options['time_type'],
);
}
function render($values) {
return _video_playtime_seconds($values, $this->options['time_type']);
}
}
function _video_playtime_seconds($values, $type) {
if ($values->node_type && $values->node_type != 'video') {
return NULL;
}
switch ($type) {
case 'hms':
$hms = _video_sec2hms($values->video_playtime_seconds);
if ($hms['hours'] > 0) {
$hms['minutes'] = str_pad($hms['minutes'], 2, '0', STR_PAD_LEFT);
}
$hms['seconds'] = str_pad($hms['seconds'], 2, '0', STR_PAD_LEFT);
$out = '';
if ($hms['hours'] > 0) {
$out .= $hms['hours'] . ":";
}
$out .= $hms['minutes'] . ":" . $hms['seconds'];
return $out;
case 'sec':
default:
return $values->video_playtime_seconds;
}
}