You are here

function _weather_format_condition in Weather 5.6

Same name and namespace in other branches
  1. 5 weather.module \_weather_format_condition()
  2. 6.5 weather.module \_weather_format_condition()

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

1 call to _weather_format_condition()
theme_weather in ./weather.module
Custom theme function for the weather block output

File

./weather.module, line 980
Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world

Code

function _weather_format_condition($metar) {
  if (!isset($metar) or !isset($metar['condition_text'])) {
    return t('No data');
  }

  // sky conditions
  switch ($metar['condition_text']) {
    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']['rain'])) {
    $rain = $metar['phenomena']['rain'];
    if (isset($rain['#light'])) {
      if (isset($rain['#showers'])) {
        $result[] = t('light rain showers');
      }
      else {
        if (isset($rain['#freezing'])) {
          $result[] = t('light freezing rain');
        }
        else {
          $result[] = t('light rain');
        }
      }
    }
    else {
      if (isset($rain['#heavy'])) {
        if (isset($rain['#showers'])) {
          $result[] = t('heavy rain showers');
        }
        else {
          if (isset($rain['#freezing'])) {
            $result[] = t('heavy freezing rain');
          }
          else {
            $result[] = t('heavy rain');
          }
        }
      }
      else {
        if (isset($rain['#showers'])) {
          $result[] = t('rain showers');
        }
        else {
          if (isset($rain['#freezing'])) {
            $result[] = t('freezing rain');
          }
          else {
            $result[] = t('rain');
          }
        }
      }
    }
  }
  else {
    if (isset($metar['phenomena']['snow'])) {
      $snow = $metar['phenomena']['snow'];
      if (isset($snow['#light'])) {
        if (isset($snow['#blowing'])) {
          $result[] = t('light blowing snow');
        }
        else {
          if (isset($snow['#low_drifting'])) {
            $result[] = t('light low drifting snow');
          }
          else {
            $result[] = t('light snow');
          }
        }
      }
      else {
        if (isset($snow['#heavy'])) {
          if (isset($snow['#blowing'])) {
            $result[] = t('heavy blowing snow');
          }
          else {
            if (isset($snow['#low_drifting'])) {
              $result[] = t('heavy low drifting snow');
            }
            else {
              $result[] = t('heavy snow');
            }
          }
        }
        else {
          if (isset($snow['#blowing'])) {
            $result[] = t('blowing snow');
          }
          else {
            if (isset($snow['#low_drifting'])) {
              $result[] = t('low drifting snow');
            }
            else {
              $result[] = t('snow');
            }
          }
        }
      }
    }
  }
  return join(", ", $result);
}