/libs/Albireo/WeatherApi/WorldWeatheOnlineApi/Entities/WeatherConditions.php
PHP | 457 lines | 195 code | 40 blank | 222 comment | 4 complexity | bced8afd913ff6fb51e6c443ee02cd3f MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0
- <?php
- /**
- * Conditions entity
- *
- * @copyright Copyright (c) 2011 Celebrio Software
- * @package WeatherApi
- */
- namespace Celebrio\WeatherApi\WorldWeatherOnline;
- use Nette\Object;
- use Nette\Environment;
- use \MemberAccessException;
- abstract class WeatherConditions extends Object {
- private $weatherCode;
- private $weatherIconUrl;
- private $weatherDesc;
- private $windspeedMiles;
- private $windspeedKmph;
- private $winddirDegree;
- private $winddir16Point;
- private $winddirNat;
- private $precipMM;
-
- public function getWeatherCode() {
- return $this->weatherCode;
- }
- public function setWeatherCode($weatherCode) {
- $this->weatherCode = $weatherCode;
- }
- public function getWeatherIconUrl() {
- return $this->weatherIconUrl;
- }
- public function setWeatherIconUrl($weatherIconUrl) {
- $icon = $this->codeToLink($this->getWeatherCode());
- if($icon !== FALSE) {
- $this->weatherIconUrl = $icon;
- } else {
- $this->weatherIconUrl = $weatherIconUrl;
- }
- $this->codeToLink($this->getWeatherCode());
- }
- public function getWeatherDesc() {
- return $this->weatherDesc;
- }
- public function setWeatherDesc($weatherDesc) {
- $this->weatherDesc = $weatherDesc;
- //TODO: Az to bude hotovy, tak tohle odkomentovat a nahradit
- //$this->codeToDescription($this->weatherCode);
- }
- public function getWindspeedMiles() {
- return $this->windspeedMiles;
- }
- public function setWindspeedMiles($windspeedMiles) {
- $this->windspeedMiles = $windspeedMiles;
- }
- public function getWindspeedKmph() {
- return $this->windspeedKmph;
- }
- public function setWindspeedKmph($windspeedKmph) {
- $this->windspeedKmph = $windspeedKmph;
- }
- public function getWinddirDegree() {
- return $this->winddirDegree;
- }
- public function setWinddirDegree($winddirDegree) {
- $this->winddirDegree = $winddirDegree;
- }
- public function getWinddir16Point() {
- return $this->winddir16Point;
- }
- public function setWinddir16Point($winddir16Point) {
- $this->winddir16Point = $winddir16Point;
- $this->setWinddirNat($winddir16Point);
- }
-
-
- public function getWinddirNat() {
- return $this->winddirNat;
- }
- public function setWinddirNat($winddirNat) {
- $this->winddirNat = $this->convertWindDirection($winddirNat);
- }
-
- public function getPrecipMM() {
- return $this->precipMM;
- }
- public function setPrecipMM($precipMM) {
- $this->precipMM = $precipMM;
- }
- /*public function setAttribute($name, $value) {
- if(empty($value) || empty($name)) {
- return false;
- }
- $name = "set" . ucfirst($name);
- try {
- $this->$name($value);
- } catch (MemberAccessException $e) {
- //TODO: log an error here
- }
- }
-
- private function codeToDescription($code) {
-
- switch ($code) {
- case 113:
- $this->weatherDesc(_("Clear / Sunny"));
- break;
-
- case 116:
- $this->weatherDesc(_("Partly cloudy"));
- break;
-
- case 119:
- $this->weatherDesc(_("Cloudy"));
- $this->eatherIconUrl($code);
- break;
-
- case 122:
- $this->weatherDesc(_("Overcast"));
- break;
-
- case 143:
- $this->weatherDesc(_("Mist"));
- break;
-
- case 176:
- $this->weatherDesc(_("Patchy rain nearby"));
- break;
-
- case 179:
- $this->weatherDesc(_("Patchy snow nearby"));
- break;
-
- case 182:
- $this->weatherDesc(_("Patchy sleet nearby"));
- break;
-
- case 185:
- $this->weatherDesc(_("Patchy freezing drizzle nearby"));
- break;
-
- case 200:
- $this->weatherDesc(_("Thundery outbreaks in nearby"));
- break;
-
- case 227:
- $this->weatherDesc(_("Blowing snow"));
- break;
-
- case 230:
- $this->weatherDesc(_("Blizzard")); //entertainment and blizzard north presents ...
- break;
-
- case 248:
- $this->weatherDesc(_("Fog"));
- break;
-
- case 260:
- $this->weatherDesc(_("Freezing fog")); //it sounds more like some pokemon attack
- break;
-
- case 263:
- $this->weatherDesc(_("Patchy light drizzle"));
- break;
-
- case 266:
- $this->weatherDesc(_("Light drizzle"));
- break;
-
- case 281:
- $this->weatherDesc(_("Freezing drizzle"));
- break;
-
- case 284:
- $this->weatherDesc(_("Heavy freezing drizzle"));
- break;
-
- case 293:
- $this->weatherDesc(_("Patchy light rain"));
- break;
-
- case 296:
- $this->weatherDesc(_("Light rain"));
- break;
-
- case 299:
- $this->weatherDesc(_("Moderate rain at times"));
- break;
-
- case 302:
- $this->weatherDesc(_("Moderate rain"));
- break;
-
- case 305:
- $this->weatherDesc(_("Heavy rain at times"));
- break;
-
- case 308:
- $this->weatherDesc(_("Heavy rain"));
- break;
-
- case 311:
- $this->weatherDesc(_("Light freezing rain"));
- break;
-
- case 314:
- $this->weatherDesc(_("Moderate or heavy freezing rain"));
- break;
-
- case 317:
- $this->weatherDesc(_("Light sleet"));
- break;
- case 320:
- $this->weatherDesc(_("Moderate or heavy sleet"));
- break;
-
- case 323:
- $this->weatherDesc(_("Patchy light snow"));
- break;
-
- case 326:
- $this->weatherDesc(_("Light snow"));
- break;
-
- case 329:
- $this->weatherDesc(_("Patchy moderate snow"));
- break;
-
- case 332:
- $this->weatherDesc(_("Moderate snow"));
- break;
-
- case 335:
- $this->weatherDesc(_("Patchy heavy snow"));
- break;
-
- case 338:
- $this->weatherDesc(_("Heavy snow"));
- break;
-
- case 350:
- $this->weatherDesc(_("Ice pellets"));
- break;
-
- case 353:
- $this->weatherDesc(_("Light rain shower"));
- break;
-
- case 356:
- $this->weatherDesc(_("Moderate or heavy rain shower"));
- break;
-
- case 359:
- $this->weatherDesc(_("Torrential rain shower"));
- break;
-
- case 362:
- $this->weatherDesc(_("Light sleet showers"));
- break;
-
- case 365:
- $this->weatherDesc(_("Moderate or heavy sleet showers"));
- break;
-
- case 368:
- $this->weatherDesc(_("Light snow showers"));
- break;
-
- case 371:
- $this->weatherDesc(_("Moderate or heavy snow showers"));
- break;
-
- case 374:
- $this->weatherDesc(_("Light showers of snow pellets"));
- break;
-
- case 377:
- $this->weatherDesc(_("Moderate or heavy showers of snow pellets"));
- break;
-
- case 386:
- $this->weatherDesc(_("Patchy light rain in area with thunder"));
- break;
-
- case 389:
- $this->weatherDesc(_("Moderate or heavy rain in area with thunder"));
- break;
-
- case 392:
- $this->weatherDesc(_("Patchy light snow in area with thunder"));
- break;
-
- case 395:
- $this->weatherDesc(_("Moderate or heavy snow with area with thunder"));
- break;
-
- default:
- $this->weatherDesc("Not available");
- break;
- }
- }*/
- //TODO: make this complete and refactor
- private function codeToLink($code) {
- $request = Environment::getHttpRequest()->uri;
- $host = $request->host;
- $scriptPath = $request->scriptPath;
- $scheme = $request->scheme;
- $partPath = $scheme . "://" . $host . $scriptPath;
- $path = $partPath . "systemApps/celebrioweather/images/";
- $linksToImages = array(
- 113 => "wsymbol_0001_sunny.svg",
- 116 => "wsymbol_0002_sunny_intervals.svg",
- 119 => "wsymbol_0003_white_cloud.svg",
- 122 => "wsymbol_0003_white_cloud.svg",
- 143 => "wsymbol_0006_mist.svg",
- 176 => "wsymbol_0009_light_rain_showers.svg",
- 179 => "wsymbol_0013_sleet_showers.svg",
- 182 => "wsymbol_0021_cloudy_with_sleet.svg",
- 185 => "wsymbol_0021_cloudy_with_sleet.svg",
- 200 => "wsymbol_0016_thundery_showers.svg",
- 227 => "wsymbol_0019_cloudy_with_light_snow.svg",
- 230 => "wsymbol_0020_cloudy_with_heavy_snow.svg",
- 248 => "wsymbol_0006_mist.svg",
- 260 => "wsymbol_0006_mist.svg",
- 263 => "wsymbol_0009_light_rain_showers.svg",
- 266 => "wsymbol_0017_cloudy_with_light_rain.svg",
- 281 => "wsymbol_0021_cloudy_with_sleet.svg",
- 284 => "wsymbol_0021_cloudy_with_sleet.svg",
- 293 => "wsymbol_0017_cloudy_with_light_rain.svg",
- 296 => "wsymbol_0017_cloudy_with_light_rain.svg",
- 299 => "wsymbol_0010_heavy_rain_showers.svg",
- 302 => "wsymbol_0018_cloudy_with_heavy_rain.svg",
- 305 => "wsymbol_0010_heavy_rain_showers.svg",
- 308 => "wsymbol_0018_cloudy_with_heavy_rain.svg",
- 311 => "wsymbol_0021_cloudy_with_sleet.svg",
- 314 => "wsymbol_0021_cloudy_with_sleet.svg",
- 317 => "wsymbol_0021_cloudy_with_sleet.svg",
- 320 => "wsymbol_0019_cloudy_with_light_snow.svg",
- 323 => "wsymbol_0011_light_snow_showers.svg",
- 326 => "wsymbol_0011_light_snow_showers.svg",
- 329 => "wsymbol_0020_cloudy_with_heavy_snow.svg",
- 332 => "wsymbol_0020_cloudy_with_heavy_snow.svg",
- 335 => "wsymbol_0012_heavy_snow_showers.svg",
- 338 => "wsymbol_0020_cloudy_with_heavy_snow.svg",
- 350 => "wsymbol_0021_cloudy_with_sleet.svg",
- 353 => "wsymbol_0009_light_rain_showers.svg",
- 356 => "wsymbol_0010_heavy_rain_showers.svg",
- 359 => "wsymbol_0018_cloudy_with_heavy_rain.svg",
- 362 => "wsymbol_0013_sleet_showers.svg",
- 365 => "wsymbol_0013_sleet_showers.svg",
- 368 => "wsymbol_0011_light_snow_showers.svg",
- 371 => "wsymbol_0012_heavy_snow_showers.svg",
- 374 => "wsymbol_0013_sleet_showers.svg",
- 377 => "wsymbol_0021_cloudy_with_sleet.svg",
- 386 => "wsymbol_0016_thundery_showers.svg",
- 389 => "wsymbol_0024_thunderstorm.svg",
- 392 => "wsymbol_0016_thundery_showers.svg",
- 395 => "wsymbol_0012_heavy_snow_showers.svg"
- );
- if(array_key_exists($code, $linksToImages)) {
- return $path . $linksToImages[$code];
- } else {
- return false;
- }
- }
-
- private function convertWindDirection($wind_dir) {
- switch($wind_dir) {
- case "N":
- return _("North");
- break;
-
- case "E":
- return _("East");
- break;
-
- case "S":
- return _("South");
- break;
-
- case "W":
- return _("West");
- break;
-
- case "NE":
- return _("North-east");
- break;
-
- case "NW":
- return _("North-west");
- break;
-
- case "SE":
- return _("South-east");
- break;
-
- case "SW":
- return _("South-west");
- break;
-
- case "NNE":
- return _("North-north-east");
- break;
-
- case "NNW":
- return _("North-north-west");
- break;
-
- case "SSE":
- return _("South-south-east");
- break;
-
- case "SSW":
- return _("South-south-west");
- break;
-
- case "ENE":
- return _("East-north-east");
- break;
-
- case "WNW":
- return _("West-north-west");
- break;
-
- case "ESE":
- return _("East-south-east");
- break;
-
- case "WSW":
- return _("West-south-east");
- break;
-
- default:
- return _("North");
- break;
- }
- }
- }