ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilADTLocationFormBridge.php
Go to the documentation of this file.
1 <?php
2 
3 require_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 $DIC;
15 
16  $lng = $DIC['lng'];
17 
18  $adt = $this->getADT();
19 
20  $default = false;
21  if ($adt->isNull()) {
22  // see ilPersonalProfileGUI::addLocationToForm()
23 
24  // use installation default
25  include_once("./Services/Maps/classes/class.ilMapUtil.php");
27  $adt->setLatitude($def["latitude"]);
28  $adt->setLongitude($def["longitude"]);
29  $adt->setZoom($def["zoom"]);
30 
31  $default = true;
32  }
33 
34  // :TODO: title?
35  $title = $this->isRequired()
36  ? $this->getTitle()
37  : $lng->txt("location");
38 
39  $loc = new ilLocationInputGUI($title, $this->getElementId());
40  $loc->setLongitude($adt->getLongitude());
41  $loc->setLatitude($adt->getLatitude());
42  $loc->setZoom($adt->getZoom());
43 
44  $this->addBasicFieldProperties($loc, $adt->getCopyOfDefinition());
45 
46  if (!$this->isRequired()) {
47  $optional = new ilCheckboxInputGUI($this->getTitle(), $this->getElementId() . "_tgl");
48  $optional->addSubItem($loc);
49  $this->addToParentElement($optional);
50 
51  if (!$default && !$adt->isNull()) {
52  $optional->setChecked(true);
53  }
54  } else {
55  $this->addToParentElement($loc);
56  }
57  }
58 
59  public function importFromPost()
60  {
61  $do_import = true;
62  if (!$this->isRequired()) {
63  $toggle = $this->getForm()->getInput($this->getElementId() . "_tgl");
64  if (!$toggle) {
65  $do_import = false;
66  }
67  }
68 
69  if ($do_import) {
70  // ilPropertyFormGUI::checkInput() is pre-requisite
71  $incoming = $this->getForm()->getInput($this->getElementId());
72  $this->getADT()->setLongitude($incoming["longitude"]);
73  $this->getADT()->setLatitude($incoming["latitude"]);
74  $this->getADT()->setZoom($incoming["zoom"]);
75  } else {
76  $this->getADT()->setLongitude(null);
77  $this->getADT()->setLatitude(null);
78  $this->getADT()->setZoom(null);
79  }
80 
81  $field = $this->getForm()->getItemByPostvar($this->getElementId());
82  $field->setLongitude($this->getADT()->getLongitude());
83  $field->setLatitude($this->getADT()->getLatitude());
84  $field->setZoom($this->getADT()->getZoom());
85  }
86 }
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
global $DIC
Definition: saml.php:7
ADT form bridge base class.
isRequired()
Get required.
This class represents a checkbox property in a property form.
ADT base class.
Definition: class.ilADT.php:11
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
$lng
static getDefaultSettings()
Get default longitude, latitude and zoom.
This class represents a location property in a property form.
$default
Definition: build.php:20
getElementId()
Get element id.
$def
Definition: croninfo.php:21