-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataView.php
65 lines (59 loc) · 1.97 KB
/
DataView.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
<?php
// Lucas Tiago de Moraes
// include class DHX
include_once 'DHX.php';
// class DataView
class DataView extends DHX {
private $document; // ref document
private $data; // ref data
public $pos; // set pos
public $total_count; // set total_count
// auto construct
function __construct($value = ''){
if($value){
$this->encoding($value);
}
$this->document = $this->document();
$this->data = $this->document->appendChild(new DOMElement('data'));
}
// public item
public function item(){
$data = func_get_args();
foreach($data as $row){
$item = $this->data->appendChild(new DOMElement('item'));
foreach($row as $key => $value){
if($key == 'id'){
$item->setAttributeNode(new DOMAttr($key, $value));
}else{
$k = $item->appendChild(new DOMElement($key));
$k->appendChild(new DOMCdataSection($value));
}
}
}
}
// public file
public function file(){
$data = func_get_args();
foreach($data as $row){
$item = $this->data->appendChild(new DOMElement('item'));
foreach($row as $key => $value){
if($key == 'filesize' || $key == 'modifdate'){
$k = $item->appendChild(new DOMElement($key));
$k->appendChild($this->document->createTextNode($value));
}else{
$item->setAttributeNode(new DOMAttr($key, $value));
}
}
}
}
// public result
public function result(){
if($this->pos){
$this->data->setAttributeNode(new DOMAttr('pos', $this->pos));
}
if($this->total_count){
$this->data->setAttributeNode(new DOMAttr('total_count', $this->total_count));
}
return $this->document->saveXML();
}
}