Skip to content

Commit 01878ec

Browse files
committed
INTERIM: HC Settings show URL param options
1 parent 8e9943e commit 01878ec

File tree

2 files changed

+118
-18
lines changed

2 files changed

+118
-18
lines changed

code/web/Drivers/Koha.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,8 @@ public function getFineById(string $id, bool $includeAdditionalFieldValues = fal
30393039
return $formattedFine;
30403040
}
30413041

3042-
$additionalFineFieldValues = $this->getAdditionalFieldValuesByTable('accountlines:debit');
3042+
// $additionalFineFieldValues = $this->getAdditionalFieldValuesByTable('accountlines:debit');
3043+
$additionalFineFieldValues = $this->getAdditionalFieldValuesByTable('account_debit_types');
30433044

30443045
if (empty($additionalFineFieldValues)) {
30453046
return $formattedFine;
@@ -3079,6 +3080,14 @@ public function getAdditionalFieldValuesByTable(string $tableName) {
30793080
return $values;
30803081
}
30813082

3083+
public function getAdditionalFieldsNamesByTable(string $tableName, string $category = null): array {
3084+
$fieldNamesList = [];
3085+
foreach($this->getAdditionalFieldsByTable($tableName, $category) as $fields) {
3086+
$fieldNamesList[] = $fields['name'];
3087+
}
3088+
return $fieldNamesList;
3089+
}
3090+
30823091
private function getAdditionalFieldsByTable(string $tableName, string $category = null): array {
30833092
// TODO: refactor to send a GET request to the api/v1/extended_attribute_types endpoint instead
30843093
$this->initDatabaseConnection();

code/web/sys/ECommerce/HeyCentricSetting.php

+108-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
require_once ROOT_DIR . '/sys/ECommerce/HeyCentricUrlParameterSettings.php';
34

45
class HeyCentricSetting extends DataObject {
56
public $__table = 'heycentric_setting';
@@ -15,13 +16,37 @@ class HeyCentricSetting extends DataObject {
1516
public $rurl;
1617

1718
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+
}
1841

1942
public function getEncryptedFieldNames(): array {
2043
return ['privateKey'];
2144
}
2245

2346
static function getObjectStructure($context = ''): array {
2447
$libraryList = Library::getLibraryList(!UserAccount::userHasPermission('Administer All Libraries'));
48+
$locationList = Location::getLocationList(!UserAccount::userHasPermission('Administer All Locations'));
49+
$urlParams = HeyCentricSetting::getHeyCentricUrlParamFields();
2550

2651
$structure = [
2752
'id' => [
@@ -53,39 +78,26 @@ static function getObjectStructure($context = ''): array {
5378
'label' => 'HeyCentric Private Key',
5479
'description' => 'The HeyCentric Private Key for your site',
5580
'maxLength' => 50,
56-
'required' => true,
5781
],
5882
'client' => [
5983
'property' => 'client',
6084
'type' => 'text',
6185
'label' => 'Client',
6286
'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,
7387
],
7488
'till' => [
7589
'property' => 'till',
7690
'type' => 'text',
7791
'label' => 'Till',
7892
'description' => '',
7993
'maxLength' => 10,
80-
'required' => true,
8194
],
8295
'area' => [
8396
'property' => 'area',
8497
'type' => 'text',
8598
'label' => 'Area',
8699
'description' => '',
87100
'maxLength' => 50,
88-
'required' => true,
89101
],
90102
'rurl' => [
91103
'property' => 'rurl',
@@ -96,6 +108,16 @@ static function getObjectStructure($context = ''): array {
96108
'maxLength' => 50,
97109
'default' => ROOT_DIR . '/MyAccount/AJAX?method=completeHeyCentricOrder'
98110
],
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+
],
99121
'libraries' => [
100122
'property' => 'libraries',
101123
'type' => 'multiSelect',
@@ -105,6 +127,15 @@ static function getObjectStructure($context = ''): array {
105127
'values' => $libraryList,
106128
'hideInLists' => true,
107129
],
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+
],
108139
];
109140

110141
if (!UserAccount::userHasPermission('Library eCommerce Options')) {
@@ -126,22 +157,35 @@ public function __get($name) {
126157
}
127158
return $this->_libraries;
128159
} else {
160+
161+
// TODO: handle locations
162+
// TODO: handle url parameters and parameters settings
129163
return parent::__get($name);
130164
}
131165
}
132166

133167
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);
138180
}
139181
}
140182

141183
public function update($context = '') {
142184
$ret = parent::update();
143185
if ($ret !== FALSE) {
144186
$this->saveLibraries();
187+
$this->saveLocations();
188+
$this->saveUrlParameters();
145189
}
146190
return true;
147191
}
@@ -150,6 +194,8 @@ public function insert($context = '') {
150194
$ret = parent::insert();
151195
if ($ret !== FALSE) {
152196
$this->saveLibraries();
197+
$this->saveLocations();
198+
$this->saveUrlParameters();
153199
}
154200
return $ret;
155201
}
@@ -182,4 +228,49 @@ public function saveLibraries() {
182228
unset($this->_libraries);
183229
}
184230
}
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+
}
185276
}

0 commit comments

Comments
 (0)