Overview

Packages

  • Service
    • Weather

Classes

  • Horde_Service_Weather
  • Horde_Service_Weather_Base
  • Horde_Service_Weather_Current_Base
  • Horde_Service_Weather_Current_Google
  • Horde_Service_Weather_Current_WeatherUnderground
  • Horde_Service_Weather_Current_Wwo
  • Horde_Service_Weather_Exception
  • Horde_Service_Weather_Exception_InvalidProperty
  • Horde_Service_Weather_Forecast_Base
  • Horde_Service_Weather_Forecast_Google
  • Horde_Service_Weather_Forecast_WeatherUnderground
  • Horde_Service_Weather_Forecast_Wwo
  • Horde_Service_Weather_Google
  • Horde_Service_Weather_Period_Base
  • Horde_Service_Weather_Period_Google
  • Horde_Service_Weather_Period_WeatherUnderground
  • Horde_Service_Weather_Period_Wwo
  • Horde_Service_Weather_Station
  • Horde_Service_Weather_Translation
  • Horde_Service_Weather_WeatherUnderground
  • Horde_Service_Weather_Wwo
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * This file contains the Horde_Service_Weather_Current class for abstracting
  4:  * access to current observations from Wunderground.
  5:  *
  6:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * @author   Michael J Rubinsky <mrubinsk@horde.org>
  9:  * @license  http://www.horde.org/licenses/bsd BSD
 10:  * @category Horde
 11:  * @package  Service_Weather
 12:  */
 13: 
 14: /**
 15:  * Horde_Service_Weather_Current_WeatherUnderground class
 16:  *
 17:  * @author   Michael J Rubinsky <mrubinsk@horde.org>
 18:  * @category Horde
 19:  * @package  Service_Weather
 20:  */
 21:  class Horde_Service_Weather_Current_WeatherUnderground extends Horde_Service_Weather_Current_Base
 22:  {
 23:     protected $_map = array(
 24:         'condition' => 'weather',
 25:         'humidity' => 'relative_humidity',
 26:         'wind_direction' => 'wind_dir',
 27:         'wind_degrees' => 'wind_degrees',
 28:         'icon_url' => 'icon_url'
 29:     );
 30: 
 31:     /**
 32:      * Magic __isset method.
 33:      *
 34:      * @param string $property  Property name.
 35:      *
 36:      * @return boolen
 37:      */
 38:     public function __isset($property)
 39:     {
 40:         return !empty($this->_properties[$property]);
 41:     }
 42: 
 43:     /**
 44:      * Accessor
 45:      *
 46:      * @param string $property  Property to get
 47:      *
 48:      * @return mixed  The property value
 49:      */
 50:     public function __get($property)
 51:     {
 52:         // Maybe someday I can add a better $_map array with 'type' fields etc..
 53:         // for now, just as easy to manually check for these exceptions.
 54:         switch ($property) {
 55:         case 'logo_url':
 56:             return $this->_properties['image']->url;
 57:         case 'time':
 58:             $time = $this->_properties['observation_time_rfc822'];
 59:             $time = new Horde_Date($time);
 60:             $time->setTimezone($this->_properties['local_tz_long']);
 61:             return $time;
 62:         case 'temp':
 63:             if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 64:                 return round($this->_properties['temp_f']);
 65:             }
 66:             return round($this->_properties['temp_c']);
 67:         case 'wind_speed':
 68:             if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 69:                 return $this->_properties['wind_mph'];
 70:             }
 71:             return round($this->_properties['wind_mph'] * Horde_Service_Weather::CONVERSION_MPH_TO_KPH);
 72:         case 'wind_gust':
 73:             if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 74:                 return $this->_properties['wind_gust_mph'];
 75:             }
 76:             return round($this->_properties['wind_gust_mph'] * Horde_Service_Weather::CONVERSION_MPH_TO_KPH);
 77: 
 78:         case 'dewpoint':
 79:             if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 80:                 return $this->_properties['dewpoint_f'];
 81:             }
 82:             return $this->_properties['dewpoint_c'];
 83: 
 84:         case 'heat_index':
 85:             if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 86:                 return $this->_properties['heat_index_f'];
 87:             }
 88:             return $this->_properties['heat_index_c'];
 89: 
 90:         case 'wind_chill':
 91:             if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 92:                 return $this->_properties['wind_chill_f'];
 93:             }
 94:             return $this->_properties['wind_chill_c'];
 95: 
 96:         case 'visibility':
 97:             if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 98:                 return round($this->_properties['visibility_mi']);
 99:             }
100:             return round($this->_properties['visibility_km']);
101: 
102:         case 'pressure':
103:             if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
104:                 return $this->_properties['pressure_in'];
105:             }
106:             return $this->_properties['pressure_mb'];
107: 
108:         case 'pressure_trend':
109:             switch ($this->_properties['pressure_trend']) {
110:             case '0':
111:                 return Horde_Service_Weather_Translation::t('steady');
112:             case '+':
113:                 return Horde_Service_Weather_Translation::t('rising');
114:             case '-':
115:                 return Horde_Service_Weather_Translation::t('falling');
116:             }
117:             break;
118: 
119:         case 'icon':
120:            return $this->_weather->iconMap[$this->_properties['icon']];
121: 
122:         default:
123:             if (empty($this->_map[$property])) {
124:                 throw new Horde_Service_Weather_Exception_InvalidProperty();
125:             }
126:             if (strpos($this->_properties[$this->_map[$property]], '-999') !== false) {
127:                 return Horde_Service_Weather_Translation::t('N/A');
128:             }
129:             return Horde_Service_Weather_Translation::t($this->_properties[$this->_map[$property]]);
130:         }
131:     }
132: 
133:  }
API documentation generated by ApiGen