You are here

function weather_format_sky_condition in Weather 7

Format sky condition and weather phenomena (rain, drizzle, snow, ...).

Parameters

object $metar: METAR data object.

1 call to weather_format_sky_condition()
theme_weather_theming in ./weather_theme.inc
Custom theme function for preprocessing the weather display.

File

./weather_theme.inc, line 113
Prepare themed weather output.

Code

function weather_format_sky_condition($metar) {
  if (empty($metar) or !isset($metar->sky_condition)) {
    return t('No data');
  }

  // Sky condition.
  switch ($metar->sky_condition) {
    case 'clear':
      $result[] = t('Clear sky');
      break;
    case 'few':
      $result[] = t('Few clouds');
      break;
    case 'scattered':
      $result[] = t('Scattered clouds');
      break;
    case 'broken':
      $result[] = t('Broken clouds');
      break;
    case 'overcast':
      $result[] = t('Overcast');
      break;
    case 'no significant clouds':
      $result[] = t('No significant clouds');
      break;
  }

  // Weather phenomena.
  if (isset($metar->phenomena)) {
    $phenomena = explode(', ', $metar->phenomena);
    foreach ($phenomena as $phenomen) {
      switch ($phenomen) {

        // Obscuration.
        case 'mist':
          $result[] = t('mist');
          break;
        case 'shallow fog':
          $result[] = t('shallow fog');
          break;
        case 'partial fog':
          $result[] = t('partial fog');
          break;
        case 'patches of fog':
          $result[] = t('patches of fog');
          break;
        case 'freezing fog':
          $result[] = t('freezing fog');
          break;
        case 'fog':
          $result[] = t('fog');
          break;
        case 'smoke':
          $result[] = t('smoke');
          break;

        // Precipitation, rain.
        case 'light rain showers':
          $result[] = t('light rain showers');
          break;
        case 'light freezing rain':
          $result[] = t('light freezing rain');
          break;
        case 'light rain':
          $result[] = t('light rain');
          break;
        case 'heavy rain showers':
          $result[] = t('heavy rain showers');
          break;
        case 'heavy freezing rain':
          $result[] = t('heavy freezing rain');
          break;
        case 'heavy rain':
          $result[] = t('heavy rain');
          break;
        case 'rain showers':
          $result[] = t('rain showers');
          break;
        case 'freezing rain':
          $result[] = t('freezing rain');
          break;
        case 'rain':
          $result[] = t('rain');
          break;

        // Precipitation, drizzle.
        case 'light freezing drizzle':
          $result[] = t('light freezing drizzle');
          break;
        case 'light drizzle':
          $result[] = t('light drizzle');
          break;
        case 'heavy freezing drizzle':
          $result[] = t('heavy freezing drizzle');
          break;
        case 'heavy drizzle':
          $result[] = t('heavy drizzle');
          break;
        case 'freezing drizzle':
          $result[] = t('freezing drizzle');
          break;
        case 'drizzle':
          $result[] = t('drizzle');
          break;

        // Precipitation, snow.
        case 'light blowing snow':
          $result[] = t('light blowing snow');
          break;
        case 'light low drifting snow':
          $result[] = t('light low drifting snow');
          break;
        case 'light snow showers':
          $result[] = t('light snow showers');
          break;
        case 'light snow':
          $result[] = t('light snow');
          break;
        case 'heavy blowing snow':
          $result[] = t('heavy blowing snow');
          break;
        case 'heavy low drifting snow':
          $result[] = t('heavy low drifting snow');
          break;
        case 'heavy snow showers':
          $result[] = t('heavy snow showers');
          break;
        case 'heavy snow':
          $result[] = t('heavy snow');
          break;
        case 'blowing snow':
          $result[] = t('blowing snow');
          break;
        case 'low drifting snow':
          $result[] = t('low drifting snow');
          break;
        case 'snow showers':
          $result[] = t('snow showers');
          break;
        case 'snow':
          $result[] = t('snow');
          break;
      }
    }
  }
  return implode(", ", $result);
}