WeatherHelper.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. App::uses('AppHelper', 'View/Helper');
  3. App::uses('WeatherLib', 'Tools.Lib');
  4. /**
  5. * Display weather in the view
  6. *
  7. * @author Mark Scherer
  8. * @license MIT
  9. */
  10. class WeatherHelper extends AppHelper {
  11. public $helpers = array('Html');
  12. public $imagePath = ''; //'http://www.google.com/ig/images/weather/';
  13. public $imageUrl = '';
  14. public function __construct($View = null, $settings = array()) {
  15. parent::__construct($View, $settings);
  16. $this->imageUrl = $this->imagePath;
  17. }
  18. /**
  19. * Display a ready table
  20. *
  21. * //TODO
  22. * @return string
  23. */
  24. public function display($location) {
  25. $weather = $this->get($location);
  26. $res = '';
  27. if (empty($weather)) {
  28. return $res;
  29. }
  30. $res .= '<table><tr>';
  31. //$res .= '<td>'.[].'</td>';
  32. $res .= '</tr></table>';
  33. $res .= '<h1>' . h($weather['city']) . ':</h1>';
  34. return $res;
  35. }
  36. /**
  37. * @return string
  38. */
  39. public function imageUrl($icon, $full = false) {
  40. return $this->imageUrl . $icon;
  41. }
  42. /**
  43. * @return array
  44. */
  45. public function get($location, $cOptions = array()) {
  46. $Weather = new WeatherLib();
  47. $options = array(
  48. 'cache' => '+1 hour'
  49. );
  50. $options = array_merge($options, $cOptions);
  51. return $Weather->get($location, $options);
  52. }
  53. }