ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
class.ilObjMapsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 private readonly ilRbacSystem $rbacsystem;
28
29 public function __construct($data, int $id = 0, bool $call_by_reference = true, bool $prepare_output = true)
30 {
32 global $DIC;
33 $this->rbacsystem = $DIC->rbac()->system();
34 }
35
36 public function executeCommand(): void
37 {
38 if (!$this->rbacsystem->checkAccess('read', $this->object->getRefId())) {
39 $this->ilias->raiseError(
40 $this->lng->txt('permission_denied'),
41 $this->ilias->error_obj->MESSAGE
42 );
43 }
44
45 $this->lng->loadLanguageModule('maps');
46 $this->tpl->setTitle($this->lng->txt('obj_maps'));
47 $this->initTabs();
48 switch ($this->ctrl->getNextClass()) {
49 case strtolower(ilPermissionGUI::class):
50 $this->ctrl->forwardCommand(new ilPermissionGUI($this));
51 $this->tabs_gui->activateTab('permissions');
52 break;
53 default:
54 $cmd = $this->ctrl->getCmd('view');
55 if (in_array($cmd, ['view', 'save'], true)) {
56 $this->tabs_gui->activateTab('view');
57 $this->$cmd();
58 }
59 break;
60 }
61 }
62
63 public function view(): void
64 {
65 $this->tpl->setContent($this->buildForm()->getHTML());
66 }
67
68 private function initTabs(): void
69 {
70 $this->tabs_gui->addTab(
71 'view',
72 $this->lng->txt('view'),
73 $this->ctrl->getLinkTarget($this, 'view'),
74 );
75
76 $this->tabs_gui->addTab(
77 'permissions',
78 $this->lng->txt('perm_settings'),
79 $this->ctrl->getLinkTargetByClass([self::class, ilPermissionGUI::class], 'perm')
80 );
81 }
82
83 private function buildForm(): ilPropertyFormGUI
84 {
86 $ilCtrl = $this->ctrl;
87 $std_latitude = (float) ilMapUtil::getStdLatitude();
88 $std_longitude = (float) ilMapUtil::getStdLongitude();
89 $std_zoom = ilMapUtil::getStdZoom();
91 $form = new ilPropertyFormGUI();
92 $form->setFormAction($ilCtrl->getFormAction($this));
93 $form->setTitle($lng->txt('maps_settings'));
94
95 // Enable Maps
96 $enable = new ilCheckboxInputGUI($lng->txt('maps_enable_maps'), 'enable');
97 $enable->setChecked(ilMapUtil::isActivated());
98 $enable->setInfo($lng->txt('maps_enable_maps_info'));
99 $form->addItem($enable);
100
101 // Select type
102 $types = new ilSelectInputGUI($lng->txt('maps_map_type'), 'type');
103 $types->setOptions(ilMapUtil::getAvailableMapTypes());
104 $types->setValue($type);
105 $form->addItem($types);
106
107 // map data server property
108 if ($type === 'openlayers') {
109 $tile = new ilTextInputGUI($lng->txt('maps_tile_server'), 'tile');
110 $tile->setValue(ilMapUtil::getStdTileServers());
111 $tile->setInfo(sprintf($lng->txt('maps_custom_tile_server_info'), ilMapUtil::DEFAULT_TILE));
112 $geolocation = new ilTextInputGUI($lng->txt('maps_geolocation_server'), 'geolocation');
113 $geolocation->setValue(ilMapUtil::getStdGeolocationServer());
114 $geolocation->setInfo($lng->txt('maps_custom_geolocation_server_info'));
115
116 $form->addItem($tile);
117 $form->addItem($geolocation);
118 } else {
119 // api key for google
120 $key = new ilTextInputGUI('Google API Key', 'api_key');
121 $key->setMaxLength(200);
122 $key->setValue(ilMapUtil::getApiKey());
123 $form->addItem($key);
124 }
125
126 // location property
127 $loc_prop = new ilLocationInputGUI(
128 $lng->txt('maps_std_location'),
129 'std_location'
130 );
131
132 $loc_prop->setLatitude($std_latitude);
133 $loc_prop->setLongitude($std_longitude);
134 $loc_prop->setZoom((int) $std_zoom);
135 $form->addItem($loc_prop);
136
137 if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
138 $form->addCommandButton('save', $lng->txt('save'));
139 $form->addCommandButton('view', $lng->txt('cancel'));
140 }
141
142 return $form;
143 }
144
145 private function save(): void
146 {
147 $form = $this->buildForm();
148 if ($form->checkInput()) {
149 if ($form->getInput('type') === 'openlayers' && 'openlayers' === ilMapUtil::getType()) {
150 ilMapUtil::setStdTileServers($form->getInput('tile'));
152 $form->getInput('geolocation')
153 );
154 } else {
155 ilMapUtil::setApiKey($form->getInput('api_key'));
156 }
157
158 ilMapUtil::setActivated($form->getInput('enable') === '1');
159 ilMapUtil::setType($form->getInput('type'));
160 $location = $form->getInput('std_location');
161 ilMapUtil::setStdLatitude((string) $location['latitude']);
162 ilMapUtil::setStdLongitude((string) $location['longitude']);
163 ilMapUtil::setStdZoom((string) $location['zoom']);
164 }
165 $this->ctrl->redirect($this, 'view');
166 }
167}
$location
Definition: buildRTE.php:22
This class represents a checkbox property in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This class represents a location property in a property form.
static setActivated(bool $activated)
static getApiKey()
static getStdGeolocationServer()
Returns the reverse geolocation server to be used in the installation.
static getStdLatitude()
static setStdLongitude(string $lon)
static setStdTileServers(string $tile)
static setStdLatitude(string $lat)
static getStdTileServers()
Returns the tile server to be used in the installation.
static getStdLongitude()
static setStdGeolocationServer($geolocation)
static getStdZoom()
const DEFAULT_TILE
static setStdZoom(string $zoom)
static isActivated()
Checks whether Map feature is activated.
static setType(string $type)
static getAvailableMapTypes()
Get a dict { $id => $name } for available maps services.
static setApiKey(string $api_key)
static getType()
@ilCtrl_isCalledBy ilObjMapsGUI: ilAdministrationGUI @ilCtrl_Calls ilObjMapsGUI: ilPermissionGUI
readonly ilRbacSystem $rbacsystem
__construct($data, int $id=0, bool $call_by_reference=true, bool $prepare_output=true)
Class ilObjectGUI Basic methods of all Output classes.
ilLanguage $lng
This class represents a property form user interface.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This class represents a selection list property in a property form.
This class represents a text property in a property form.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ilObjForumAdministration.
global $DIC
Definition: shib_login.php:26