ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTLocationFormBridge.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected function isValidADT(ilADT $a_adt): bool
24 {
25 return ($a_adt instanceof ilADTLocation);
26 }
27
28 public function addToForm(): void
29 {
30 $adt = $this->getADT();
31
32 $default = false;
33 if ($adt->isNull()) {
34 // see ilPersonalProfileGUI::addLocationToForm()
35 // use installation default
37 $adt->setLatitude((float) $def["latitude"]);
38 $adt->setLongitude((float) $def["longitude"]);
39 $adt->setZoom((int) $def["zoom"]);
40
41 $default = true;
42 }
43
44 // :TODO: title?
45 $title = $this->isRequired()
46 ? $this->getTitle()
47 : $this->lng->txt("location");
48
49 $loc = new ilLocationInputGUI($title, $this->getElementId());
50 $loc->setLongitude($adt->getLongitude());
51 $loc->setLatitude($adt->getLatitude());
52 $loc->setZoom($adt->getZoom());
53
55
56 if (!$this->isRequired()) {
57 $optional = new ilCheckboxInputGUI($this->getTitle(), $this->getElementId() . "_tgl");
58 $optional->addSubItem($loc);
59 $this->addToParentElement($optional);
60
61 if (!$default && !$adt->isNull()) {
62 $optional->setChecked(true);
63 }
64 } else {
65 $this->addToParentElement($loc);
66 }
67 }
68
69 public function importFromPost(): void
70 {
71 $do_import = true;
72 if (!$this->isRequired()) {
73 $toggle = $this->getForm()->getInput($this->getElementId() . "_tgl");
74 if (!$toggle) {
75 $do_import = false;
76 }
77 }
78
79 if ($do_import) {
80 // ilPropertyFormGUI::checkInput() is pre-requisite
81 $incoming = $this->getForm()->getInput($this->getElementId());
82 $this->getADT()->setLongitude((float) $incoming["longitude"]);
83 $this->getADT()->setLatitude((float) $incoming["latitude"]);
84 $this->getADT()->setZoom((int) $incoming["zoom"]);
85 } else {
86 $this->getADT()->setLongitude(null);
87 $this->getADT()->setLatitude(null);
88 $this->getADT()->setZoom(null);
89 }
90
91 $field = $this->getForm()->getItemByPostVar($this->getElementId());
92 $field->setLongitude($this->getADT()->getLongitude());
93 $field->setLatitude($this->getADT()->getLatitude());
94 $field->setZoom($this->getADT()->getZoom());
95 }
96}
ADT form bridge base class.
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
addToParentElement(ilFormPropertyGUI $a_field)
addToForm()
Add ADT-specific fields to form.
importFromPost()
Import values from form request POST data.
ADT base class.
Definition: class.ilADT.php:26
isNull()
Is currently null.
getCopyOfDefinition()
Get copy of definition.
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.