-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathSystemValues.php
123 lines (111 loc) · 3.38 KB
/
SystemValues.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
namespace ToolkitApi;
/**
* Class SystemValues
*
* @package ToolkitApi
*/
class SystemValues
{
private $ToolkitSrvObj;
private $ErrMessage;
/**
* @param ToolkitInterface $ToolkitSrvObj
*/
public function __construct(?ToolkitInterface $ToolkitSrvObj = null){
if ($ToolkitSrvObj instanceof Toolkit) {
$this->ToolkitSrvObj = $ToolkitSrvObj;
return $this;
} else {
return false;
}
}
/**
*
* @todo Deprecate setConnection in future.
*
* @param $dbname
* @param $user
* @param $pass
*/
public function setConnection ($dbname , $user, $pass)
{
if (!$this->ToolkitSrvObj instanceof Toolkit) {
$this->ToolkitSrvObj = new Toolkit($dbname, $user, $pass);
}
}
/**
* @return array|bool
*/
public function systemValuesList()
{
if (!$this->ToolkitSrvObj instanceof Toolkit) {
return false;
}
$tmparray = $this->ToolkitSrvObj->CLInteractiveCommand ('WRKSYSVAL OUTPUT(*PRINT)');
if (isset($tmparray)) {
$i = 4;
while (isset($tmparray [$i + 1])) {
$tmparr = trim($tmparray [++$i]);
if (substr($tmparr, 0, 1) == 'Q') {
$len = strlen ($tmparr);
$sysvals [] = array('Name' => substr ($tmparr, 0, 10),
'CurrentValue' => substr ($tmparr, 15, 32),
'ShippedValue' => substr ($tmparr, 47, 32),
'Description' => substr ($tmparr, 79, ($len - 79)));
}
}
return $sysvals;
} else {
return false;
}
}
/**
* @todo QWCRSVAL to work with 2 tiers while retaining good performance
*
* @param $sysValueName
*/
public function getSystemValue($sysValueName)
{
if (!$this->ToolkitSrvObj instanceof Toolkit) {
return false;
}
$Err = ' ';
$SysValue = ' ';
$params [] = $this->ToolkitSrvObj->AddParameterChar('both', 1, "ErrorCode", 'errorcode', $Err);
$params [] = $this->ToolkitSrvObj->AddParameterChar('both', 10, "SysValName", 'sysvalname', $sysValueName);
$params [] = $this->ToolkitSrvObj->AddParameterChar('both', 1024, "SysValue", 'sysval', $SysValue);
$retArr = $this->ToolkitSrvObj->PgmCall(ZSTOOLKITPGM, $this->ToolkitSrvObj->getOption('HelperLib'), $params, NULL, array('func' => 'RTVSYSVAL'));
if ($retArr !== false && isset($retArr['io_param'])) {
$sysval = $retArr['io_param'];
if (isset($sysval['sysvalname'])) {
return $sysval['sysval'];
} else {
$this->setError($sysval['errorcode']);
}
}
}
/**
* @return mixed
*/
public function getError() {
return $this->ErrMessage;
}
/**
* @param $errCode
*/
private function setError($errCode)
{
if ($errCode == '') /*clear error message*/ {
$this->ErrMessage = '';
return;
}
if ($errCode == '1') {
$this->ErrMessage = 'System value data is not available.';
} else {
if ($errCode == '2') {
$this->ErrMessage = 'System value can not be retrieved. ';
}
}
}
}