forked from eturino/Data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRowset.php
131 lines (112 loc) · 2.79 KB
/
Rowset.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
class EtuDev_Data_Rowset extends Zend_Db_Table_Rowset
{
protected $firstKey;
protected $endKey;
public function __construct(array $config)
{
parent::__construct($config);
$this->refreshKeys();
}
/**
* @return array
*/
public function toArrayOfRows()
{
if (count($this->_rows) != count($this->_data)) {
$a = array();
foreach ($this as $r) {
$a[] = $r;
}
return $a;
}
return $this->_rows;
}
public function firstRow()
{
if ($this->_data) {
return $this->getRow($this->firstKey);
}
return null;
}
public function endRow()
{
if ($this->_data) {
return $this->getRow($this->endKey);
}
return null;
}
protected $total;
public function getTotal()
{
if (is_null($this->total)) {
$table = $this->getTable();
if ($table instanceof EtuDev_Data_Table) {
$this->total = $table->getFoundRows();
}
}
return $this->total;
}
/**
* @param mixed $total
*
* @return EtuDev_Data_Rowset
*/
public function setTotal($total)
{
$this->total = $total;
return $this;
}
/**
* @param array|Zend_Db_Table_Rowset $list_rows
*/
public function appendRows($list_rows)
{
foreach ($list_rows as $v) {
if (is_array($v)) {
$this->doAppendRowData($v);
} elseif ($v instanceof Zend_Db_Table_Row_Abstract) {
$this->doAppendRowData($v->toArray());
}
}
$this->refreshKeys();
$this->refreshCount();
$this->refreshRows();
}
public function appendRow(Zend_Db_Table_Row $data)
{
$this->doAppendRowData($data->toArray());
$this->refreshKeys();
$this->refreshCount();
$this->refreshRows();
}
public function appendRowData(array $data)
{
$this->doAppendRowData($data);
$this->refreshKeys();
$this->refreshCount();
$this->refreshRows();
}
protected function doAppendRowData(array $data)
{
$this->_data[] = $data;
}
protected function refreshCount()
{
$this->_count = count($this->_data);
}
protected function refreshRows()
{
if (count($this->_rows) != count($this->_data)) {
return $this->setTable($this->_table);
}
return $this->_connected;
}
protected function refreshKeys()
{
if ($this->_data) {
$this->firstKey = key(array_slice($this->_data, 0, 1, true));
$this->endKey = key(array_slice($this->_data, -1, 1, true));
}
}
}