~ubuntu-branches/ubuntu/vivid/php-horde-service-weather/vivid-proposed

« back to all changes in this revision

Viewing changes to Horde_Service_Weather-2.1.4/lib/Horde/Service/Weather/Current/Wwo.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2014-10-16 21:46:14 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20141016214614-no8xuhfj8ofsey56
Tags: 2.1.4-1
New upstream version 2.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * This file contains the Horde_Service_Weather_Current class for abstracting
 
4
 * access to current observations from WorldWeatherOnline.
 
5
 *
 
6
 * Copyright 2011-2014 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_Wwo class
 
16
 *
 
17
 * @author   Michael J Rubinsky <mrubinsk@horde.org>
 
18
 * @category Horde
 
19
 * @package  Service_Weather
 
20
 */
 
21
 class Horde_Service_Weather_Current_Wwo extends Horde_Service_Weather_Current_Base
 
22
 {
 
23
    protected $_map = array(
 
24
        'humidity' => 'humidity',
 
25
        'wind_direction' => 'winddir16Point',
 
26
        'wind_degrees' => 'winddirDegree'
 
27
    );
 
28
 
 
29
    public function __isset($property)
 
30
    {
 
31
        return !empty($this->_properties->$property);
 
32
    }
 
33
 
 
34
    public function __get($property)
 
35
    {
 
36
        // Maybe someday I can add a better $_map array with 'type' fields etc..
 
37
        // for now, just as easy to manually check for these exceptions.
 
38
        switch ($property) {
 
39
        case 'wind_gust':
 
40
        case 'dewpoint':
 
41
        case 'heat_index':
 
42
        case 'wind_chill':
 
43
        case 'pressure_trend':
 
44
        case 'logo_url':
 
45
            return null;
 
46
 
 
47
        case 'condition':
 
48
            return Horde_Service_Weather_Translation::t($this->_properties->weatherDesc[0]->value);
 
49
 
 
50
        // Note that even though this is "localObsDateTime", the timezone set
 
51
        // in the date object will be the server's default timezone since it's
 
52
        // impossible to figure out the timezone from the information given by
 
53
        // the API.
 
54
        case 'time':
 
55
            return new Horde_Date($this->_properties->localObsDateTime);
 
56
 
 
57
        case 'time_utc':
 
58
            return new Horde_Date($this->_properties->date . ' ' . $this->_properties->observation_time, 'UTC');
 
59
 
 
60
        case 'temp':
 
61
            if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 
62
                return $this->_properties->temp_F;
 
63
            }
 
64
            return $this->_properties->temp_C;
 
65
 
 
66
        case 'wind_speed':
 
67
            if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 
68
                return $this->_properties->windspeedMiles;
 
69
            }
 
70
            return $this->_properties->windspeedKmph;
 
71
 
 
72
        case 'visibility':
 
73
            if ($this->_weather->units == Horde_Service_Weather::UNITS_METRIC) {
 
74
                return $this->_properties->visibility;
 
75
            } else {
 
76
                return round($this->_properties->visibility * Horde_Service_Weather::CONVERSION_KPH_TO_MPH);
 
77
            }
 
78
 
 
79
        case 'pressure':
 
80
            if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
 
81
                return round($this->_properties->pressure * Horde_Service_Weather::CONVERSION_MB_TO_INCHES, 2);
 
82
            }
 
83
            return $this->_properties->pressure;
 
84
 
 
85
        case 'icon':
 
86
           return $this->_weather->iconMap[
 
87
                str_replace('.png', '', basename($this->_properties->weatherIconUrl[0]->value))
 
88
            ];
 
89
 
 
90
        case 'humidity':
 
91
            return $this->_properties->humidity . '%';
 
92
        default:
 
93
            if (empty($this->_map[$property])) {
 
94
                throw new Horde_Service_Weather_Exception_InvalidProperty();
 
95
            }
 
96
            return Horde_Service_Weather_Translation::t($this->_properties->{$this->_map[$property]});
 
97
        }
 
98
    }
 
99
 
 
100
 }
 
 
b'\\ No newline at end of file'