1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* /classes/DomainMOD/Currency.php |
4
|
|
|
* |
5
|
|
|
* This file is part of DomainMOD, an open source domain and internet asset manager. |
6
|
|
|
* Copyright (c) 2010-2018 Greg Chetcuti <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Project: http://domainmod.org Author: http://chetcuti.com |
9
|
|
|
* |
10
|
|
|
* DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public |
11
|
|
|
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later |
12
|
|
|
* version. |
13
|
|
|
* |
14
|
|
|
* DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
15
|
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License along with DomainMOD. If not, see |
18
|
|
|
* http://www.gnu.org/licenses/. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
//@formatter:off |
22
|
|
|
namespace DomainMOD; |
23
|
|
|
|
24
|
|
|
class Currency |
25
|
|
|
{ |
26
|
|
|
public $deeb; |
27
|
|
|
public $log; |
28
|
|
|
|
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
$this->deeb = Database::getInstance(); |
32
|
|
|
$this->log = new Log('class.currency'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function format($amount, $symbol, $order, $space) |
36
|
|
|
{ |
37
|
|
|
if ($order == "1" && $space == "1") { |
38
|
|
|
$formatted_output = number_format($amount, 2, '.', ',') . " " . $symbol; |
39
|
|
|
} elseif ($order == "1" && $space == "0") { |
40
|
|
|
$formatted_output = number_format($amount, 2, '.', ',') . $symbol; |
41
|
|
|
} elseif ($order == "0" && $space == "1") { |
42
|
|
|
$formatted_output = $symbol . " " . number_format($amount, 2, '.', ','); |
43
|
|
|
} else { |
44
|
|
|
$formatted_output = $symbol . number_format($amount, 2, '.', ','); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $formatted_output; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getCurrencyId($currency) |
51
|
|
|
{ |
52
|
|
|
$pdo = $this->deeb->cnxx; |
53
|
|
|
|
54
|
|
|
$stmt = $pdo->prepare(" |
55
|
|
|
SELECT id |
56
|
|
|
FROM currencies |
57
|
|
|
WHERE currency = :currency"); |
58
|
|
|
$stmt->bindValue('currency', $currency, \PDO::PARAM_STR); |
59
|
|
|
$stmt->execute(); |
60
|
|
|
$result = $stmt->fetchColumn(); |
61
|
|
|
|
62
|
|
|
if (!$result) { |
63
|
|
|
|
64
|
|
|
$log_message = 'Unable to retrieve Currency ID'; |
65
|
|
|
$log_extra = array('Currency' => $currency); |
66
|
|
|
$this->log->critical($log_message, $log_extra); |
67
|
|
|
return $log_message; |
68
|
|
|
|
69
|
|
|
} else { |
70
|
|
|
|
71
|
|
|
return $result; |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getCurrencyInfo($currency) |
78
|
|
|
{ |
79
|
|
|
$pdo = $this->deeb->cnxx; |
80
|
|
|
|
81
|
|
|
$stmt = $pdo->prepare(" |
82
|
|
|
SELECT `name`, symbol, symbol_order, symbol_space |
83
|
|
|
FROM currencies |
84
|
|
|
WHERE currency = :currency"); |
85
|
|
|
$stmt->bindValue('currency', $currency, \PDO::PARAM_STR); |
86
|
|
|
$stmt->execute(); |
87
|
|
|
$result = $stmt->fetch(); |
88
|
|
|
|
89
|
|
|
return array($result->name, $result->symbol, $result->symbol_order, $result->symbol_space); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} //@formatter:on |
93
|
|
|
|