ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilADTLocationFormBridge.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTFormBridge.php";
4
6{
7 protected function isValidADT(ilADT $a_adt)
8 {
9 return ($a_adt instanceof ilADTLocation);
10 }
11
12 public function addToForm()
13 {
14 global $lng;
15
16 $adt = $this->getADT();
17
18 $default = false;
19 if ($adt->isNull()) {
20 // see ilPersonalProfileGUI::addLocationToForm()
21
22 // use installation default
23 include_once("./Services/Maps/classes/class.ilMapUtil.php");
25 $adt->setLatitude($def["latitude"]);
26 $adt->setLongitude($def["longitude"]);
27 $adt->setZoom($def["zoom"]);
28
29 $default = true;
30 }
31
32 // :TODO: title?
33 $title = $this->isRequired()
34 ? $this->getTitle()
35 : $lng->txt("location");
36
37 $loc = new ilLocationInputGUI($title, $this->getElementId());
38 $loc->setLongitude($adt->getLongitude());
39 $loc->setLatitude($adt->getLatitude());
40 $loc->setZoom($adt->getZoom());
41
42 $this->addBasicFieldProperties($loc, $adt->getCopyOfDefinition());
43
44 if (!$this->isRequired()) {
45 $optional = new ilCheckboxInputGUI($this->getTitle(), $this->getElementId() . "_tgl");
46 $optional->addSubItem($loc);
47 $this->addToParentElement($optional);
48
49 if (!$default && !$adt->isNull()) {
50 $optional->setChecked(true);
51 }
52 } else {
53 $this->addToParentElement($loc);
54 }
55 }
56
57 public function importFromPost()
58 {
59 $do_import = true;
60 if (!$this->isRequired()) {
61 $toggle = $this->getForm()->getInput($this->getElementId() . "_tgl");
62 if (!$toggle) {
63 $do_import = false;
64 }
65 }
66
67 if ($do_import) {
68 // ilPropertyFormGUI::checkInput() is pre-requisite
69 $incoming = $this->getForm()->getInput($this->getElementId());
70 $this->getADT()->setLongitude($incoming["longitude"]);
71 $this->getADT()->setLatitude($incoming["latitude"]);
72 $this->getADT()->setZoom($incoming["zoom"]);
73 } else {
74 $this->getADT()->setLongitude(null);
75 $this->getADT()->setLatitude(null);
76 $this->getADT()->setZoom(null);
77 }
78
79 $field = $this->getForm()->getItemByPostvar($this->getElementId());
80 $field->setLongitude($this->getADT()->getLongitude());
81 $field->setLatitude($this->getADT()->getLatitude());
82 $field->setZoom($this->getADT()->getZoom());
83 }
84}
An exception for terminatinating execution or to throw for unit testing.
ADT form bridge base class.
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
getElementId()
Get element id.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
isRequired()
Get required.
addToForm()
Add ADT-specific fields to form.
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
importFromPost()
Import values from form request POST data.
ADT base class.
Definition: class.ilADT.php:12
This class represents a checkbox property in a property form.
This class represents a location property in a property form.
static getDefaultSettings()
Get default longitude, latitude and zoom.
$def
Definition: croninfo.php:21
global $lng
Definition: privfeed.php:17