This repository was archived by the owner on Apr 29, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMETnoSymbol.php
67 lines (54 loc) · 1.57 KB
/
METnoSymbol.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* @author Martin Kluska @ iMakers, s.r.o. <martin.kluska@imakers.cz>
* @copyright iMakers, s.r.o.
* @copyright Martin Kluska
* @web http://imakers.cz
*
*
* @uses METnoForecast Description
*/
class METnoSymbol {
/**
* For detection of day progress (night)
* @var METnoForecast
*/
protected $weather;
protected $name = "NONE";
protected $number = 1;
protected $imageUrl = "http://api.met.no/weatherapi/weathericon/1.1/?symbol={code};content_type=image/png";
public function __construct($number,$name) {
$this->name = $name;
$this->number = $number;
}
public function setWeather(METnoForecast $weather) {
$this->weather = $weather;
return $this;
}
public function getNumber() {
return $this->number;
}
public function getName() {
return $this->name;
}
public function getUrl() {
$url = str_replace("{code}",$this->number,$this->imageUrl);
/**
* Detects if its night and show the right symbol
*/
if ($this->isNight()) {
$url.=";is_night=1";
}
return $url;
}
protected function isNight() {
return is_object($this->weather) && is_object($this->weather->getMODay()) && $this->weather->isNight();
}
public function getHTML() {
return "<img src='".$this->getUrl()."' alt='".$this->name."'/>";
}
public function __toString() {
return $this->getUrl();
}
}
?>