You are here

function office_hours_field_formatter in Office Hours 5

implementation of hook_field_formatter Prepare an individual item for viewing in a browser.

Parameters

$field: The field the action is being performed on.

$item: An array, keyed by column, of the data stored for this item in this field.

$formatter: The name of the formatter being used to display the field.

$node: The node object, for context. Will be NULL in some cases. Warning : when displaying field retrieved by Views, $node will not be a "full-fledged" node object, but an object containg the data returned by the Views query (at least nid, vid, changed)

Return value

An HTML string containing the formatted item.

It is important that this function at the minimum perform security transformations such as running check_plain() or check_markup().

File

./office_hours.module, line 278
Creates a field and widget for inserting working or office hours per day

Code

function office_hours_field_formatter($field, $item, $formatter, $node) {
  static $count = 0;
  static $lastday = 7;
  if ($count > 0) {

    //this is not the first iteration.
    if ($lastday == $item['day']) {
      $display = 'hide';
    }
    else {
      $display = 'show';
    }
  }
  $count++;
  $lastday = $item['day'];
  if (isset($item['day'])) {
    $daykey = check_plain($item['day']);
    $days = array(
      0 => t('Sunday'),
      1 => t('Monday'),
      2 => t('Tuesday'),
      3 => t('Wednesday'),
      4 => t('Thursday'),
      5 => t('Friday'),
      6 => t('Saturday'),
    );
    $day = $days[$daykey];
  }
  else {
    $day = '';
  }
  $endhrs = check_plain($item['endhours']);
  $strhrs = check_plain($item['starthours']);
  if ($field['hoursformat'] == 1) {
    $endhrs = convert_to_ampm($endhrs);
    $strhrs = convert_to_ampm($strhrs);
  }
  switch ($formatter) {
    default:
      return theme('oh_formatter_display', $day, $strhrs, $endhrs, $display);
  }
}