forked from Super-Visions/sv-geolocation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractiveform.class.inc.php
More file actions
133 lines (115 loc) · 3.74 KB
/
interactiveform.class.inc.php
File metadata and controls
133 lines (115 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* @copyright 2019-2025 Super-Visions
* @license http://opensource.org/licenses/AGPL-3.0
*/
class GeolocationInteractiveForm implements iApplicationUIExtension
{
/**
* @inheritDoc
*/
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false): void
{
if (!$bEditMode) return;
$aAttributes = MetaModel::FlattenZList(MetaModel::GetZListItems(get_class($oObject), 'details'));
foreach($aAttributes as $sAttCode)
{
try
{
$oAttDef = MetaModel::GetAttributeDef(get_class($oObject), $sAttCode);
if (is_a($oAttDef, AttributeGeolocation::class) && !($oObject->GetAttributeFlags($sAttCode) & (OPT_ATT_READONLY | OPT_ATT_SLAVE)))
{
$this->DisplayInteractiveField($oAttDef, $oObject, $oPage);
}
} catch (Exception $e) {}
}
}
/**
* Add additional code to the page to alter the specified attribute into an interactive map
*
* @param AttributeGeolocation $oAttDef The field to enhance
* @param DBObject $oObject The object being displayed
* @param WebPage $oPage The output context
* @throws ConfigException
* @throws CoreException
* @throws Exception
*/
protected function DisplayInteractiveField(AttributeGeolocation $oAttDef, DBObject $oObject, WebPage $oPage): void
{
$sApiKey = utils::GetConfig()->GetModuleSetting('sv-geolocation', 'api_key');
$iDefaultLat = utils::GetConfig()->GetModuleSetting('sv-geolocation', 'default_latitude');
$iDefaultLng = utils::GetConfig()->GetModuleSetting('sv-geolocation', 'default_longitude');
$iZoom = utils::GetConfig()->GetModuleSetting('sv-geolocation', 'default_zoom');
$bDisplay = utils::GetConfig()->GetModuleSetting('sv-geolocation', 'display_coordinates');
list($sLang, $sRegion) = explode(' ', UserRights::GetUserLanguage(), 2);
$oAttOptions = ['code' => $oAttDef->GetCode(), 'width' => $oAttDef->GetWidth(), 'height' => $oAttDef->GetHeight(), 'display' => $bDisplay];
switch (utils::GetConfig()->GetModuleSetting('sv-geolocation', 'provider'))
{
case 'GoogleMaps':
$sLang = match (UserRights::GetUserLanguage())
{
'PT BR', 'ZH CN' => strtolower($sLang) . '-' . $sRegion,
default => strtolower($sLang),
};
$oPage->LinkScriptFromURI(sprintf('https://maps.googleapis.com/maps/api/js?key=%s&callback=$.noop&language=%s&libraries=marker', $sApiKey, $sLang));
$oPage->LinkScriptFromModule('sv-geolocation/js/google-maps-utils.js');
$oMapOptions = ['center' => new ormGeolocation($iDefaultLat, $iDefaultLng), 'zoom' => $iZoom, 'mapId' => $oAttDef->GetCode()];
break;
case 'MapLibre':
case 'MapTiler':
case 'OpenStreetMap':
$oPage->LinkScriptFromURI('https://unpkg.com/maplibre-gl/dist/maplibre-gl.js');
$oPage->LinkStylesheetFromURI('https://unpkg.com/maplibre-gl/dist/maplibre-gl.css');
$oPage->LinkScriptFromModule('sv-geolocation/js/maplibre-utils.js');
$oMapOptions = ['center' => [$iDefaultLng, $iDefaultLat], 'zoom' => $iZoom, 'style' => AttributeGeolocation::GetStyle()];
break;
default:
return;
}
$oPage->add_ready_script(sprintf('make_interactive_map(%s, %s);', json_encode($oAttOptions), json_encode($oMapOptions)));
}
/**
* @ignore Unused
*/
public function OnDisplayRelations($oObject, WebPage $oPage, $bEditMode = false)
{
}
/**
* @ignore Unused
*/
public function OnFormSubmit($oObject, $sFormPrefix = '')
{
}
/**
* @ignore Unused
*/
public function OnFormCancel($sTempId)
{
}
/**
* @ignore Unused
*/
public function EnumUsedAttributes($oObject): array
{
return [];
}
/**
* @ignore Unused
*/
public function GetIcon($oObject)
{
}
/**
* @ignore Unused
*/
public function GetHilightClass($oObject)
{
}
/**
* @ignore Unused
*/
public function EnumAllowedActions(DBObjectSet $oSet): array
{
return [];
}
}