|
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\Info\SplClassInfo; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class Result |
|
25
|
|
|
* |
|
26
|
|
|
* @package O2System\Database\DataStructures |
|
27
|
|
|
*/ |
|
28
|
|
|
class Result extends \O2System\Database\DataObjects\Result |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Result::$model |
|
32
|
|
|
* |
|
33
|
|
|
* @var Model |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $model; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Result::$info |
|
39
|
|
|
* |
|
40
|
|
|
* @var Info |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $info; |
|
43
|
|
|
|
|
44
|
|
|
// ------------------------------------------------------------------------ |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Result::__construct |
|
48
|
|
|
* |
|
49
|
|
|
* @param \O2System\Database\DataObjects\Result $result |
|
50
|
|
|
* @param \O2System\Framework\Models\Sql\Model $model |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct(\O2System\Database\DataObjects\Result $result, Model &$model) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->model = new SplClassInfo($model); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
if ( ! models()->has($this->model->getClass())) { |
|
|
|
|
|
|
57
|
|
|
models()->add($model, $this->model->getClass()); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$this->info = $result->getInfo(); |
|
61
|
|
|
parent::__construct($result->toArray()); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// ------------------------------------------------------------------------ |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Result::offsetSet |
|
68
|
|
|
* |
|
69
|
|
|
* @param mixed $offset |
|
70
|
|
|
* @param mixed $row |
|
71
|
|
|
*/ |
|
72
|
|
|
public function offsetSet($offset, $row) |
|
73
|
|
|
{ |
|
74
|
|
|
$model = models($this->model->getClass()); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
if (method_exists($model, 'rebuildRow')) { |
|
77
|
|
|
$row = $model->rebuildRow($row); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$hideColumns = []; |
|
81
|
|
|
|
|
82
|
|
|
// Visible Columns |
|
83
|
|
|
if (count($model->visibleColumns)) { |
|
|
|
|
|
|
84
|
|
|
$hideColumns = array_diff($row->getColumns(), $model->visibleColumns); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// Hide Columns |
|
88
|
|
|
if (count($model->hideColumns)) { |
|
|
|
|
|
|
89
|
|
|
$hideColumns = array_merge($model->hideColumns); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
// Unset Columns |
|
93
|
|
|
foreach ($hideColumns as $column) { |
|
94
|
|
|
$row->offsetUnset($column); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
parent::offsetSet($offset, new Result\Row($row, $model)); |
|
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
// ------------------------------------------------------------------------ |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Result::pagination |
|
104
|
|
|
* |
|
105
|
|
|
* @return \O2System\Framework\Libraries\Ui\Components\Pagination |
|
106
|
|
|
*/ |
|
107
|
|
|
public function pagination() |
|
108
|
|
|
{ |
|
109
|
|
|
$rows = $this->info->num_rows; |
|
|
|
|
|
|
110
|
|
|
$rows = empty($rows) ? 0 : $rows; |
|
111
|
|
|
|
|
112
|
|
|
$limit = input()->get('limit'); |
|
113
|
|
|
$limit = empty($limit) ? $this->info->limit : $limit; |
|
114
|
|
|
|
|
115
|
|
|
return new Pagination($rows, $limit); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..