function theme_wunderground_weather_forecast in Wunderground weather 7
Same name and namespace in other branches
- 8 wunderground_weather.module \theme_wunderground_weather_forecast()
Theme function to render weather forecast block.
1 theme call to theme_wunderground_weather_forecast()
- wunderground_weather_get_forecast in ./
wunderground_weather.module - Get forecast data and return a themed table.
File
- ./
wunderground_weather.module, line 448 - Wunderground weather module to display weather forecasts and current weather conditions in blocks.
Code
function theme_wunderground_weather_forecast($variables) {
$header = array();
$rows = array();
$degrees = variable_get('wunderground_weather_degrees', 'celsius');
foreach ($variables['days'] as $day) {
if (!empty($day)) {
// Format date.
$date_format = variable_get('wunderground_weather_forecast_date_format_' . $variables['block_number'], 'medium');
$date = format_date($day['date']['epoch'], $date_format);
// Table header.
$header[] = array(
'data' => $date,
);
// Build rows.
foreach (element_children($variables['fields'], TRUE) as $field) {
if ($variables['fields'][$field]['#enabled'] == 1) {
switch ($field) {
case 'image':
$rows[$field][] = theme('image', array(
'path' => $day['icon_url'],
'alt' => t('Weather forecast for !date', array(
'!date' => $date,
)),
'title' => t('Weather forecast for !date', array(
'!date' => $date,
)),
'attributes' => array(),
));
break;
case 'temperature':
$suffix = $degrees == 'celsius' ? 'C' : 'F';
$rows[$field][] = $day['high'][$degrees] . '°' . $suffix . ' / ' . $day['low'][$degrees] . '°' . $suffix;
break;
case 'conditions':
$rows[$field][] = $day['conditions'];
break;
case 'rain':
$rows[$field][] = $day['pop'] . '% ' . t('rain');
break;
case 'wind':
$windspeed_unit = variable_get('wunderground_weather_windspeed', 'kph');
switch ($windspeed_unit) {
case 'mph':
$windspeed = $day['avewind']['mph'] . ' ' . t('mph');
break;
case 'bft':
$windspeed = _wunderground_weather_speed_to_beaufort($day['avewind']['kph'], 'kph') . ' ' . t('bft');
break;
default:
$windspeed = $day['avewind']['kph'] . ' ' . t('km/h');
break;
}
$rows[$field][] = $windspeed;
break;
}
}
}
}
}
// Variables for hook_table.
$variables = array(
'header' => $header,
'rows' => $rows,
'attributes' => array(),
'caption' => '',
'colgroups' => array(),
'sticky' => FALSE,
'empty' => '',
);
// Return a table.
return theme('table', $variables);
}