ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $lng;
15 
16  $adt = $this->getADT();
17 
18  $default = false;
19  if($adt->isNull())
20  {
21  // see ilPersonalProfileGUI::addLocationToForm()
22 
23  // use installation default
24  include_once("./Services/Maps/classes/class.ilMapUtil.php");
26  $adt->setLatitude($def["latitude"]);
27  $adt->setLongitude($def["longitude"]);
28  $adt->setZoom($def["zoom"]);
29 
30  $default = true;
31  }
32 
33  // :TODO: title?
34  $title = $this->isRequired()
35  ? $this->getTitle()
36  : $lng->txt("location");
37 
38  $loc = new ilLocationInputGUI($title, $this->getElementId());
39  $loc->setLongitude($adt->getLongitude());
40  $loc->setLatitude($adt->getLatitude());
41  $loc->setZoom($adt->getZoom());
42 
43  $this->addBasicFieldProperties($loc, $adt->getCopyOfDefinition());
44 
45  if(!$this->isRequired())
46  {
47  $optional = new ilCheckboxInputGUI($this->getTitle(), $this->getElementId()."_tgl");
48  $optional->addSubItem($loc);
49  $this->addToParentElement($optional);
50 
51  if(!$default && !$adt->isNull())
52  {
53  $optional->setChecked(true);
54  }
55  }
56  else
57  {
58  $this->addToParentElement($loc);
59  }
60  }
61 
62  public function importFromPost()
63  {
64  $do_import = true;
65  if(!$this->isRequired())
66  {
67  $toggle = $this->getForm()->getInput($this->getElementId()."_tgl");
68  if(!$toggle)
69  {
70  $do_import = false;
71  }
72  }
73 
74  if($do_import)
75  {
76  // ilPropertyFormGUI::checkInput() is pre-requisite
77  $incoming = $this->getForm()->getInput($this->getElementId());
78  $this->getADT()->setLongitude($incoming["longitude"]);
79  $this->getADT()->setLatitude($incoming["latitude"]);
80  $this->getADT()->setZoom($incoming["zoom"]);
81  }
82  else
83  {
84  $this->getADT()->setLongitude(null);
85  $this->getADT()->setLatitude(null);
86  $this->getADT()->setZoom(null);
87  }
88 
89  $field = $this->getForm()->getItemByPostvar($this->getElementId());
90  $field->setLongitude($this->getADT()->getLongitude());
91  $field->setLatitude($this->getADT()->getLatitude());
92  $field->setZoom($this->getADT()->getZoom());
93  }
94 }
95 
96 ?>
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
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()
static getDefaultSettings()
Get default longitude, latitude and zoom.
This class represents a location property in a property form.
getElementId()
Get element id.
global $lng
Definition: privfeed.php:17