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\Result; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Database; |
19
|
|
|
use O2System\Framework\Models\Sql\Model; |
20
|
|
|
use O2System\Spl\DataStructures\SplArrayObject; |
21
|
|
|
use O2System\Spl\Info\SplClassInfo; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Row |
25
|
|
|
* |
26
|
|
|
* @package O2System\Framework\Models\Sql\DataObjects |
27
|
|
|
*/ |
28
|
|
|
class Row extends SplArrayObject |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Row::$model |
32
|
|
|
* |
33
|
|
|
* @var \O2System\Spl\Info\SplClassInfo |
34
|
|
|
*/ |
35
|
|
|
private $model; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Row::$record |
39
|
|
|
* |
40
|
|
|
* @var \O2System\Database\DataObjects\Result\Row\Record |
|
|
|
|
41
|
|
|
*/ |
42
|
|
|
private $record; |
43
|
|
|
|
44
|
|
|
// ------------------------------------------------------------------------ |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Row::__construct |
48
|
|
|
* |
49
|
|
|
* @param mixed $row |
50
|
|
|
* @param Model $model |
51
|
|
|
*/ |
52
|
|
|
public function __construct($row, Model &$model) |
53
|
|
|
{ |
54
|
|
|
$this->model = new SplClassInfo($model); |
55
|
|
|
$this->record = $row->getRecord(); |
56
|
|
|
|
57
|
|
|
if ( ! models()->has($this->model->getClass())) { |
|
|
|
|
58
|
|
|
models()->add($model, $this->model->getClass()); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($row instanceof Database\DataObjects\Result\Row) { |
62
|
|
|
parent::__construct($row->getArrayCopy()); |
63
|
|
|
} elseif (is_array($row)) { |
64
|
|
|
parent::__construct($row); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// Append Columns |
68
|
|
|
if (count($model->appendColumns)) { |
69
|
|
|
foreach ($model->appendColumns as $appendColumn) { |
70
|
|
|
$this->offsetSet($appendColumn, $this->offsetGet($appendColumn)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
models($this->model->getClass())->row = $this; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// ------------------------------------------------------------------------ |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Row::offsetGet |
81
|
|
|
* |
82
|
|
|
* @param string $offset |
83
|
|
|
* |
84
|
|
|
* @return mixed |
85
|
|
|
*/ |
86
|
|
|
public function offsetGet($offset) |
87
|
|
|
{ |
88
|
|
|
if ($this->offsetExists($offset)) { |
89
|
|
|
return parent::offsetGet($offset); |
90
|
|
|
} elseif(strpos($offset, 'record') !== false) { |
91
|
|
|
switch ($offset) { |
92
|
|
|
case 'record': |
93
|
|
|
return $this->record; |
94
|
|
|
break; |
|
|
|
|
95
|
|
|
case 'record_status': |
96
|
|
|
return $this->record->status; |
97
|
|
|
break; |
98
|
|
|
case 'record_left': |
99
|
|
|
return $this->record->left; |
100
|
|
|
break; |
101
|
|
|
case 'record_right': |
102
|
|
|
return $this->record->right; |
103
|
|
|
break; |
104
|
|
|
case 'record_depth': |
105
|
|
|
return $this->record->depth; |
106
|
|
|
break; |
107
|
|
|
case 'record_ordering': |
108
|
|
|
return $this->record->ordering; |
109
|
|
|
break; |
110
|
|
|
case 'record_create_user': |
111
|
|
|
return $this->record->create->user; |
112
|
|
|
break; |
113
|
|
|
case 'record_create_timestamp': |
114
|
|
|
return $this->record->create->timestamp; |
115
|
|
|
break; |
116
|
|
|
case 'record_update_user': |
117
|
|
|
return $this->record->update->user; |
118
|
|
|
break; |
119
|
|
|
case 'record_update_timestamp': |
120
|
|
|
return $this->record->update->timestamp; |
121
|
|
|
break; |
122
|
|
|
} |
123
|
|
|
} elseif (null !== ($result = $this->__call($offset))) { |
124
|
|
|
return $result; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return null; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
// ------------------------------------------------------------------------ |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Row::__call |
134
|
|
|
* |
135
|
|
|
* @param string $method |
136
|
|
|
* @param array $args |
137
|
|
|
* |
138
|
|
|
* @return bool|\O2System\Framework\Models\Sql\DataObjects\Result|\O2System\Framework\Models\Sql\DataObjects\Result\Row|null |
139
|
|
|
*/ |
140
|
|
|
public function __call($method, $args = []) |
141
|
|
|
{ |
142
|
|
|
$model = models($this->model->getClass()); |
143
|
|
|
|
144
|
|
|
if (method_exists($model, $method)) { |
145
|
|
|
$model->row = $this; |
|
|
|
|
146
|
|
|
|
147
|
|
|
if (false !== ($result = call_user_func_array([&$model, $method], $args))) { |
148
|
|
|
$this->offsetSet($method, $result); |
149
|
|
|
|
150
|
|
|
return $result; |
151
|
|
|
} |
152
|
|
|
} elseif (strpos($method, 'Url')) { |
153
|
|
|
$key = str_replace('Url', '', $method); |
154
|
|
|
|
155
|
|
|
if ($key === $model->uploadedImageKey) { |
|
|
|
|
156
|
|
|
if (isset($model->uploadedImageFilePath)) { |
|
|
|
|
157
|
|
|
if (is_file($filePath = $model->uploadedImageFilePath . $this->offsetGet($key))) { |
158
|
|
|
return images_url($filePath); |
159
|
|
|
} elseif (is_file($filePath = PATH_STORAGE . 'images/default/not-found.jpg')) { |
160
|
|
|
return images_url($filePath); |
161
|
|
|
} elseif (is_file($filePath = PATH_STORAGE . 'images/default/not-found.png')) { |
162
|
|
|
return images_url($filePath); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
} elseif (in_array($key, $model->uploadedImageKeys)) { |
|
|
|
|
166
|
|
|
if (isset($model->uploadedImageFilePath)) { |
167
|
|
|
if (is_file($filePath = $model->uploadedImageFilePath . $this->offsetGet($key))) { |
168
|
|
|
return images_url($filePath); |
169
|
|
|
} elseif (is_file($filePath = PATH_STORAGE . 'images/default/not-found.jpg')) { |
170
|
|
|
return images_url($filePath); |
171
|
|
|
} elseif (is_file($filePath = PATH_STORAGE . 'images/default/not-found.png')) { |
172
|
|
|
return images_url($filePath); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
} elseif ($key === $model->uploadedFileKey) { |
|
|
|
|
176
|
|
|
if (isset($model->uploadedFileFilepath)) { |
|
|
|
|
177
|
|
|
return storage_url($model->uploadedFileFilepath . $this->offsetGet($key)); |
178
|
|
|
} |
179
|
|
|
} elseif (in_array($key, $model->uploadedFileKeys)) { |
|
|
|
|
180
|
|
|
if (isset($model->uploadedFileFilepath)) { |
181
|
|
|
return storage_url($model->uploadedFileFilepath . $this->offsetGet($key)); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
return null; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
// ------------------------------------------------------------------------ |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Row::delete |
193
|
|
|
* |
194
|
|
|
* @return bool |
195
|
|
|
* @throws \O2System\Spl\Exceptions\RuntimeException |
196
|
|
|
* @throws \Psr\Cache\InvalidArgumentException |
197
|
|
|
*/ |
198
|
|
|
public function delete() |
199
|
|
|
{ |
200
|
|
|
$model = models($this->model->getClass()); |
201
|
|
|
|
202
|
|
|
$primaryKey = isset($model->primaryKey) ? $model->primaryKey : 'id'; |
|
|
|
|
203
|
|
|
$id = $this->offsetGet($primaryKey); |
204
|
|
|
|
205
|
|
|
if (method_exists($model, 'beforeDelete')) { |
206
|
|
|
$model->beforeDelete(); |
|
|
|
|
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
if ($model->qb->table($model->table)->limit(1)->delete([$primaryKey => $id])) { |
|
|
|
|
210
|
|
|
if (method_exists($model, 'afterDelete')) { |
211
|
|
|
return $model->afterDelete(); |
|
|
|
|
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
return true; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
return false; |
218
|
|
|
} |
219
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths