function brightcove_cck_handler_field_video_date_multiple::render in Brightcove Video Connect 6.2
Same name and namespace in other branches
- 6 brightcove_cck/views/brightcove_cck_handler_field_video_date_multiple.inc \brightcove_cck_handler_field_video_date_multiple::render()
Overrides brightcove_cck_handler_field_video_date::render
File
- brightcove_cck/
views/ brightcove_cck_handler_field_video_date_multiple.inc, line 152 - An extended subclass for field handling that adds multiple field grouping.
Class
- brightcove_cck_handler_field_video_date_multiple
- @file An extended subclass for field handling that adds multiple field grouping.
Code
function render($values) {
// If this is not a grouped field, use content_handler_field::render().
if (!$this->defer_query) {
return parent::render($values);
}
$options = $this->options;
$vid = $values->node_vid;
if (isset($this->field_values[$vid])) {
// Gather items, respecting the 'Display n values starting from m' settings.
$count_skipped = 0;
$items = array();
foreach ($this->field_values[$vid] as $item) {
if (empty($options['multiple']['multiple_from']) || $count_skipped >= $options['multiple']['multiple_from']) {
if (empty($options['multiple']['multiple_number']) || count($items) < $options['multiple']['multiple_number']) {
// Grab the nid - needed for render_link().
$video_id = $item['video_id'];
$items[] = $item;
}
else {
break;
}
}
$count_skipped++;
}
foreach ($items as $item) {
$video = brightcove_video_load($item['video_id']);
if (!empty($video)) {
if (isset($video->{$this->bc_field})) {
$value = floor($video->{$this->bc_field} / 1000);
$time_diff = $_SERVER['REQUEST_TIME'] - $value;
// will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
switch ($format) {
case 'raw time ago':
$output = format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2);
case 'time ago':
$output = t('%time ago', array(
'%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2),
));
case 'raw time span':
$output = ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
case 'time span':
$output = t($time_diff < 0 ? '%time hence' : '%time ago', array(
'%time' => format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2),
));
case 'custom':
$output = format_date($value, $format, $custom_format);
default:
$output = format_date($value, $format);
}
$rendered[] = $this
->render_link($output, (object) array(
'nid' => $item['_nid'],
));
}
}
}
if (count($rendered) > 1) {
// TODO: could we use generic field display ?
return theme('content_view_multiple_field', $rendered, $field, $values);
}
elseif ($rendered) {
return $rendered[0];
}
}
return '';
}