1: <?php
2: /**
3: * This file contains the Horde_Service_Weather_Forecast class for abstracting
4: * access to forecast data. Provides a simple iterator for a collection of
5: * forecast periods.
6: *
7: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
8: *
9: * @author Michael J Rubinsky <mrubinsk@horde.org>
10: * @license http://www.horde.org/licenses/bsd BSD
11: * @category Horde
12: * @package Service_Weather
13: */
14:
15: /**
16: * Horde_Service_Weather_Current class
17: *
18: * @author Michael J Rubinsky <mrubinsk@horde.org>
19: * @category Horde
20: * @package Service_Weather
21: */
22: class Horde_Service_Weather_Forecast_Base implements IteratorAggregate
23: {
24:
25: /**
26: * The forecast properties as returned from the forecast request.
27: *
28: * @var array
29: */
30: protected $_properties = array();
31:
32: /**
33: * Local cache of forecast periods
34: *
35: * @var array
36: */
37: protected $_periods = array();
38:
39: /**
40: * Parent Weather driver.
41: *
42: * @var Horde_Service_Weather_Base
43: */
44: public $weather;
45:
46: /**
47: * Forecast type
48: *
49: * @var integer A Horde_Service_Weather::FORECAST_TYPE_* constant.
50: */
51: protected $_type;
52:
53: /**
54: * Maximum forecast length to return. Defaults to sufficiently high number
55: * to ensure all available days returned by default.
56: */
57: protected $_maxDays = 20;
58:
59:
60: /**
61: * Advertise how detailed the forecast period is.
62: *<pre>
63: * FORECAST_TYPE_STANDARD - Each Period represents a full day
64: * FORECAST_TYPE_DETAILED - Each period represents either day or night.
65: * FORECAST_TYPE_HOURLY - Each period represents a single hour.
66: *</pre>
67: *
68: * @var integer
69: */
70: public $detail = Horde_Service_Weather::FORECAST_TYPE_STANDARD;
71:
72: /**
73: * Const'r
74: *
75: * @param array $properties Forecast properties.
76: * @param Horde_Service_Weather_base $weather The base driver.
77: * @param integer $type The forecast type.
78: */
79: public function __construct(
80: $properties,
81: Horde_Service_Weather_Base $weather,
82: $type = Horde_Service_Weather::FORECAST_TYPE_STANDARD)
83: {
84: $this->_properties = $properties;
85: $this->weather = $weather;
86: $this->_type = $type;
87: }
88:
89: public function getIterator()
90: {
91: return new ArrayIterator(array_slice($this->_periods, 0, $this->_maxDays));
92: }
93:
94: public function getForecastDay($day)
95: {
96: return $this->_periods[$day];
97: }
98:
99: public function getForecastTime()
100: {
101: return false;
102: }
103:
104: /**
105: * Limit the returned number of forecast days. Used for emulating a smaller
106: * forecast length than the provider supports or for using one, longer
107: * request to supply two different forecast length requests.
108: *
109: * @param integer $days The number of days to return.
110: */
111: public function limitLength($days)
112: {
113: $this->_maxDays = $days;
114: }
115:
116: }