PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/libs/Albireo/WeatherApi/WorldWeatheOnlineApi/Entities/WeatherConditions.php

https://code.google.com/
PHP | 457 lines | 195 code | 40 blank | 222 comment | 4 complexity | bced8afd913ff6fb51e6c443ee02cd3f MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0
  1. <?php
  2. /**
  3. * Conditions entity
  4. *
  5. * @copyright Copyright (c) 2011 Celebrio Software
  6. * @package WeatherApi
  7. */
  8. namespace Celebrio\WeatherApi\WorldWeatherOnline;
  9. use Nette\Object;
  10. use Nette\Environment;
  11. use \MemberAccessException;
  12. abstract class WeatherConditions extends Object {
  13. private $weatherCode;
  14. private $weatherIconUrl;
  15. private $weatherDesc;
  16. private $windspeedMiles;
  17. private $windspeedKmph;
  18. private $winddirDegree;
  19. private $winddir16Point;
  20. private $winddirNat;
  21. private $precipMM;
  22. public function getWeatherCode() {
  23. return $this->weatherCode;
  24. }
  25. public function setWeatherCode($weatherCode) {
  26. $this->weatherCode = $weatherCode;
  27. }
  28. public function getWeatherIconUrl() {
  29. return $this->weatherIconUrl;
  30. }
  31. public function setWeatherIconUrl($weatherIconUrl) {
  32. $icon = $this->codeToLink($this->getWeatherCode());
  33. if($icon !== FALSE) {
  34. $this->weatherIconUrl = $icon;
  35. } else {
  36. $this->weatherIconUrl = $weatherIconUrl;
  37. }
  38. $this->codeToLink($this->getWeatherCode());
  39. }
  40. public function getWeatherDesc() {
  41. return $this->weatherDesc;
  42. }
  43. public function setWeatherDesc($weatherDesc) {
  44. $this->weatherDesc = $weatherDesc;
  45. //TODO: Az to bude hotovy, tak tohle odkomentovat a nahradit
  46. //$this->codeToDescription($this->weatherCode);
  47. }
  48. public function getWindspeedMiles() {
  49. return $this->windspeedMiles;
  50. }
  51. public function setWindspeedMiles($windspeedMiles) {
  52. $this->windspeedMiles = $windspeedMiles;
  53. }
  54. public function getWindspeedKmph() {
  55. return $this->windspeedKmph;
  56. }
  57. public function setWindspeedKmph($windspeedKmph) {
  58. $this->windspeedKmph = $windspeedKmph;
  59. }
  60. public function getWinddirDegree() {
  61. return $this->winddirDegree;
  62. }
  63. public function setWinddirDegree($winddirDegree) {
  64. $this->winddirDegree = $winddirDegree;
  65. }
  66. public function getWinddir16Point() {
  67. return $this->winddir16Point;
  68. }
  69. public function setWinddir16Point($winddir16Point) {
  70. $this->winddir16Point = $winddir16Point;
  71. $this->setWinddirNat($winddir16Point);
  72. }
  73. public function getWinddirNat() {
  74. return $this->winddirNat;
  75. }
  76. public function setWinddirNat($winddirNat) {
  77. $this->winddirNat = $this->convertWindDirection($winddirNat);
  78. }
  79. public function getPrecipMM() {
  80. return $this->precipMM;
  81. }
  82. public function setPrecipMM($precipMM) {
  83. $this->precipMM = $precipMM;
  84. }
  85. /*public function setAttribute($name, $value) {
  86. if(empty($value) || empty($name)) {
  87. return false;
  88. }
  89. $name = "set" . ucfirst($name);
  90. try {
  91. $this->$name($value);
  92. } catch (MemberAccessException $e) {
  93. //TODO: log an error here
  94. }
  95. }
  96. private function codeToDescription($code) {
  97. switch ($code) {
  98. case 113:
  99. $this->weatherDesc(_("Clear / Sunny"));
  100. break;
  101. case 116:
  102. $this->weatherDesc(_("Partly cloudy"));
  103. break;
  104. case 119:
  105. $this->weatherDesc(_("Cloudy"));
  106. $this->eatherIconUrl($code);
  107. break;
  108. case 122:
  109. $this->weatherDesc(_("Overcast"));
  110. break;
  111. case 143:
  112. $this->weatherDesc(_("Mist"));
  113. break;
  114. case 176:
  115. $this->weatherDesc(_("Patchy rain nearby"));
  116. break;
  117. case 179:
  118. $this->weatherDesc(_("Patchy snow nearby"));
  119. break;
  120. case 182:
  121. $this->weatherDesc(_("Patchy sleet nearby"));
  122. break;
  123. case 185:
  124. $this->weatherDesc(_("Patchy freezing drizzle nearby"));
  125. break;
  126. case 200:
  127. $this->weatherDesc(_("Thundery outbreaks in nearby"));
  128. break;
  129. case 227:
  130. $this->weatherDesc(_("Blowing snow"));
  131. break;
  132. case 230:
  133. $this->weatherDesc(_("Blizzard")); //entertainment and blizzard north presents ...
  134. break;
  135. case 248:
  136. $this->weatherDesc(_("Fog"));
  137. break;
  138. case 260:
  139. $this->weatherDesc(_("Freezing fog")); //it sounds more like some pokemon attack
  140. break;
  141. case 263:
  142. $this->weatherDesc(_("Patchy light drizzle"));
  143. break;
  144. case 266:
  145. $this->weatherDesc(_("Light drizzle"));
  146. break;
  147. case 281:
  148. $this->weatherDesc(_("Freezing drizzle"));
  149. break;
  150. case 284:
  151. $this->weatherDesc(_("Heavy freezing drizzle"));
  152. break;
  153. case 293:
  154. $this->weatherDesc(_("Patchy light rain"));
  155. break;
  156. case 296:
  157. $this->weatherDesc(_("Light rain"));
  158. break;
  159. case 299:
  160. $this->weatherDesc(_("Moderate rain at times"));
  161. break;
  162. case 302:
  163. $this->weatherDesc(_("Moderate rain"));
  164. break;
  165. case 305:
  166. $this->weatherDesc(_("Heavy rain at times"));
  167. break;
  168. case 308:
  169. $this->weatherDesc(_("Heavy rain"));
  170. break;
  171. case 311:
  172. $this->weatherDesc(_("Light freezing rain"));
  173. break;
  174. case 314:
  175. $this->weatherDesc(_("Moderate or heavy freezing rain"));
  176. break;
  177. case 317:
  178. $this->weatherDesc(_("Light sleet"));
  179. break;
  180. case 320:
  181. $this->weatherDesc(_("Moderate or heavy sleet"));
  182. break;
  183. case 323:
  184. $this->weatherDesc(_("Patchy light snow"));
  185. break;
  186. case 326:
  187. $this->weatherDesc(_("Light snow"));
  188. break;
  189. case 329:
  190. $this->weatherDesc(_("Patchy moderate snow"));
  191. break;
  192. case 332:
  193. $this->weatherDesc(_("Moderate snow"));
  194. break;
  195. case 335:
  196. $this->weatherDesc(_("Patchy heavy snow"));
  197. break;
  198. case 338:
  199. $this->weatherDesc(_("Heavy snow"));
  200. break;
  201. case 350:
  202. $this->weatherDesc(_("Ice pellets"));
  203. break;
  204. case 353:
  205. $this->weatherDesc(_("Light rain shower"));
  206. break;
  207. case 356:
  208. $this->weatherDesc(_("Moderate or heavy rain shower"));
  209. break;
  210. case 359:
  211. $this->weatherDesc(_("Torrential rain shower"));
  212. break;
  213. case 362:
  214. $this->weatherDesc(_("Light sleet showers"));
  215. break;
  216. case 365:
  217. $this->weatherDesc(_("Moderate or heavy sleet showers"));
  218. break;
  219. case 368:
  220. $this->weatherDesc(_("Light snow showers"));
  221. break;
  222. case 371:
  223. $this->weatherDesc(_("Moderate or heavy snow showers"));
  224. break;
  225. case 374:
  226. $this->weatherDesc(_("Light showers of snow pellets"));
  227. break;
  228. case 377:
  229. $this->weatherDesc(_("Moderate or heavy showers of snow pellets"));
  230. break;
  231. case 386:
  232. $this->weatherDesc(_("Patchy light rain in area with thunder"));
  233. break;
  234. case 389:
  235. $this->weatherDesc(_("Moderate or heavy rain in area with thunder"));
  236. break;
  237. case 392:
  238. $this->weatherDesc(_("Patchy light snow in area with thunder"));
  239. break;
  240. case 395:
  241. $this->weatherDesc(_("Moderate or heavy snow with area with thunder"));
  242. break;
  243. default:
  244. $this->weatherDesc("Not available");
  245. break;
  246. }
  247. }*/
  248. //TODO: make this complete and refactor
  249. private function codeToLink($code) {
  250. $request = Environment::getHttpRequest()->uri;
  251. $host = $request->host;
  252. $scriptPath = $request->scriptPath;
  253. $scheme = $request->scheme;
  254. $partPath = $scheme . "://" . $host . $scriptPath;
  255. $path = $partPath . "systemApps/celebrioweather/images/";
  256. $linksToImages = array(
  257. 113 => "wsymbol_0001_sunny.svg",
  258. 116 => "wsymbol_0002_sunny_intervals.svg",
  259. 119 => "wsymbol_0003_white_cloud.svg",
  260. 122 => "wsymbol_0003_white_cloud.svg",
  261. 143 => "wsymbol_0006_mist.svg",
  262. 176 => "wsymbol_0009_light_rain_showers.svg",
  263. 179 => "wsymbol_0013_sleet_showers.svg",
  264. 182 => "wsymbol_0021_cloudy_with_sleet.svg",
  265. 185 => "wsymbol_0021_cloudy_with_sleet.svg",
  266. 200 => "wsymbol_0016_thundery_showers.svg",
  267. 227 => "wsymbol_0019_cloudy_with_light_snow.svg",
  268. 230 => "wsymbol_0020_cloudy_with_heavy_snow.svg",
  269. 248 => "wsymbol_0006_mist.svg",
  270. 260 => "wsymbol_0006_mist.svg",
  271. 263 => "wsymbol_0009_light_rain_showers.svg",
  272. 266 => "wsymbol_0017_cloudy_with_light_rain.svg",
  273. 281 => "wsymbol_0021_cloudy_with_sleet.svg",
  274. 284 => "wsymbol_0021_cloudy_with_sleet.svg",
  275. 293 => "wsymbol_0017_cloudy_with_light_rain.svg",
  276. 296 => "wsymbol_0017_cloudy_with_light_rain.svg",
  277. 299 => "wsymbol_0010_heavy_rain_showers.svg",
  278. 302 => "wsymbol_0018_cloudy_with_heavy_rain.svg",
  279. 305 => "wsymbol_0010_heavy_rain_showers.svg",
  280. 308 => "wsymbol_0018_cloudy_with_heavy_rain.svg",
  281. 311 => "wsymbol_0021_cloudy_with_sleet.svg",
  282. 314 => "wsymbol_0021_cloudy_with_sleet.svg",
  283. 317 => "wsymbol_0021_cloudy_with_sleet.svg",
  284. 320 => "wsymbol_0019_cloudy_with_light_snow.svg",
  285. 323 => "wsymbol_0011_light_snow_showers.svg",
  286. 326 => "wsymbol_0011_light_snow_showers.svg",
  287. 329 => "wsymbol_0020_cloudy_with_heavy_snow.svg",
  288. 332 => "wsymbol_0020_cloudy_with_heavy_snow.svg",
  289. 335 => "wsymbol_0012_heavy_snow_showers.svg",
  290. 338 => "wsymbol_0020_cloudy_with_heavy_snow.svg",
  291. 350 => "wsymbol_0021_cloudy_with_sleet.svg",
  292. 353 => "wsymbol_0009_light_rain_showers.svg",
  293. 356 => "wsymbol_0010_heavy_rain_showers.svg",
  294. 359 => "wsymbol_0018_cloudy_with_heavy_rain.svg",
  295. 362 => "wsymbol_0013_sleet_showers.svg",
  296. 365 => "wsymbol_0013_sleet_showers.svg",
  297. 368 => "wsymbol_0011_light_snow_showers.svg",
  298. 371 => "wsymbol_0012_heavy_snow_showers.svg",
  299. 374 => "wsymbol_0013_sleet_showers.svg",
  300. 377 => "wsymbol_0021_cloudy_with_sleet.svg",
  301. 386 => "wsymbol_0016_thundery_showers.svg",
  302. 389 => "wsymbol_0024_thunderstorm.svg",
  303. 392 => "wsymbol_0016_thundery_showers.svg",
  304. 395 => "wsymbol_0012_heavy_snow_showers.svg"
  305. );
  306. if(array_key_exists($code, $linksToImages)) {
  307. return $path . $linksToImages[$code];
  308. } else {
  309. return false;
  310. }
  311. }
  312. private function convertWindDirection($wind_dir) {
  313. switch($wind_dir) {
  314. case "N":
  315. return _("North");
  316. break;
  317. case "E":
  318. return _("East");
  319. break;
  320. case "S":
  321. return _("South");
  322. break;
  323. case "W":
  324. return _("West");
  325. break;
  326. case "NE":
  327. return _("North-east");
  328. break;
  329. case "NW":
  330. return _("North-west");
  331. break;
  332. case "SE":
  333. return _("South-east");
  334. break;
  335. case "SW":
  336. return _("South-west");
  337. break;
  338. case "NNE":
  339. return _("North-north-east");
  340. break;
  341. case "NNW":
  342. return _("North-north-west");
  343. break;
  344. case "SSE":
  345. return _("South-south-east");
  346. break;
  347. case "SSW":
  348. return _("South-south-west");
  349. break;
  350. case "ENE":
  351. return _("East-north-east");
  352. break;
  353. case "WNW":
  354. return _("West-north-west");
  355. break;
  356. case "ESE":
  357. return _("East-south-east");
  358. break;
  359. case "WSW":
  360. return _("West-south-east");
  361. break;
  362. default:
  363. return _("North");
  364. break;
  365. }
  366. }
  367. }