-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIReportProvider.php
88 lines (69 loc) · 2.33 KB
/
IReportProvider.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
class IReportProvider {
protected $data = array();
public function getData() {
return $this->data;
}
public function execute($IReportParserXML) {
}
}
class IReportProviderDB extends IReportProvider {
private $connection;
public function __construct($connection) {
$this->connection = $connection;
}
private function buildsql($IReportParserXML) {
$sql = $IReportParserXML->sql;
if (isset($IReportParserXML->parameters)) {
foreach ($IReportParserXML->parameters as $v => $a) {
$sql = str_replace('$P{' . $v . '}', $a, $sql);
}
}
return $sql;
}
public function execute($IReportParserXML) {
$this->m = 0;
$command = $this->connection->createCommand($this->buildsql($IReportParserXML));
$reader = $command->query();
foreach ($reader as $row) {
foreach ($IReportParserXML->fields as $out) {
$this->data[$this->m]["$out"] = $row["$out"];
}
$this->m++;
}
}
}
class IReportProviderFileXml extends IReportProvider {
private $fileName;
public function __construct($fileName) {
$this->fileName = $fileName;
}
public function execute($IReportParserXML) {
if (!file_exists($fileName))
echo "File - $fileName does not exist";
else {
$this->m = 0;
$xmlAry = $this->xmlobj2arr(simplexml_load_file($fileName));
foreach ($xmlAry[header] as $key => $value)
$this->data["$this->m"]["$key"] = $value;
foreach ($xmlAry[detail][record]["$this->m"] as $key2 => $value2)
$this->data["$this->m"]["$key2"] = $value2;
}
// if (isset($this->arrayVariable)) //if self define variable existing, go to do the calculation
// $this->variable_calculation($m);
}
private function xmlobj2arr($Data) {
if (is_object($Data)) {
foreach (get_object_vars($Data) as $key => $val)
$ret[$key] = $this->xmlobj2arr($val);
return $ret;
} elseif (is_array($Data)) {
foreach ($Data as $key => $val)
$ret[$key] = $this->xmlobj2arr($val);
return $ret;
}
else
return $Data;
}
}
?>