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_Period class for abstracting
  4:  * access to a single forecast period 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_Period_WeatherUnderground
 16:  *
 17:  * @author   Michael J Rubinsky <mrubinsk@horde.org>
 18:  * @category Horde
 19:  * @package  Service_Weather
 20:  */
 21: class Horde_Service_Weather_Period_WeatherUnderground extends Horde_Service_Weather_Period_Base
 22: {
 23: 
 24:     /**
 25:      * Property Map
 26:      *
 27:      * @TODO Figure out what to do with the 'skyicon' value - which is sometimes
 28:      *       different than the icon and icon_url. Also, should add a icon set
 29:      *       property to allow using other icon sets e.g., {icon_set_url}/{icon}.gif
 30:      *
 31:      * @var array
 32:      */
 33:     protected $_map = array(
 34:         'conditions' => 'conditions',
 35:         'icon_url' => 'icon_url',
 36:         'precipitation_percent' => 'pop',
 37:         'period' => 'period',
 38:         'humidity' => 'maxhumidity',
 39:     );
 40: 
 41:     /**
 42:      * Accessor so we can lazy-parse the results.
 43:      *
 44:      * @param string $property  The property name.
 45:      *
 46:      * @return mixed  The value of requested property
 47:      * @throws Horde_Service_Weather_Exception_InvalidProperty
 48:      */
 49:     public function __get($property)
 50:     {
 51:         switch ($property) {
 52:         case 'is_pm':
 53:              // Wunderground only supports standard
 54:             return false;
 55:         case 'hour':
 56:              // Wunderground supports this, but we don't.
 57:             return false;
 58:         case 'date':
 59:             $date = new Horde_Date(array(
 60:                 'year' => $this->_properties['date']->year,
 61:                 'month' => $this->_properties['date']->month,
 62:                 'mday' => $this->_properties['date']->day));
 63:             $date->hour = $this->_properties['date']->hour;
 64:             $date->min = $this->_properties['date']->min;
 65:             $date->setTimezone($this->_properties['date']->tz_long);
 66: 
 67:             return $date;
 68: 
 69:         case 'high':
 70:             if ($this->_forecast->weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 71:                 return $this->_properties['high']->fahrenheit !== '' ?
 72:                     $this->_properties['high']->fahrenheit :
 73:                     Horde_Service_Weather_Translation::t('N/A');
 74:             }
 75:             return $this->_properties['high']->celsius;
 76: 
 77:         case 'low':
 78:             if ($this->_forecast->weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 79:                 return $this->_properties['low']->fahrenheit !== '' ?
 80:                     $this->_properties['low']->fahrenheit :
 81:                     Horde_Service_Weather_Translation::t('N/A');
 82:             }
 83:             return $this->_properties['low']->celsius;
 84: 
 85:         case 'icon':
 86:             return $this->_forecast->weather->iconMap[$this->_properties['icon']];
 87: 
 88:         case 'wind_direction':
 89:             return Horde_Service_Weather_Translation::t($this->_properties['avewind']->dir);
 90: 
 91:         case 'wind_degrees':
 92:             return $this->_properties['avewind']->degrees;
 93: 
 94:         case 'wind_speed':
 95:            if ($this->_forecast->weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 96:                return $this->_properties['avewind']->mph;
 97:            }
 98:            return $this->_properties['avewind']->kph;
 99: 
100:         case 'wind_gust':
101:            if ($this->_forecast->weather->units == Horde_Service_Weather::UNITS_STANDARD) {
102:                return $this->_properties['maxwind']->mph;
103:            }
104:            return $this->_properties['maxwind']->kph;
105: 
106:         case 'rain_total':
107:             if ($this->_forecast->weather->units == Horde_Service_Weather::UNITS_STANDARD) {
108:                 return $this->_properties['qpf_allday']->in;
109:             }
110:             return $this->_properties['qpf_allday']->mm;
111: 
112:         case 'snow_total':
113:             if ($this->_forecast->weather->units == Horde_Service_Weather::UNITS_STANDARD) {
114:                 return $this->_properties['snow_allday']->in;
115:             }
116:             return $this->_properties['snow_allday']->cm;
117: 
118:         default:
119:             if (!empty($this->_map[$property])) {
120:                 return Horde_Service_Weather_Translation::t($this->_properties[$this->_map[$property]]);
121:             }
122: 
123:             throw new Horde_Service_Weather_Exception_InvalidProperty('This provider does not support the "' . $property . '" property');
124:         }
125:     }
126: 
127: }
API documentation generated by ApiGen