1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
13
|
|
|
|
14
|
|
|
namespace O2System\Framework\Models\Sql\DataObjects; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Database\DataObjects\Result\Info; |
19
|
|
|
use O2System\Framework\Libraries\Ui\Components\Pagination; |
20
|
|
|
use O2System\Framework\Models\Sql\Model; |
21
|
|
|
use O2System\Spl\Iterators\ArrayIterator; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Result |
25
|
|
|
* |
26
|
|
|
* @package O2System\Database\DataStructures |
27
|
|
|
*/ |
28
|
|
|
class Result extends ArrayIterator |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Result::$info |
32
|
|
|
* |
33
|
|
|
* @var Info |
34
|
|
|
*/ |
35
|
|
|
public $info; |
36
|
|
|
|
37
|
|
|
// ------------------------------------------------------------------------ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Result::__construct |
41
|
|
|
* |
42
|
|
|
* @param \O2System\Database\DataObjects\Result $result |
43
|
|
|
* @param \O2System\Framework\Models\Sql\Model $model |
44
|
|
|
*/ |
45
|
|
|
public function __construct(\O2System\Database\DataObjects\Result $result, Model &$model) |
46
|
|
|
{ |
47
|
|
|
if ($result->count() > 0) { |
48
|
|
|
$ormResult = new \SplFixedArray($result->count()); |
49
|
|
|
|
50
|
|
|
foreach ($result as $key => $row) { |
51
|
|
|
if (method_exists($model, 'rebuildRow')) { |
52
|
|
|
$row = $model->rebuildRow($row); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// Visible Columns |
56
|
|
|
if (count($model->visibleColumns)) { |
57
|
|
|
$columns = $row->getColumns(); |
58
|
|
|
foreach ($columns as $column) { |
59
|
|
|
if ( ! in_array($column, $model->visibleColumns)) { |
60
|
|
|
array_push($model->hideColumns, $column); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// Hide Columns |
66
|
|
|
if (count($model->hideColumns)) { |
67
|
|
|
foreach ($model->hideColumns as $column) { |
68
|
|
|
if ($row->offsetExists($column)) { |
69
|
|
|
$row->offsetUnset($column); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$ormResult[ $key ] = new Result\Row($row, $model); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
parent::__construct($ormResult->toArray()); |
78
|
|
|
|
79
|
|
|
unset($ormResult); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// ------------------------------------------------------------------------ |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Result::setInfo |
87
|
|
|
* |
88
|
|
|
* @param \O2System\Database\DataObjects\Result\Info $info |
89
|
|
|
* |
90
|
|
|
* @return static |
91
|
|
|
*/ |
92
|
|
|
public function setInfo(Info $info) |
93
|
|
|
{ |
94
|
|
|
$this->info = $info; |
95
|
|
|
|
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// ------------------------------------------------------------------------ |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Result::getInfo |
103
|
|
|
* |
104
|
|
|
* @return \O2System\Database\DataObjects\Result\Info |
105
|
|
|
*/ |
106
|
|
|
public function getInfo() |
107
|
|
|
{ |
108
|
|
|
return $this->info; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
// ------------------------------------------------------------------------ |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Result::pagination |
115
|
|
|
* |
116
|
|
|
* @return \O2System\Framework\Libraries\Ui\Components\Pagination |
117
|
|
|
*/ |
118
|
|
|
public function pagination() |
119
|
|
|
{ |
120
|
|
|
$rows = $this->info->getTotal()->rows; |
121
|
|
|
$rows = empty($rows) ? 0 : $rows; |
122
|
|
|
|
123
|
|
|
$limit = input()->get('limit'); |
124
|
|
|
$limit = empty($limit) ? $this->info->limit : $limit; |
125
|
|
|
|
126
|
|
|
return new Pagination($rows, $limit); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
} |