-
Notifications
You must be signed in to change notification settings - Fork 4
/
interactiveform.class.inc.php
123 lines (107 loc) · 3.21 KB
/
interactiveform.class.inc.php
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
<?php
/**
* @copyright Copyright (C) 2019 Super-Visions
* @license http://opensource.org/licenses/AGPL-3.0
*/
class GeolocationInteractiveForm implements iApplicationUIExtension
{
/**
* @inheritDoc
*/
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false)
{
if (!$bEditMode) return;
$aAttributes = MetaModel::FlattenZList(MetaModel::GetZListItems(get_class($oObject), 'details'));
foreach($aAttributes as $sAttCode)
{
$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);
}
}
}
/**
* 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 CoreException
*/
protected function DisplayInteractiveField(AttributeGeolocation $oAttDef, DBObject $oObject, WebPage $oPage)
{
$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);
switch (utils::GetConfig()->GetModuleSetting('sv-geolocation', 'provider'))
{
case 'GoogleMaps':
switch (UserRights::GetUserLanguage())
{
case 'PT BR':
case 'ZH CN':
$sLang = strtolower($sLang).'-'.$sRegion;
break;
default:
$sLang = strtolower($sLang);
break;
}
$oPage->add_linked_script(sprintf('https://maps.googleapis.com/maps/api/js?key=%s&callback=$.noop&language=%s', $sApiKey, $sLang));
$oPage->add_linked_script(utils::GetAbsoluteUrlModulesRoot().'sv-geolocation/js/google-maps-utils.js');
$oAttOptions = array('code' => $oAttDef->GetCode(), 'width' => $oAttDef->GetWidth(), 'height' => $oAttDef->GetHeight(), 'display' => $bDisplay);
$oMapOptions = array('center' => new ormGeolocation($iDefaultLat, $iDefaultLng), 'zoom' => $iZoom);
$oPage->add_ready_script(sprintf('make_interactive_map(%s, %s);', json_encode($oAttOptions), json_encode($oMapOptions)));
break;
default:
break;
}
}
/**
* Unused
*/
public function OnDisplayRelations($oObject, WebPage $oPage, $bEditMode = false)
{
}
/**
* Unused
*/
public function OnFormSubmit($oObject, $sFormPrefix = '')
{
}
/**
* Unused
*/
public function OnFormCancel($sTempId)
{
}
/**
* Unused
*/
public function EnumUsedAttributes($oObject)
{
return array();
}
/**
* Unused
*/
public function GetIcon($oObject)
{
}
/**
* Unused
*/
public function GetHilightClass($oObject)
{
}
/**
* Unused
*/
public function EnumAllowedActions(DBObjectSet $oSet)
{
return array();
}
}