SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Widgets/MapDirectionsWidget.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Widgets;
  15.  
  16. use Sprout\Helpers\Form;
  17. use Sprout\Helpers\View;
  18.  
  19.  
  20. /**
  21. * Displays a google map
  22. **/
  23. class MapDirectionsWidget extends Widget
  24. {
  25. protected $friendly_name = "Map w/ Directions";
  26. protected $friendly_desc = 'A dynamic Google map, with directions';
  27.  
  28.  
  29. /**
  30.   * Return the front-end view of this widget
  31.   *
  32.   * @param int $orientation The orientation of the widget.
  33.   **/
  34. public function render($orientation)
  35. {
  36. $view = new View('sprout/map_directions');
  37. if (!empty($this->settings['address'])) {
  38. $view->address = $this->settings['address'];
  39. } else if (!empty($this->settings['latitude']) and !empty($this->settings['longitude'])) {
  40. $view->address = $this->settings['latitude'] . ' ' . $this->settings['longitude'];
  41. } else {
  42. return null;
  43. }
  44.  
  45. if (!empty($this->settings['zoom'])) {
  46. $view->zoom = $this->settings['zoom'];
  47. } else {
  48. $view->zoom = 5;
  49. }
  50.  
  51. return $view->render();
  52. }
  53.  
  54.  
  55. /**
  56.   * Return the settings form for this widget
  57.   **/
  58. public function getSettingsForm()
  59. {
  60. $out = '';
  61.  
  62. Form::nextFieldDetails('Search and choose an exact point on the map', false);
  63. $out .= Form::googleMap('latitude,longitude,zoom');
  64.  
  65. return $out;
  66. }
  67.  
  68.  
  69. /**
  70.   * Returns a label which describes the contents of this widget
  71.   * See {@link Widget::get_info_label} for full documentation
  72.   **/
  73. public function getInfoLabels()
  74. {
  75. return array(
  76. 'Latitude' => @$this->settings['latitude'],
  77. 'Longitude' => @$this->settings['longitude'],
  78. );
  79. }
  80.  
  81. }
  82.  
  83.