WeatherHelper.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. *
  23. * @return string
  24. */
  25. public function display($location) {
  26. $weather = $this->get($location);
  27. $res = '';
  28. if (empty($weather)) {
  29. return $res;
  30. }
  31. $res .= '<table><tr>';
  32. //$res .= '<td>'.[].'</td>';
  33. $res .= '</tr></table>';
  34. $res .= '<h1>' . h($weather['city']) . ':</h1>';
  35. return $res;
  36. }
  37. /**
  38. * @return string
  39. */
  40. public function imageUrl($icon, $full = false) {
  41. return $this->imageUrl . $icon;
  42. }
  43. /**
  44. * @return array
  45. */
  46. public function get($location, $cOptions = array()) {
  47. $Weather = new WeatherLib();
  48. $options = array(
  49. 'cache' => '+1 hour'
  50. );
  51. $options = array_merge($options, $cOptions);
  52. return $Weather->get($location, $options);
  53. }
  54. }