-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageGenerator.php
55 lines (49 loc) · 1.74 KB
/
MessageGenerator.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
<?php
require_once ('libs/log4php/Logger.php');
Logger::configure ( 'logs/config.xml' );
class MessageGenerator {
private $rates;
private $log;
public function MessageGenerator($rates) {
$this->rates = $rates;
}
public function getMessage($messageType) {
switch ($messageType) {
case 'G' :
return 'G=' . (isset ( $this->rates ['Gold'] ) ? $this->rates ['Gold'] : 'n/a');
break;
case 'S' :
return 'S=' . (isset ( $this->rates ['Silver'] ) ? $this->rates ['Silver'] : 'n/a');
break;
case 'D' :
return '$=' . (isset ( $this->rates ['Dollar'] ) ? $this->rates ['Dollar'] : 'n/a');
break;
case 'GS' :
return 'G=' . (isset ( $this->rates ['Gold'] ) ? $this->rates ['Gold'] : 'n/a') . '\n' .
'S=' . (isset ( $this->rates ['Silver'] ) ? $this->rates ['Silver'] : 'n/a');
break;
case 'GSD' :
return 'G=' . (isset ( $this->rates ['Gold'] ) ? $this->rates ['Gold'] : 'n/a') . '\n'
. 'S=' . (isset ( $this->rates ['Silver'] ) ? $this->rates ['Silver'] : 'n/a') . '\n'
. '$=' . (isset ( $this->rates ['Dollar'] ) ? $this->rates ['Dollar'] : 'n/a') . '\n'
. 'Time: ' . date('H:i');
break;
case 'GSDLocal' :
return 'G: ' . (isset( $this->rates ['Gold'] ) ? $this->calculateLocalRates($this->rates ['Gold']) : 'n/a') . '\n'
. 'S: ' . (isset ( $this->rates ['Silver'] ) ? $this->calculateLocalRates($this->rates ['Silver']) : 'n/a') . '\n'
. '$: ' . (isset ( $this->rates ['Dollar'] ) ? $this->rates ['Dollar'] : 'n/a') . '\n'
. 'Time: ' . date('H:i');
break;
}
}
private function calculateLocalRates($rate)
{
if(isset( $this->rates ['Dollar']))
{
return round(($rate * $this->rates ['Dollar'] * 0.375006308),0);
}
else
return 'n/a';
}
}
?>