1
|
|
|
<?php namespace XoopsModules\Smartobject; |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* You may not change or alter any portion of this comment or credits |
5
|
|
|
* of supporting developers from this source code or any supporting source code |
6
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
* |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @copyright XOOPS Project https://xoops.org/ |
15
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
16
|
|
|
* @package |
17
|
|
|
* @since |
18
|
|
|
* @author XOOPS Development Team |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use XoopsModules\Smartobject; |
22
|
|
|
|
23
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
24
|
|
|
|
25
|
|
|
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
26
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class SmartobjectCurrency |
30
|
|
|
*/ |
31
|
|
|
class Currency extends Smartobject\BaseSmartObject |
32
|
|
|
{ |
33
|
|
|
public $_modulePlugin = false; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* SmartobjectCurrency constructor. |
37
|
|
|
*/ |
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
$this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
41
|
|
|
$this->quickInitVar('iso4217', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_ISO4217, _CO_SOBJECT_CURRENCY_ISO4217_DSC); |
42
|
|
|
$this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_NAME); |
43
|
|
|
$this->quickInitVar('symbol', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_SYMBOL); |
44
|
|
|
$this->quickInitVar('rate', XOBJ_DTYPE_FLOAT, true, _CO_SOBJECT_CURRENCY_RATE, '', '1.0'); |
45
|
|
|
$this->quickInitVar('default_currency', XOBJ_DTYPE_INT, false, _CO_SOBJECT_CURRENCY_DEFAULT, '', false); |
46
|
|
|
|
47
|
|
|
$this->setControl('symbol', [ |
48
|
|
|
'name' => 'text', |
49
|
|
|
'size' => '15', |
50
|
|
|
'maxlength' => '15' |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
$this->setControl('iso4217', [ |
54
|
|
|
'name' => 'text', |
55
|
|
|
'size' => '5', |
56
|
|
|
'maxlength' => '5' |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
$this->setControl('rate', [ |
60
|
|
|
'name' => 'text', |
61
|
|
|
'size' => '5', |
62
|
|
|
'maxlength' => '5' |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
$this->setControl('rate', [ |
66
|
|
|
'name' => 'text', |
67
|
|
|
'size' => '5', |
68
|
|
|
'maxlength' => '5' |
69
|
|
|
]); |
70
|
|
|
|
71
|
|
|
$this->hideFieldFromForm('default_currency'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $key |
76
|
|
|
* @param string $format |
77
|
|
|
* @return mixed |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function getVar($key, $format = 's') |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
if ('s' === $format && in_array($key, ['rate', 'default_currency'])) { |
82
|
|
|
// return call_user_func(array($this, $key)); |
83
|
|
|
return $this->{$key}(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return parent::getVar($key, $format); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return mixed |
91
|
|
|
*/ |
92
|
|
|
public function getCurrencyLink() |
93
|
|
|
{ |
94
|
|
|
$ret = $this->getVar('name', 'e'); |
95
|
|
|
|
96
|
|
|
return $ret; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
|
|
public function getCode() |
103
|
|
|
{ |
104
|
|
|
$ret = $this->getVar('iso4217', 'e'); |
105
|
|
|
|
106
|
|
|
return $ret; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return float|int|mixed|string |
111
|
|
|
*/ |
112
|
|
|
public function rate() |
113
|
|
|
{ |
114
|
|
|
return Smartobject\Utility::getCurrency($this->getVar('rate', 'e')); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function defaultCurrency() |
121
|
|
|
{ |
122
|
|
|
if (true === $this->getVar('default_currency', 'e')) { |
123
|
|
|
return _YES; |
124
|
|
|
} else { |
125
|
|
|
return _NO; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
public function getDefaultCurrencyControl() |
133
|
|
|
{ |
134
|
|
|
$radio_box = '<input name="default_currency" value="' . $this->getVar('currencyid') . '" type="radio"'; |
135
|
|
|
if ($this->getVar('default_currency', 'e')) { |
136
|
|
|
$radio_box .= 'checked'; |
137
|
|
|
} |
138
|
|
|
$radio_box .= '>'; |
139
|
|
|
|
140
|
|
|
return $radio_box; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.