ILIAS  release_8 Revision v8.24
class.ilLocationInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
29 protected ?float $latitude = null;
30 protected ?float $longitude = null;
31 protected ?int $zoom = null;
32 protected string $address = "";
33
34 public function __construct(
35 string $a_title = "",
36 string $a_postvar = ""
37 ) {
38 global $DIC;
39
40 $this->lng = $DIC->language();
41 $this->rbacsystem = $DIC->rbac()->system();
42 parent::__construct($a_title, $a_postvar);
43 $this->setType("location");
44 }
45
46 public function setLatitude(?float $a_latitude): void
47 {
48 $this->latitude = $a_latitude;
49 }
50
51 public function getLatitude(): ?float
52 {
53 return $this->latitude;
54 }
55
56 public function setLongitude(?float $a_longitude): void
57 {
58 $this->longitude = $a_longitude;
59 }
60
61 public function getLongitude(): ?float
62 {
63 return $this->longitude;
64 }
65
66 public function setZoom(?int $a_zoom): void
67 {
68 $this->zoom = $a_zoom;
69 }
70
71 public function getZoom(): ?int
72 {
73 return $this->zoom;
74 }
75
76 public function setAddress(string $a_address): void
77 {
78 $this->address = $a_address;
79 }
80
81 public function getAddress(): string
82 {
83 return $this->address;
84 }
85
86 public function setValueByArray(array $a_values): void
87 {
88 $lat = (isset($a_values[$this->getPostVar()]["latitude"]) && $a_values[$this->getPostVar()]["latitude"] != "")
89 ? (float) $a_values[$this->getPostVar()]["latitude"]
90 : null;
91 $lon = (isset($a_values[$this->getPostVar()]["longitude"]) && $a_values[$this->getPostVar()]["longitude"] != "")
92 ? (float) $a_values[$this->getPostVar()]["longitude"]
93 : null;
94 $this->setLatitude($lat);
95 $this->setLongitude($lon);
96 $this->setZoom((int) $a_values[$this->getPostVar()]["zoom"]);
97 }
98
99 public function checkInput(): bool
100 {
102
103 $val = $this->strArray($this->getPostVar());
104 if ($this->getRequired() && (
105 !isset($val["latitude"]) || trim($val["latitude"]) == "" ||
106 !isset($val["longitude"]) || trim($val["longitude"]) == ""
107 )) {
108 $this->setAlert($lng->txt("msg_input_is_required"));
109 return false;
110 }
111 return true;
112 }
113
114 public function getInput(): array
115 {
116 $val = $this->strArray($this->getPostVar());
117 return [
118 "latitude" => (float) ($val["latitude"] ?? 0),
119 "longitude" => (float) ($val["longitude"] ?? 0),
120 "zoom" => (int) ($val["zoom"] ?? 0),
121 "address" => ($val["address"] ?? "")
122 ];
123 }
124
125 public function insert(ilTemplate $a_tpl): void
126 {
129 $levels = [];
130
131 $lng->loadLanguageModule("maps");
132 $tpl = new ilTemplate("tpl.prop_location.html", true, true, "Services/Form");
133 $tpl->setVariable("POST_VAR", $this->getPostVar());
134 $tpl->setVariable("TXT_ZOOM", $lng->txt("maps_zoom_level"));
135 $tpl->setVariable("TXT_LATITUDE", $lng->txt("maps_latitude"));
136 $tpl->setVariable("TXT_LONGITUDE", $lng->txt("maps_longitude"));
137 $tpl->setVariable("LOC_DESCRIPTION", $lng->txt("maps_std_location_desc"));
138
139 $lat = is_numeric($this->getLatitude())
140 ? $this->getLatitude()
141 : 0;
142 $long = is_numeric($this->getLongitude())
143 ? $this->getLongitude()
144 : 0;
145 $tpl->setVariable("PROPERTY_VALUE_LAT", $lat);
146 $tpl->setVariable("PROPERTY_VALUE_LONG", $long);
147 for ($i = 0; $i <= 18; $i++) {
148 $levels[$i] = $i;
149 }
150
151 $map_id = "map_" . md5(uniqid());
152
153 $tpl->setVariable(
154 "ZOOM_SELECT",
156 $this->getZoom(),
157 $this->getPostVar() . "[zoom]",
158 $levels,
159 false,
160 true,
161 0,
162 "",
163 array("id" => $map_id . "_zoom",
164 "onchange" => "ilUpdateMap('" . $map_id . "');")
165 )
166 );
167 $tpl->setVariable("MAP_ID", $map_id);
168 $tpl->setVariable("ID", $this->getPostVar());
169
170 // only show address input if geolocation url available
171 // else, if admin: show warning.
172
173 if ($this->geolocationAvailiable()) {
174 $tpl->setVariable("TXT_ADDR", $lng->txt("address"));
175 $tpl->setVariable("TXT_LOOKUP", $lng->txt("maps_lookup_address"));
176 $tpl->setVariable("TXT_ADDRESS", $this->getAddress());
177 $tpl->setVariable("MAP_ID_ADDR", $map_id);
178 $tpl->setVariable("POST_VAR_ADDR", $this->getPostVar());
179 } else {
180 if ($rbacsystem->checkAccess("visible", SYSTEM_FOLDER_ID)) {
181 $tpl->setVariable("TEXT", $lng->txt("configure_geolocation"));
182 }
183 }
184
185 $map_gui = ilMapUtil::getMapGUI();
186 $map_gui->setMapId($map_id)
187 ->setLatitude((string) $lat)
188 ->setLongitude((string) $long)
189 ->setZoom($this->getZoom())
190 ->setEnableTypeControl(true)
191 ->setEnableLargeMapControl(true)
192 ->setEnableUpdateListener(true)
193 ->setEnableCentralMarker(true);
194
195 $tpl->setVariable("MAP", $map_gui->getHtml());
196
197 $a_tpl->setCurrentBlock("prop_generic");
198 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
199 $a_tpl->parseCurrentBlock();
200 }
201
202 protected function geolocationAvailiable(): bool
203 {
204 switch (ilMapUtil::getType()) {
205 case 'openlayers':
207 case 'googlemaps':
208 return true;
209 default:
210 return false;
211 }
212 }
213}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
This class represents a property in a property form.
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static formSelect( $selected, string $varname, array $options, bool $multiple=false, bool $direct_text=false, int $size=0, string $style_class="", array $attribs=[], bool $disabled=false)
Builds a select form field with options and shows the selected option first.
This class represents a location property in a property form.
__construct(string $a_title="", string $a_postvar="")
checkInput()
Check input, strip slashes etc.
setAddress(string $a_address)
setValueByArray(array $a_values)
setLatitude(?float $a_latitude)
setLongitude(?float $a_longitude)
static getStdGeolocationServer()
Returns the reverse geolocation server to be used in the installation.
static getMapGUI()
Get an instance of the GUI class.
static getType()
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
checkAccess(string $a_operations, int $a_ref_id, string $a_type="")
checkAccess represents the main method of the RBAC-system in ILIAS3 developers want to use With this ...
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
const SYSTEM_FOLDER_ID
Definition: constants.php:35
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc