ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
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->tpl->setTitleIcon(ilObject::_getIcon($this->object->getId()));
48 $this->initTabs();
49 switch ($this->ctrl->getNextClass()) {
50 case strtolower(ilPermissionGUI::class):
51 $this->ctrl->forwardCommand(new ilPermissionGUI($this));
52 $this->tabs_gui->activateTab('permissions');
53 break;
54 default:
55 $cmd = $this->ctrl->getCmd('view');
56 if (in_array($cmd, ['view', 'save'], true)) {
57 $this->tabs_gui->activateTab('view');
58 $this->$cmd();
59 }
60 break;
61 }
62 }
63
64 public function view(): void
65 {
66 $this->tpl->setContent($this->buildForm()->getHTML());
67 }
68
69 private function initTabs(): void
70 {
71 $this->tabs_gui->addTab(
72 'view',
73 $this->lng->txt('view'),
74 $this->ctrl->getLinkTarget($this, 'view'),
75 );
76
77 $this->tabs_gui->addTab(
78 'permissions',
79 $this->lng->txt('perm_settings'),
80 $this->ctrl->getLinkTargetByClass([self::class, ilPermissionGUI::class], 'perm')
81 );
82 }
83
84 private function buildForm(): ilPropertyFormGUI
85 {
87 $ilCtrl = $this->ctrl;
88 $std_latitude = (float) ilMapUtil::getStdLatitude();
89 $std_longitude = (float) ilMapUtil::getStdLongitude();
90 $std_zoom = ilMapUtil::getStdZoom();
92 $form = new ilPropertyFormGUI();
93 $form->setFormAction($ilCtrl->getFormAction($this));
94 $form->setTitle($lng->txt('maps_settings'));
95
96 // Enable Maps
97 $enable = new ilCheckboxInputGUI($lng->txt('maps_enable_maps'), 'enable');
98 $enable->setChecked(ilMapUtil::isActivated());
99 $enable->setInfo($lng->txt('maps_enable_maps_info'));
100 $form->addItem($enable);
101
102 // Select type
103 $types = new ilSelectInputGUI($lng->txt('maps_map_type'), 'type');
104 $types->setOptions(ilMapUtil::getAvailableMapTypes());
105 $types->setValue($type);
106 $form->addItem($types);
107
108 // map data server property
109 if ($type === 'openlayers') {
110 $tile = new ilTextInputGUI($lng->txt('maps_tile_server'), 'tile');
111 $tile->setValue(ilMapUtil::getStdTileServers());
112 $tile->setInfo(sprintf($lng->txt('maps_custom_tile_server_info'), ilMapUtil::DEFAULT_TILE));
113 $geolocation = new ilTextInputGUI($lng->txt('maps_geolocation_server'), 'geolocation');
114 $geolocation->setValue(ilMapUtil::getStdGeolocationServer());
115 $geolocation->setInfo($lng->txt('maps_custom_geolocation_server_info'));
116
117 $form->addItem($tile);
118 $form->addItem($geolocation);
119 } else {
120 // api key for google
121 $key = new ilTextInputGUI('Google API Key', 'api_key');
122 $key->setMaxLength(200);
123 $key->setValue(ilMapUtil::getApiKey());
124 $form->addItem($key);
125 }
126
127 // location property
128 $loc_prop = new ilLocationInputGUI(
129 $lng->txt('maps_std_location'),
130 'std_location'
131 );
132
133 $loc_prop->setLatitude($std_latitude);
134 $loc_prop->setLongitude($std_longitude);
135 $loc_prop->setZoom((int) $std_zoom);
136 $form->addItem($loc_prop);
137
138 if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
139 $form->addCommandButton('save', $lng->txt('save'));
140 $form->addCommandButton('view', $lng->txt('cancel'));
141 }
142
143 return $form;
144 }
145
146 private function save(): void
147 {
148 $form = $this->buildForm();
149 if ($form->checkInput()) {
150 if ($form->getInput('type') === 'openlayers' && 'openlayers' === ilMapUtil::getType()) {
151 ilMapUtil::setStdTileServers($form->getInput('tile'));
153 $form->getInput('geolocation')
154 );
155 } else {
156 ilMapUtil::setApiKey($form->getInput('api_key'));
157 }
158
159 ilMapUtil::setActivated($form->getInput('enable') === '1');
160 ilMapUtil::setType($form->getInput('type'));
161 $location = $form->getInput('std_location');
162 ilMapUtil::setStdLatitude((string) $location['latitude']);
163 ilMapUtil::setStdLongitude((string) $location['longitude']);
164 ilMapUtil::setStdZoom((string) $location['zoom']);
165 }
166 $this->ctrl->redirect($this, 'view');
167 }
168}
$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
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
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