You are here

function brightcove_cck_handler_field_video_date::render in Brightcove Video Connect 6

Same name and namespace in other branches
  1. 6.2 brightcove_cck/views/brightcove_cck_handler_field_video_date.inc \brightcove_cck_handler_field_video_date::render()

Overrides content_handler_field_multiple::render

1 call to brightcove_cck_handler_field_video_date::render()
brightcove_cck_handler_field_video_date_multiple::render in brightcove_cck/views/brightcove_cck_handler_field_video_date_multiple.inc
1 method overrides brightcove_cck_handler_field_video_date::render()
brightcove_cck_handler_field_video_date_multiple::render in brightcove_cck/views/brightcove_cck_handler_field_video_date_multiple.inc

File

brightcove_cck/views/brightcove_cck_handler_field_video_date.inc, line 108
The subclass adds basic field and formatter info, for field-specific subclasses to use if they need to.

Class

brightcove_cck_handler_field_video_date
@file The subclass adds basic field and formatter info, for field-specific subclasses to use if they need to.

Code

function render($values) {
  $value = $values->{$this->field_alias};
  if (empty($value)) {
    return '';
  }
  $video = brightcove_video_load($value);
  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':
          return format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2);
        case 'time ago':
          return t('%time ago', array(
            '%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2),
          ));
        case 'raw time span':
          return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
        case 'time span':
          return t($time_diff < 0 ? '%time hence' : '%time ago', array(
            '%time' => format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2),
          ));
        case 'custom':
          return format_date($value, $format, $custom_format);
        default:
          return format_date($value, $format);
      }
    }
  }
  return theme('views_nodate');
}