1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* PayPal Donation extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2018 Skouat |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace skouat\ppde\actions; |
12
|
|
|
|
13
|
|
|
use phpbb\template\template; |
14
|
|
|
|
15
|
|
|
class currency |
16
|
|
|
{ |
17
|
|
|
protected $entity; |
18
|
|
|
protected $locale; |
19
|
|
|
protected $operator; |
20
|
|
|
protected $template; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* currency constructor. |
24
|
|
|
* |
25
|
|
|
* @param \skouat\ppde\entity\currency $entity Currency entity object |
26
|
|
|
* @param \skouat\ppde\actions\locale_icu $locale PPDE Locale object |
27
|
|
|
* @param \skouat\ppde\operators\currency $operator Currency operator object |
28
|
|
|
* @param template $template Template object |
29
|
|
|
* |
30
|
|
|
* @access public |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
public function __construct(\skouat\ppde\entity\currency $entity, locale_icu $locale, \skouat\ppde\operators\currency $operator, template $template) |
34
|
|
|
{ |
35
|
|
|
$this->entity = $entity; |
36
|
|
|
$this->locale = $locale; |
37
|
|
|
$this->operator = $operator; |
38
|
|
|
$this->template = $template; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get currency data based on currency ISO code |
43
|
|
|
* |
44
|
|
|
* @param string $iso_code |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
* @access public |
48
|
|
|
*/ |
49
|
|
|
public function get_currency_data($iso_code) |
50
|
|
|
{ |
51
|
|
|
$this->entity->data_exists($this->entity->build_sql_data_exists($iso_code)); |
52
|
|
|
|
53
|
|
|
return $this->get_default_currency_data($this->entity->get_id()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get default currency symbol |
58
|
|
|
* |
59
|
|
|
* @param int $id Currency identifier; default: 0 |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
* @access public |
63
|
|
|
*/ |
64
|
|
|
public function get_default_currency_data($id = 0) |
65
|
|
|
{ |
66
|
|
|
return $this->entity->get_data($this->operator->build_sql_data($id, true)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Format currency value, based on the PHP intl extension. |
71
|
|
|
* If this PHP Extension is not available, we switch on a basic currency formatter. |
72
|
|
|
* |
73
|
|
|
* @param int|float $value |
74
|
|
|
* @param string $currency_iso_code |
75
|
|
|
* @param string $currency_symbol |
76
|
|
|
* @param bool $on_left |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
* @access public |
80
|
|
|
*/ |
81
|
|
|
public function format_currency($value, $currency_iso_code, $currency_symbol, $on_left = true) |
82
|
|
|
{ |
83
|
|
|
if ($this->locale->is_locale_configured()) |
84
|
|
|
{ |
85
|
|
|
return $this->locale->numfmt_format_currency($this->locale->numfmt_create(), $value, $currency_iso_code); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $this->currency_on_left($value, $currency_symbol, $on_left); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Put the currency on the left or on the right of the amount |
93
|
|
|
* |
94
|
|
|
* @param int|float $value |
95
|
|
|
* @param string $currency_symbol |
96
|
|
|
* @param bool $on_left |
97
|
|
|
* @param string $dec_point |
98
|
|
|
* @param string $thousands_sep |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
* @access public |
102
|
|
|
* @deprecated 2.2.0 (To be removed: 3.0.0) |
103
|
|
|
* |
104
|
|
|
*/ |
105
|
|
|
public function currency_on_left($value, $currency_symbol, $on_left = true, $dec_point = '.', $thousands_sep = '') |
106
|
|
|
{ |
107
|
|
|
if ($on_left) |
108
|
|
|
{ |
109
|
|
|
return $currency_symbol . number_format(round($value, 2), 2, $dec_point, $thousands_sep); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return number_format(round($value, 2), 2, $dec_point, $thousands_sep) . $currency_symbol; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Build pull down menu options of available currency |
117
|
|
|
* |
118
|
|
|
* @param int $config_value Currency identifier; default: 0 |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
* @access public |
122
|
|
|
*/ |
123
|
|
|
public function build_currency_select_menu($config_value = 0) |
124
|
|
|
{ |
125
|
|
|
// Grab the list of all enabled currencies; 0 is for all data |
126
|
|
|
$currency_items = $this->entity->get_data($this->operator->build_sql_data(0, true)); |
127
|
|
|
|
128
|
|
|
// Process each rule menu item for pull-down |
129
|
|
|
foreach ($currency_items as $currency_item) |
130
|
|
|
{ |
131
|
|
|
// Set output block vars for display in the template |
132
|
|
|
$this->template->assign_block_vars('options', array( |
133
|
|
|
'CURRENCY_ID' => (int) $currency_item['currency_id'], |
134
|
|
|
'CURRENCY_ISO_CODE' => $currency_item['currency_iso_code'], |
135
|
|
|
'CURRENCY_NAME' => $currency_item['currency_name'], |
136
|
|
|
'CURRENCY_SYMBOL' => $currency_item['currency_symbol'], |
137
|
|
|
'S_CURRENCY_DEFAULT' => $config_value == $currency_item['currency_id'], |
138
|
|
|
)); |
139
|
|
|
} |
140
|
|
|
unset ($currency_items, $currency_item); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.