ILIAS  release_8 Revision v8.24
class.ilADTLocationFormBridge.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6{
7 protected function isValidADT(ilADT $a_adt): bool
8 {
9 return ($a_adt instanceof ilADTLocation);
10 }
11
12 public function addToForm(): void
13 {
14 $adt = $this->getADT();
15
16 $default = false;
17 if ($adt->isNull()) {
18 // see ilPersonalProfileGUI::addLocationToForm()
19 // use installation default
21 $adt->setLatitude((float) $def["latitude"]);
22 $adt->setLongitude((float) $def["longitude"]);
23 $adt->setZoom((int) $def["zoom"]);
24
25 $default = true;
26 }
27
28 // :TODO: title?
29 $title = $this->isRequired()
30 ? $this->getTitle()
31 : $this->lng->txt("location");
32
33 $loc = new ilLocationInputGUI($title, $this->getElementId());
34 $loc->setLongitude($adt->getLongitude());
35 $loc->setLatitude($adt->getLatitude());
36 $loc->setZoom($adt->getZoom());
37
39
40 if (!$this->isRequired()) {
41 $optional = new ilCheckboxInputGUI($this->getTitle(), $this->getElementId() . "_tgl");
42 $optional->addSubItem($loc);
43 $this->addToParentElement($optional);
44
45 if (!$default && !$adt->isNull()) {
46 $optional->setChecked(true);
47 }
48 } else {
49 $this->addToParentElement($loc);
50 }
51 }
52
53 public function importFromPost(): void
54 {
55 $do_import = true;
56 if (!$this->isRequired()) {
57 $toggle = $this->getForm()->getInput($this->getElementId() . "_tgl");
58 if (!$toggle) {
59 $do_import = false;
60 }
61 }
62
63 if ($do_import) {
64 // ilPropertyFormGUI::checkInput() is pre-requisite
65 $incoming = $this->getForm()->getInput($this->getElementId());
66 $this->getADT()->setLongitude((float) $incoming["longitude"]);
67 $this->getADT()->setLatitude((float) $incoming["latitude"]);
68 $this->getADT()->setZoom((int) $incoming["zoom"]);
69 } else {
70 $this->getADT()->setLongitude(null);
71 $this->getADT()->setLatitude(null);
72 $this->getADT()->setZoom(null);
73 }
74
75 $field = $this->getForm()->getItemByPostVar($this->getElementId());
76 $field->setLongitude($this->getADT()->getLongitude());
77 $field->setLatitude($this->getADT()->getLatitude());
78 $field->setZoom($this->getADT()->getZoom());
79 }
80}
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:12
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.