1
1
<?php
2
2
3
+ require_once ROOT_DIR . '/sys/ECommerce/HeyCentricUrlParameterSettings.php ' ;
3
4
4
5
class HeyCentricSetting extends DataObject {
5
6
public $ __table = 'heycentric_setting ' ;
@@ -15,13 +16,37 @@ class HeyCentricSetting extends DataObject {
15
16
public $ rurl ;
16
17
17
18
private $ _libraries ;
19
+ private $ _locations ;
20
+ private $ _urlParameters ;
21
+
22
+ static function getHeyCentricUrlParamFields () {
23
+ $ urlParamsArr = [];
24
+ $ urlParam = new HeyCentricUrlParameter ();
25
+ $ urlParam = $ urlParam ->fetchAll ();
26
+
27
+ foreach ($ urlParam as $ param ) {
28
+ $ urlParamsArr [] = [
29
+ 'id ' => $ param ->id ,
30
+ 'property ' => $ param ->name ,
31
+ 'type ' => 'section ' ,
32
+ 'label ' => $ param ->name ,
33
+ 'description ' => '' ,
34
+ 'maxLength ' => 10 ,
35
+ 'required ' => true ,
36
+ 'properties ' => HeyCentricUrlParameterSettings::getObjectStructure (),
37
+ ];
38
+ }
39
+ return $ urlParamsArr ;
40
+ }
18
41
19
42
public function getEncryptedFieldNames (): array {
20
43
return ['privateKey ' ];
21
44
}
22
45
23
46
static function getObjectStructure ($ context = '' ): array {
24
47
$ libraryList = Library::getLibraryList (!UserAccount::userHasPermission ('Administer All Libraries ' ));
48
+ $ locationList = Location::getLocationList (!UserAccount::userHasPermission ('Administer All Locations ' ));
49
+ $ urlParams = HeyCentricSetting::getHeyCentricUrlParamFields ();
25
50
26
51
$ structure = [
27
52
'id ' => [
@@ -53,39 +78,26 @@ static function getObjectStructure($context = ''): array {
53
78
'label ' => 'HeyCentric Private Key ' ,
54
79
'description ' => 'The HeyCentric Private Key for your site ' ,
55
80
'maxLength ' => 50 ,
56
- 'required ' => true ,
57
81
],
58
82
'client ' => [
59
83
'property ' => 'client ' ,
60
84
'type ' => 'text ' ,
61
85
'label ' => 'Client ' ,
62
86
'description ' => '' ,
63
- 'maxLength ' => 10 ,
64
- 'required ' => true ,
65
- ],
66
- 'entity ' => [
67
- 'property ' => 'entity ' ,
68
- 'type ' => 'text ' ,
69
- 'label ' => 'Entity ' ,
70
- 'description ' => '' ,
71
- 'maxLength ' => 10 ,
72
- 'required ' => true ,
73
87
],
74
88
'till ' => [
75
89
'property ' => 'till ' ,
76
90
'type ' => 'text ' ,
77
91
'label ' => 'Till ' ,
78
92
'description ' => '' ,
79
93
'maxLength ' => 10 ,
80
- 'required ' => true ,
81
94
],
82
95
'area ' => [
83
96
'property ' => 'area ' ,
84
97
'type ' => 'text ' ,
85
98
'label ' => 'Area ' ,
86
99
'description ' => '' ,
87
100
'maxLength ' => 50 ,
88
- 'required ' => true ,
89
101
],
90
102
'rurl ' => [
91
103
'property ' => 'rurl ' ,
@@ -96,6 +108,16 @@ static function getObjectStructure($context = ''): array {
96
108
'maxLength ' => 50 ,
97
109
'default ' => ROOT_DIR . '/MyAccount/AJAX?method=completeHeyCentricOrder '
98
110
],
111
+ 'urlParameters ' => [
112
+ 'property ' => 'urlParameters ' ,
113
+ 'type ' => 'section ' ,
114
+ 'hideInLists ' => true ,
115
+ 'label ' => 'HeyCentric Payment URL Parameters ' ,
116
+ 'description ' => 'The parameters to include when forming the HeyCentric payment URL and/or its hash ' ,
117
+ 'maxLength ' => 50 ,
118
+ 'required ' => true ,
119
+ 'properties ' => $ urlParams ,
120
+ ],
99
121
'libraries ' => [
100
122
'property ' => 'libraries ' ,
101
123
'type ' => 'multiSelect ' ,
@@ -105,6 +127,15 @@ static function getObjectStructure($context = ''): array {
105
127
'values ' => $ libraryList ,
106
128
'hideInLists ' => true ,
107
129
],
130
+ 'locations ' => [
131
+ 'property ' => 'locations ' ,
132
+ 'type ' => 'multiSelect ' ,
133
+ 'listStyle ' => 'checkboxSimple ' ,
134
+ 'label ' => 'Locations ' ,
135
+ 'description ' => 'Define locations that use these settings ' ,
136
+ 'values ' => $ locationList ,
137
+ 'hideInLists ' => true ,
138
+ ],
108
139
];
109
140
110
141
if (!UserAccount::userHasPermission ('Library eCommerce Options ' )) {
@@ -126,22 +157,35 @@ public function __get($name) {
126
157
}
127
158
return $ this ->_libraries ;
128
159
} else {
160
+
161
+ // TODO: handle locations
162
+ // TODO: handle url parameters and parameters settings
129
163
return parent ::__get ($ name );
130
164
}
131
165
}
132
166
133
167
public function __set ($ name , $ value ) {
134
- if ($ name == "libraries " ) {
135
- $ this ->_libraries = $ value ;
136
- } else {
137
- parent ::__set ($ name , $ value );
168
+ switch ($ name ) {
169
+ case "libraries " :
170
+ $ this ->_libraries = $ value ;
171
+ break ;
172
+ case "locations " :
173
+ $ this ->_locations = $ value ;
174
+ break ;
175
+ case "urlParameters " :
176
+ $ this ->_urlParameters = $ value ;
177
+ break ;
178
+ default :
179
+ parent ::__set ($ name , $ value );
138
180
}
139
181
}
140
182
141
183
public function update ($ context = '' ) {
142
184
$ ret = parent ::update ();
143
185
if ($ ret !== FALSE ) {
144
186
$ this ->saveLibraries ();
187
+ $ this ->saveLocations ();
188
+ $ this ->saveUrlParameters ();
145
189
}
146
190
return true ;
147
191
}
@@ -150,6 +194,8 @@ public function insert($context = '') {
150
194
$ ret = parent ::insert ();
151
195
if ($ ret !== FALSE ) {
152
196
$ this ->saveLibraries ();
197
+ $ this ->saveLocations ();
198
+ $ this ->saveUrlParameters ();
153
199
}
154
200
return $ ret ;
155
201
}
@@ -182,4 +228,49 @@ public function saveLibraries() {
182
228
unset($ this ->_libraries );
183
229
}
184
230
}
231
+
232
+ public function saveUrlParameters () {
233
+ // TODO: saveURLParameters
234
+ if (isset ($ this ->_urlParameters ) && is_array ($ this ->_urlParameters )) {
235
+ $ urlParams = HeyCentricSetting::getHeyCentricUrlParamFields ();
236
+ foreach ($ urlParams as $ urlParam ) {
237
+ $ urlParamSetting = new HeyCentricUrlParameterSettings ();
238
+ $ urlParamSetting ->heyCentricSettingId = $ this ->id ;
239
+ $ urlParamSetting ->heyCenticUrlParameterId = $ urlParam ['id ' ];
240
+ $ urlParamSetting ->update ();
241
+ }
242
+ global $ logger ;
243
+ $ logger ->log (json_encode ($ urlParamSetting ), Logger::LOG_ERROR );
244
+ unset($ this ->_urlParameters );
245
+ }
246
+ }
247
+
248
+
249
+ // TODO: make HeyCentric specifc instead of websites
250
+ public function getLocations () {
251
+ if (!isset ($ this ->_locations ) && $ this ->id ) {
252
+ $ this ->_locations = [];
253
+ $ location = new LocationWebsiteIndexing ();
254
+ $ location ->settingId = $ this ->id ;
255
+ $ location ->find ();
256
+ while ($ location ->fetch ()) {
257
+ $ this ->_locations [$ location ->locationId ] = $ location ->locationId ;
258
+ }
259
+ }
260
+ return $ this ->_locations ;
261
+ }
262
+
263
+ public function saveLocations () {
264
+ if (isset ($ this ->_locations ) && is_array ($ this ->_locations )) {
265
+
266
+ foreach ($ this ->_locations as $ libraryId ) {
267
+ $ locationWebsiteIndexing = new LocationWebsiteIndexing ();
268
+
269
+ $ locationWebsiteIndexing ->settingId = $ this ->id ;
270
+ $ locationWebsiteIndexing ->locationId = $ libraryId ;
271
+ $ locationWebsiteIndexing ->insert ();
272
+ }
273
+ unset($ this ->_locations );
274
+ }
275
+ }
185
276
}
0 commit comments