1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use CMSFactory\DummyModule; |
4
|
|
|
use Currency\Currency; |
5
|
|
|
use shop\classes\Money\EmmetMoneyFormatter; |
6
|
|
|
|
7
|
|
|
if (!function_exists('module')) { |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Module loader |
11
|
|
|
* |
12
|
|
|
* @param string $moduleName |
13
|
|
|
* @return DummyModule |
14
|
|
|
*/ |
15
|
|
|
function module($moduleName) { |
16
|
|
|
$module = CI::$APP->load->module($moduleName); |
17
|
|
|
return $module ? : new DummyModule($moduleName); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
if (!function_exists('view')) { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Returns or show template with only local variables visibility |
26
|
|
|
* Add new vars but not replace origin template data |
27
|
|
|
* |
28
|
|
|
* @param string $fileName |
29
|
|
|
* @param array $data |
30
|
|
|
* @return mixed |
31
|
|
|
*/ |
32
|
|
|
function view($fileName, array $data = []) { |
33
|
|
|
$definedVars = CI::$APP->template->get_vars(); |
34
|
|
|
return CI::$APP->template->view($fileName, array_replace($definedVars, $data)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if (!function_exists('get_value')) { |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Returns old field value from session flash data |
43
|
|
|
* @param $fieldName |
|
|
|
|
44
|
|
|
* @param string $default |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
function get_value($fieldName, $default = '') { |
48
|
|
|
if (set_value($fieldName)) { |
49
|
|
|
return set_value($fieldName); |
50
|
|
|
} |
51
|
|
|
$values = CI::$APP->session->flashdata('_field_data'); |
52
|
|
|
$value = $default; |
53
|
|
|
if (isset($values[$fieldName]) && isset($values[$fieldName]['postdata'])) { |
54
|
|
|
$value = is_array($values[$fieldName]['postdata']) ? array_shift($values[$fieldName]['postdata']) : $values[$fieldName]['postdata']; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $value; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (!function_exists('get_error')) { |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns field error from session flash data |
66
|
|
|
* @param $fieldName |
|
|
|
|
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
|
|
function get_error($fieldName) { |
70
|
|
|
if (form_error($fieldName)) { |
71
|
|
|
return form_error($fieldName); |
72
|
|
|
} |
73
|
|
|
$error = false; |
74
|
|
|
$errors = CI::$APP->session->flashdata('_error_array'); |
75
|
|
|
if (isset($errors[$fieldName]) && $errors[$fieldName]) { |
76
|
|
|
$error = $errors[$fieldName]; |
77
|
|
|
} |
78
|
|
|
return $error; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (!function_exists('get_errors')) { |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Return form errors as string |
87
|
|
|
* |
88
|
|
|
* @param string $prefix |
89
|
|
|
* @param string $suffix |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
function get_errors($prefix = '', $suffix = '') { |
93
|
|
|
if (validation_errors()) { |
94
|
|
|
return validation_errors($prefix = '', $suffix = ''); |
95
|
|
|
} |
96
|
|
|
$errors = CI::$APP->session->flashdata('_error_array'); |
97
|
|
|
$str = ''; |
98
|
|
|
foreach ($errors as $val) { |
99
|
|
|
if ($val != '') { |
100
|
|
|
$str .= $prefix . $val . $suffix . "\n"; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
return $str; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Template Formatters |
110
|
|
|
* All formatters use Emmet format to render price |
111
|
|
|
* |
112
|
|
|
*/ |
|
|
|
|
113
|
|
|
|
114
|
|
|
if (!function_exists('emmet_money')) { |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Format money wrapped by rendered tags from emmet string |
118
|
|
|
* and formatted according to currency format |
119
|
|
|
* |
120
|
|
|
* @param $price |
|
|
|
|
121
|
|
|
* @param string|null $priceWrapper |
122
|
|
|
* @param string|null $coinsWrapper |
123
|
|
|
* @param string|null $symbolWrapper |
124
|
|
|
* @param null|SCurrencies $currency |
125
|
|
|
* @return EmmetMoneyFormatter |
126
|
|
|
*/ |
127
|
|
|
function emmet_money($price, $priceWrapper = null, $coinsWrapper = null, $symbolWrapper = null, $currency = null) { |
128
|
|
|
$currency = $currency ?: Currency::create()->getMainCurrency(); |
129
|
|
|
$formatter = new EmmetMoneyFormatter($price, $currency); |
130
|
|
|
$formatter->setWrappers($priceWrapper, $coinsWrapper, $symbolWrapper); |
131
|
|
|
return $formatter; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
if (!function_exists('emmet_money_additional')) { |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* |
140
|
|
|
* Array of prices converted to all currencies available on site(with column showOnSite == 1) |
141
|
|
|
* formatted according to each currency format |
142
|
|
|
* |
143
|
|
|
* @param $price |
|
|
|
|
144
|
|
|
* @param integer|float $priceWrapper |
145
|
|
|
* @param string|null $coinsWrapper |
146
|
|
|
* @param string|null $symbolWrapper |
147
|
|
|
* @return array |
148
|
|
|
* @internal param $moduleName |
149
|
|
|
*/ |
150
|
|
|
function emmet_money_additional($price, $priceWrapper = null, $coinsWrapper = null, $symbolWrapper = null) { |
151
|
|
|
$formatters = []; |
152
|
|
|
foreach (Currency::create()->getOnSiteCurrencies() as $currency) { |
153
|
|
|
$convertedPrice = $price * $currency->getRate(); |
154
|
|
|
array_push($formatters, emmet_money($convertedPrice, $priceWrapper, $coinsWrapper, $symbolWrapper, $currency)); |
155
|
|
|
} |
156
|
|
|
return $formatters; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
if (!function_exists('flashdata')) { |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Session flashdata |
166
|
|
|
* |
167
|
|
|
* @param string $key |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
function flashdata($key) { |
171
|
|
|
return CI::$APP->session->flashdata($key); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
} |