1: <?php
2: /**
3: * This file contains the Horde_Service_Weather_Forecast class for abstracting
4: * access to forecast data from Weatherunderground.
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_Forecast_WeatherUnderground
16: *
17: * @author Michael J Rubinsky <mrubinsk@horde.org>
18: * @category Horde
19: * @package Service_Weather
20: */
21: class Horde_Service_Weather_Forecast_WeatherUnderground extends Horde_Service_Weather_Forecast_Base
22: {
23:
24: public $fields = array(
25: Horde_Service_Weather::FORECAST_FIELD_WIND,
26: Horde_Service_Weather::FORECAST_FIELD_HUMIDITY,
27: Horde_Service_Weather::FORECAST_FIELD_PRECIPITATION);
28:
29: public function __construct(
30: $properties,
31: Horde_Service_Weather_Base $weather,
32: $type = Horde_Service_Weather::FORECAST_TYPE_STANDARD)
33: {
34: parent::__construct($properties, $weather, $type);
35: switch ($type) {
36: case Horde_Service_Weather::FORECAST_TYPE_STANDARD:
37: $this->_parseStd();
38: break;
39: case Horde_Service_Weather::FORECAST_TYPE_HOURLY:
40: $this->_parseHourly();
41: }
42: }
43:
44: public function getForecastTime()
45: {
46: return new Horde_Date($this->_properties['txt_forecast']->date);
47: }
48:
49: /**
50: * [_parse description]
51: *
52: * @throws Horde_Service_Weather_Exception
53: */
54: protected function _parseStd()
55: {
56: if (empty($this->_properties)) {
57: throw new Horde_Service_Weather_Exception('No forecast data to parse.');
58: }
59:
60: foreach ($this->_properties['simpleforecast']->forecastday as $period => $values) {
61: $this->_periods[] = new Horde_Service_Weather_Period_WeatherUnderground((array)$values, $this);
62: }
63: }
64:
65: protected function _parseHourly()
66: {
67: // @TODO: Use the hourly forecast to maybe get a "day"/"night"
68: }
69:
70: }