function theme_office_hours_formatter_default in Office Hours 6.2
Same name and namespace in other branches
- 6 office_hours.theme.inc \theme_office_hours_formatter_default()
Theme function for 'default' text field formatter.
File
- ./
office_hours.theme.inc, line 7
Code
function theme_office_hours_formatter_default($element) {
$items = array();
$first = variable_get('date_first_day', 0);
$field = content_fields($element['#field_name'], $element['#type_name']);
$output = '';
$days = array(
0 => t('Sunday'),
1 => t('Monday'),
2 => t('Tuesday'),
3 => t('Wednesday'),
4 => t('Thursday'),
5 => t('Friday'),
6 => t('Saturday'),
);
foreach (element_children($element) as $key => $arraykey) {
$item = $element[$arraykey]['#item'];
$day = $days[check_plain($element[$arraykey]['#item']['day'])];
if (isset($day)) {
$endhrs = _office_hours_mil_to_tf(check_plain($item['endhours']));
$strhrs = _office_hours_mil_to_tf(check_plain($item['starthours']));
if ($field['hoursformat']) {
$endhrs = _office_hours_convert_to_ampm($endhrs);
$strhrs = _office_hours_convert_to_ampm($strhrs);
}
$items[$day][] = array(
'strhrs' => $strhrs,
'endhrs' => $endhrs,
);
//we're aggregating hours for days together.
}
}
$keys = array_keys($items);
if ($keys[0] != $days[$first] && in_array(t($days[$first]), $items)) {
while ($keys[0] != $days[$first] && count($keys) > 1) {
$shifted = array_shift($items);
$items[$keys[0]] = $shifted;
$keys = array_keys($items);
}
}
foreach ($items as $day => $val) {
$strhrs = $val[0]['strhrs'];
$endhrs = $val[0]['endhrs'];
$strhrs2 = $val[1]['strhrs'];
$endhrs2 = $val[1]['endhrs'];
$additional = isset($val[1]) ? ' <span class="oh-display-hours">, ' . $strhrs2 . ' - ' . $endhrs2 . '</span>' : '';
$output .= '<div class="oh-display">' . $day . ': <span class="oh-display-hours">' . $strhrs . ' - ' . $endhrs . '</span>' . $additional . '</div>';
}
return $output;
}