|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CodexShaper\DBM\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use CodexShaper\DBM\Database\Drivers\MongoDB\Type; |
|
6
|
|
|
use CodexShaper\DBM\Database\Schema\Table; |
|
7
|
|
|
use CodexShaper\DBM\Facades\Driver; |
|
8
|
|
|
use CodexShaper\DBM\Traits\RecordHelper; |
|
9
|
|
|
use DBM; |
|
|
|
|
|
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
use Illuminate\Support\Str; |
|
12
|
|
|
|
|
13
|
|
|
class RecordController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
use RecordHelper; |
|
16
|
|
|
|
|
17
|
|
|
public function index() |
|
18
|
|
|
{ |
|
19
|
|
|
return view('dbm::app'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function store(Request $request) |
|
23
|
|
|
{ |
|
24
|
|
|
if ($request->ajax()) { |
|
25
|
|
|
|
|
26
|
|
|
if (($response = DBM::authorize('record.create')) !== true) { |
|
27
|
|
|
return $response; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$tableName = $request->table; |
|
31
|
|
|
$originalColumns = Table::getColumnsName($tableName); |
|
32
|
|
|
$columns = json_decode($request->columns); |
|
33
|
|
|
$fields = json_decode($request->fields); |
|
34
|
|
|
|
|
35
|
|
|
// return response()->json(['columns' => $columns]); |
|
36
|
|
|
|
|
37
|
|
|
$errors = $this->validation($fields, $columns); |
|
38
|
|
|
|
|
39
|
|
|
if (count($errors) > 0) { |
|
40
|
|
|
return $this->generateError($errors); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$object = DBM::Object()->where('name', $tableName)->first(); |
|
44
|
|
|
$model = $object->model; |
|
45
|
|
|
|
|
46
|
|
|
if (!class_exists($model)) { |
|
47
|
|
|
return $this->generateError(["Model not found. Please create model first"]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
try { |
|
51
|
|
|
|
|
52
|
|
|
$table = DBM::model($model, $tableName); |
|
53
|
|
|
|
|
54
|
|
|
foreach ($columns as $column => $value) { |
|
55
|
|
|
// $column = $field->name; |
|
56
|
|
|
// $value = $request->{$column}; |
|
57
|
|
|
if (in_array($column, $originalColumns)) { |
|
58
|
|
|
|
|
59
|
|
|
if ($request->hasFile($column)) { |
|
60
|
|
|
$files = $request->file($column); |
|
61
|
|
|
$values = []; |
|
62
|
|
|
foreach ($files as $file) { |
|
63
|
|
|
$fileName = Str::random(config('dbm.filesystem.random_length')) . '.' . $file->getClientOriginalExtension(); |
|
64
|
|
|
$path = 'public/dbm/' . $tableName; |
|
65
|
|
|
$file->storeAs($path, $fileName); |
|
66
|
|
|
$values[] = $fileName; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// $value = json_encode($values); |
|
70
|
|
|
|
|
71
|
|
|
if (count($values) > 1) { |
|
72
|
|
|
$value = $values; |
|
73
|
|
|
if (!Driver::isMongoDB()) { |
|
74
|
|
|
$value = is_array($values) ? json_encode($values) : $values; |
|
75
|
|
|
} |
|
76
|
|
|
} else if (count($values) == 1) { |
|
77
|
|
|
$value = $values[0]; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if (!Driver::isMongoDB()) { |
|
82
|
|
|
if ($functionName = $this->hasFunction($fields, $column)) { |
|
83
|
|
|
$value = $this->executeFunction($functionName, $value); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// if ($value != "" || !empty($value)) { |
|
88
|
|
|
|
|
89
|
|
|
$table->{$column} = is_array($value) ? json_encode($value) : $value; |
|
90
|
|
|
|
|
91
|
|
|
if (Driver::isMongoDB()) { |
|
92
|
|
|
|
|
93
|
|
|
$fieldType = $this->getFieldType($tableName, $column); |
|
94
|
|
|
|
|
95
|
|
|
if (!in_array($fieldType, Type::getTypes())) { |
|
96
|
|
|
$this->generateError([$fieldType . " type not supported."]); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$table->{$column} = Type::$fieldType($value); |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
// } |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if ($table->save()) { |
|
108
|
|
|
|
|
109
|
|
|
foreach ($fields as $field) { |
|
110
|
|
|
|
|
111
|
|
|
if (isset($field->relationship) && $field->relationship->relationType == "belongsToMany") { |
|
112
|
|
|
|
|
113
|
|
|
$relationship = $field->relationship; |
|
114
|
|
|
|
|
115
|
|
|
$localModel = $relationship->localModel; |
|
116
|
|
|
$localTable = $relationship->localTable; |
|
117
|
|
|
$foreignModel = $relationship->foreignModel; |
|
118
|
|
|
$pivotTable = $relationship->pivotTable; |
|
119
|
|
|
$parentPivotKey = $relationship->parentPivotKey; |
|
120
|
|
|
$relatedPivotKey = $relationship->relatedPivotKey; |
|
121
|
|
|
|
|
122
|
|
|
$findColumn = $object->details['findColumn']; |
|
123
|
|
|
|
|
124
|
|
|
$localObject = DBM::model($localModel, $localTable)::where($findColumn, $table->{$findColumn})->first(); |
|
125
|
|
|
|
|
126
|
|
|
DBM::Object() |
|
127
|
|
|
->setManyToManyRelation( |
|
128
|
|
|
$localObject, |
|
129
|
|
|
$foreignModel, |
|
130
|
|
|
$pivotTable, |
|
131
|
|
|
$parentPivotKey, |
|
132
|
|
|
$relatedPivotKey |
|
133
|
|
|
) |
|
134
|
|
|
->belongs_to_many() |
|
135
|
|
|
->attach($columns->{$relatedPivotKey}); |
|
136
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
// else if (isset($field['relationship']) && $field['relationship']['relationType'] == "hasMany") { |
|
140
|
|
|
|
|
141
|
|
|
// $relationship = $field['relationship']; |
|
142
|
|
|
|
|
143
|
|
|
// $localModel = $relationship['localModel']; |
|
144
|
|
|
// $findColumn = $object->details['findColumn']; |
|
145
|
|
|
// $foreignModel = $relationship['foreignModel']; |
|
146
|
|
|
// $foreignKey = $relationship['foreignKey']; |
|
147
|
|
|
// $localKey = $relationship['localKey']; |
|
148
|
|
|
|
|
149
|
|
|
// $localObject = $localModel::where($findColumn, $table->{$findColumn})->first(); |
|
150
|
|
|
|
|
151
|
|
|
// $items = []; |
|
152
|
|
|
|
|
153
|
|
|
// foreach ($columns[$foreignKey] as $key => $value) { |
|
154
|
|
|
// // return response()->json(['columns' => $columns['menu_id'], 'fields' => $value, 'model' => $foreignModel]); |
|
155
|
|
|
// $originalColumns = Table::getColumnsName($relationship['foreignTable']); |
|
156
|
|
|
// $foreignTableFields = DBM::Object()->where('name', $relationship['foreignTable'])->first()->fields()->where('create', 1)->get(); |
|
157
|
|
|
|
|
158
|
|
|
// $oldItem = $foreignModel::find($value); |
|
159
|
|
|
// $item = new $foreignModel; |
|
160
|
|
|
|
|
161
|
|
|
// foreach ($foreignTableFields as $foreignTableField) { |
|
162
|
|
|
// if (in_array($foreignTableField->name, $originalColumns)) { |
|
163
|
|
|
// if ($foreignTableField->name != $foreignKey) { |
|
164
|
|
|
// $item->{$foreignTableField->name} = $oldItem->{$foreignTableField->name}; |
|
165
|
|
|
// } |
|
166
|
|
|
// } |
|
167
|
|
|
// } |
|
168
|
|
|
// DBM::Object() |
|
169
|
|
|
// ->setCommonRelation( |
|
170
|
|
|
// $localObject, |
|
171
|
|
|
// $foreignModel, |
|
172
|
|
|
// $foreignKey, |
|
173
|
|
|
// $localKey) |
|
174
|
|
|
// ->has_many() |
|
175
|
|
|
// ->save($item); |
|
176
|
|
|
// } |
|
177
|
|
|
|
|
178
|
|
|
// } |
|
179
|
|
|
} |
|
180
|
|
|
return response()->json(['success' => true, 'object' => $object, 'table' => $table]); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
} catch (\Exception $e) { |
|
184
|
|
|
return $this->generateError([$e->getMessage()]); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
return response()->json(['success' => false]); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
public function update(Request $request) |
|
192
|
|
|
{ |
|
193
|
|
|
if ($request->ajax()) { |
|
194
|
|
|
|
|
195
|
|
|
if (($response = DBM::authorize('record.update')) !== true) { |
|
196
|
|
|
return $response; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
$tableName = $request->table; |
|
200
|
|
|
$originalColumns = Table::getColumnsName($tableName); |
|
201
|
|
|
$columns = json_decode($request->columns); |
|
202
|
|
|
$fields = json_decode($request->fields); |
|
203
|
|
|
|
|
204
|
|
|
// return response()->json(['columns' => $columns->multiple_dropdown]); |
|
205
|
|
|
|
|
206
|
|
|
$errors = $this->validation($fields, $columns, 'update'); |
|
207
|
|
|
|
|
208
|
|
|
if (count($errors) > 0) { |
|
209
|
|
|
return $this->generateError($errors); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
$object = DBM::Object()->where('name', $tableName)->first(); |
|
213
|
|
|
$model = $object->model; |
|
214
|
|
|
$details = $object->details; |
|
215
|
|
|
$key = $details['findColumn']; |
|
216
|
|
|
|
|
217
|
|
|
if (!class_exists($model)) { |
|
218
|
|
|
return $this->generateError(["Model not found. Please create model first"]); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
try { |
|
222
|
|
|
|
|
223
|
|
|
$table = DBM::model($model, $tableName)->where($key, $columns->{$key})->first(); |
|
224
|
|
|
|
|
225
|
|
|
// return response()->json(['details' => $table, 'key' => $key]); |
|
226
|
|
|
|
|
227
|
|
|
foreach ($columns as $column => $value) { |
|
228
|
|
|
// $column = $field->name; |
|
229
|
|
|
// $value = $request->{$column}; |
|
230
|
|
|
|
|
231
|
|
|
if (in_array($column, $originalColumns)) { |
|
232
|
|
|
|
|
233
|
|
|
if ($request->hasFile($column)) { |
|
234
|
|
|
$files = $request->file($column); |
|
235
|
|
|
$values = []; |
|
236
|
|
|
foreach ($files as $file) { |
|
237
|
|
|
$fileName = Str::random(config('dbm.filesystem.random_length')) . '.' . $file->getClientOriginalExtension(); |
|
238
|
|
|
$path = 'public/dbm/' . $tableName; |
|
239
|
|
|
$file->storeAs($path, $fileName); |
|
240
|
|
|
$values[] = $fileName; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
// $value = json_encode($values); |
|
244
|
|
|
|
|
245
|
|
|
if (count($values) > 1) { |
|
246
|
|
|
$value = $values; |
|
247
|
|
|
if (!Driver::isMongoDB()) { |
|
248
|
|
|
$value = is_array($values) ? json_encode($values) : $value; |
|
249
|
|
|
} |
|
250
|
|
|
} else if (count($values) == 1) { |
|
251
|
|
|
$value = $values[0]; |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
if ($value !== null && $value !== "") { |
|
256
|
|
|
|
|
257
|
|
|
if (!Driver::isMongoDB()) { |
|
258
|
|
|
if ($functionName = $this->hasFunction($fields, $column)) { |
|
259
|
|
|
|
|
260
|
|
|
$value = $this->executeFunction($functionName, $value); |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
$table->{$column} = is_array($value) ? json_encode($value) : $value; |
|
265
|
|
|
|
|
266
|
|
|
if (Driver::isMongoDB()) { |
|
267
|
|
|
|
|
268
|
|
|
$fieldType = $this->getFieldType($tableName, $column); |
|
269
|
|
|
|
|
270
|
|
|
if (!in_array($fieldType, Type::getTypes())) { |
|
271
|
|
|
$this->generateError([$fieldType . " type not supported."]); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
$table->{$column} = Type::$fieldType($value); |
|
275
|
|
|
|
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
if ($table->update()) { |
|
282
|
|
|
|
|
283
|
|
|
foreach ($fields as $field) { |
|
284
|
|
|
|
|
285
|
|
|
// return response()->json(['fields' => $fields]); |
|
286
|
|
|
|
|
287
|
|
|
if (isset($field->relationship)) { |
|
288
|
|
|
|
|
289
|
|
|
$relationship = $field->relationship; |
|
290
|
|
|
|
|
291
|
|
|
$localModel = $relationship->localModel; |
|
292
|
|
|
$localTable = $relationship->localTable; |
|
293
|
|
|
$foreignModel = $relationship->foreignModel; |
|
294
|
|
|
|
|
295
|
|
|
if ($field->relationship->relationType == "belongsToMany") { |
|
296
|
|
|
$pivotTable = $relationship->pivotTable; |
|
297
|
|
|
$parentPivotKey = $relationship->parentPivotKey; |
|
298
|
|
|
$relatedPivotKey = $relationship->relatedPivotKey; |
|
299
|
|
|
|
|
300
|
|
|
$findColumn = $object->details['findColumn']; |
|
301
|
|
|
|
|
302
|
|
|
$localObject = DBM::model($localModel, $localTable)->where($findColumn, $table->{$findColumn})->first(); |
|
303
|
|
|
|
|
304
|
|
|
DBM::Object() |
|
305
|
|
|
->setManyToManyRelation( |
|
306
|
|
|
$localObject, |
|
307
|
|
|
$foreignModel, |
|
308
|
|
|
$pivotTable, |
|
309
|
|
|
$parentPivotKey, |
|
310
|
|
|
$relatedPivotKey |
|
311
|
|
|
) |
|
312
|
|
|
->belongs_to_many() |
|
313
|
|
|
->sync($columns->{$relatedPivotKey}); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
} |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
return response()->json(['success' => true]); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
} catch (\Exception $e) { |
|
323
|
|
|
return $this->generateError([$e->getMessage()]); |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
return response()->json(['success' => false]); |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
public function delete(Request $request) |
|
331
|
|
|
{ |
|
332
|
|
|
if ($request->ajax()) { |
|
333
|
|
|
|
|
334
|
|
|
if (($response = DBM::authorize('record.delete')) !== true) { |
|
335
|
|
|
return $response; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
$tableName = $request->table; |
|
339
|
|
|
// $originalColumns = Table::getColumnsName($tableName); |
|
340
|
|
|
$columns = json_decode($request->columns); |
|
341
|
|
|
$fields = $request->fields; |
|
342
|
|
|
$object = DBM::Object()->where('name', $tableName)->first(); |
|
343
|
|
|
$model = $object->model; |
|
344
|
|
|
$details = $object->details; |
|
345
|
|
|
$key = $details['findColumn']; |
|
346
|
|
|
|
|
347
|
|
|
if (!class_exists($model)) { |
|
348
|
|
|
return $this->generateError(["Model not found. Please create model first"]); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
try { |
|
352
|
|
|
$table = DBM::model($model, $tableName)->where($key, $columns->{$key})->first(); |
|
353
|
|
|
if ($table) { |
|
354
|
|
|
// Remove Relationship data |
|
355
|
|
|
foreach ($fields as $field) { |
|
356
|
|
|
$field = json_decode($field); |
|
357
|
|
|
$this->removeRelationshipData($field, $object, $table); |
|
358
|
|
|
} |
|
359
|
|
|
// Check Table deleted successfully |
|
360
|
|
|
if ($table->delete()) { |
|
361
|
|
|
return response()->json(['success' => true]); |
|
362
|
|
|
} |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
} catch (\Exception $e) { |
|
366
|
|
|
return $this->generateError([$e->getMessage()]); |
|
367
|
|
|
} |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
return response()->json(['success' => false]); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
public function getTableDetails(Request $request) |
|
374
|
|
|
{ |
|
375
|
|
|
if ($request->ajax()) { |
|
376
|
|
|
|
|
377
|
|
|
if (($response = DBM::authorize('record.browse')) !== true) { |
|
378
|
|
|
return $response; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
$tableName = $request->table; |
|
382
|
|
|
$object = DBM::Object()->where('name', $tableName)->first(); |
|
383
|
|
|
|
|
384
|
|
|
if (!$object) { |
|
385
|
|
|
return response()->json([ |
|
386
|
|
|
'success' => false, |
|
387
|
|
|
'errors' => ["There is no Object details"], |
|
388
|
|
|
], 400); |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
$createFields = $object->createFields(); |
|
392
|
|
|
$browseFields = $object->readFields(); |
|
393
|
|
|
$editFields = $object->editFields(); |
|
394
|
|
|
$deleteFields = $object->deleteFields(); |
|
395
|
|
|
$fields = $object->allFields(); |
|
396
|
|
|
$foreignTableData = []; |
|
397
|
|
|
|
|
398
|
|
|
$createFields = $this->prepareRecordFields($createFields); |
|
399
|
|
|
$editFields = $this->prepareRecordFields($editFields); |
|
400
|
|
|
|
|
401
|
|
|
$model = $object->model; |
|
402
|
|
|
|
|
403
|
|
|
if (!class_exists($model)) { |
|
404
|
|
|
return $this->generateError(["Model not found. Please create model first"]); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
$perPage = (int) $request->perPage; |
|
408
|
|
|
$query = $request->q; |
|
409
|
|
|
$searchColumn = $object->details['searchColumn']; |
|
410
|
|
|
$records = DBM::model($model, $tableName)->paginate($perPage); |
|
411
|
|
|
|
|
412
|
|
|
if (!empty($query) && !empty($searchColumn)) { |
|
413
|
|
|
$records = DBM::model($model, $tableName) |
|
414
|
|
|
->where($searchColumn, 'LIKE', '%' . $query . '%') |
|
415
|
|
|
->paginate($perPage); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
$records = $this->prepareRelationshipData($records, $browseFields, $object); |
|
419
|
|
|
$recordsDetail = $this->prepareJsonFieldData($records, $fields, $object, $request->findValue); |
|
420
|
|
|
|
|
421
|
|
|
$objectDetails = $object->details; |
|
422
|
|
|
$objectDetails['perPage'] = $perPage; |
|
423
|
|
|
|
|
424
|
|
|
return response()->json([ |
|
425
|
|
|
'success' => true, |
|
426
|
|
|
'object' => $object, |
|
427
|
|
|
'objectDetails' => $objectDetails, |
|
428
|
|
|
'createFields' => $createFields, |
|
429
|
|
|
'browseFields' => $browseFields, |
|
430
|
|
|
'editFields' => $editFields, |
|
431
|
|
|
'deleteFields' => $deleteFields, |
|
432
|
|
|
'records' => $recordsDetail['records'], |
|
433
|
|
|
'record' => $recordsDetail['record'], |
|
434
|
|
|
'foreignTableData' => $foreignTableData, |
|
435
|
|
|
'userPermissions' => DBM::userPermissions(), |
|
436
|
|
|
'pagination' => $records, |
|
437
|
|
|
]); |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
return response()->json(['success' => false]); |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
public function prepareRecordFields($fields) |
|
444
|
|
|
{ |
|
445
|
|
|
foreach ($fields as $key => $field) { |
|
446
|
|
|
|
|
447
|
|
|
if ($field->type == 'relationship') { |
|
448
|
|
|
|
|
449
|
|
|
$relationship = $field->settings; |
|
450
|
|
|
$foreignModel = $relationship['foreignModel']; |
|
451
|
|
|
$foreignKey = $relationship['foreignKey']; |
|
452
|
|
|
$fields = $this->removeRelationshipKeyForBelongsTo($fields, $foreignKey); |
|
453
|
|
|
$field->foreignTableData = $foreignModel::all(); |
|
454
|
|
|
$field->relationship = $relationship; |
|
455
|
|
|
continue; |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
if (isset($field->settings['options'])) { |
|
459
|
|
|
$options = $this->getSettingOptions($field); |
|
460
|
|
|
if (is_array($options)) { |
|
461
|
|
|
$fields[$key]->options = $options; |
|
462
|
|
|
} |
|
463
|
|
|
} |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
return $fields; |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
public function prepareJsonFieldData($records, $fields, $object, $findValue) |
|
470
|
|
|
{ |
|
471
|
|
|
$newRecords = []; |
|
472
|
|
|
$newRecord = new \stdClass(); |
|
473
|
|
|
|
|
474
|
|
|
foreach ($records as $item => $record) { |
|
475
|
|
|
|
|
476
|
|
|
foreach ($fields as $key => &$field) { |
|
477
|
|
|
|
|
478
|
|
|
if (isset($record->{$field->name})) { |
|
479
|
|
|
|
|
480
|
|
|
$record->{$field->name} = is_json($record->{$field->name}) ? json_decode($record->{$field->name}, true) : $record->{$field->name}; |
|
481
|
|
|
} |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
if ($findValue && $record->{$object->details['findColumn']} == $findValue) { |
|
485
|
|
|
$newRecord = $record; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
$newRecords[] = $record; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
return [ |
|
492
|
|
|
"records" => $newRecords, |
|
493
|
|
|
"record" => $newRecord, |
|
494
|
|
|
]; |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
public function prepareRelationshipData($records, $browseFields, $object) |
|
498
|
|
|
{ |
|
499
|
|
|
foreach ($records as $item => $record) { |
|
500
|
|
|
|
|
501
|
|
|
foreach ($browseFields as $field) { |
|
502
|
|
|
|
|
503
|
|
|
if ($field->type == 'relationship') { |
|
504
|
|
|
|
|
505
|
|
|
$relationship = $field->settings; |
|
506
|
|
|
|
|
507
|
|
|
$findColumn = $object->details['findColumn']; |
|
508
|
|
|
|
|
509
|
|
|
$localModel = $relationship['localModel']; |
|
510
|
|
|
$localKey = $relationship['localKey']; |
|
511
|
|
|
$foreignModel = $relationship['foreignModel']; |
|
512
|
|
|
$foreignKey = $relationship['foreignKey']; |
|
513
|
|
|
$relationshipType = $relationship['relationType']; |
|
514
|
|
|
$displayLabel = $relationship['displayLabel']; |
|
515
|
|
|
|
|
516
|
|
|
if ($relationshipType == 'belongsTo') { |
|
517
|
|
|
|
|
518
|
|
|
$localObject = $localModel::where($findColumn, $record->{$findColumn})->first(); |
|
519
|
|
|
|
|
520
|
|
|
$datas = DBM::Object()->setCommonRelation($localObject, $foreignModel, $foreignKey, $localKey)->belongs_to; |
|
521
|
|
|
|
|
522
|
|
|
$record->{$field->name} = $datas; |
|
523
|
|
|
$field->displayLabel = $displayLabel; |
|
524
|
|
|
$field->localKey = $localKey; |
|
525
|
|
|
$field->foreignKey = $foreignKey; |
|
526
|
|
|
$field->relationshipType = $relationshipType; |
|
527
|
|
|
|
|
528
|
|
|
} else if ($relationshipType == 'hasMany') { |
|
529
|
|
|
|
|
530
|
|
|
$localObject = $localModel::where($findColumn, $record->{$findColumn})->first(); |
|
531
|
|
|
$datas = DBM::Object()->setCommonRelation($localObject, $foreignModel, $foreignKey, $localKey)->has_many; |
|
532
|
|
|
|
|
533
|
|
|
$record->{$field->name} = $datas; |
|
534
|
|
|
$field->displayLabel = $displayLabel; |
|
535
|
|
|
$field->localKey = $localKey; |
|
536
|
|
|
$field->foreignKey = $foreignKey; |
|
537
|
|
|
$field->relationshipType = $relationshipType; |
|
538
|
|
|
|
|
539
|
|
|
} else if ($relationshipType == 'belongsToMany') { |
|
540
|
|
|
|
|
541
|
|
|
$pivotTable = $relationship['pivotTable']; |
|
542
|
|
|
$parentPivotKey = $relationship['parentPivotKey']; |
|
543
|
|
|
$relatedPivotKey = $relationship['relatedPivotKey']; |
|
544
|
|
|
|
|
545
|
|
|
$localObject = $localModel::where($findColumn, $record->{$findColumn})->first(); |
|
546
|
|
|
|
|
547
|
|
|
$datas = DBM::Object()->setManyToManyRelation($localObject, $foreignModel, $pivotTable, $parentPivotKey, $relatedPivotKey)->belongs_to_many; |
|
548
|
|
|
|
|
549
|
|
|
$record->{$field->name} = $datas; |
|
550
|
|
|
$field->displayLabel = $displayLabel; |
|
551
|
|
|
$field->localKey = $localKey; |
|
552
|
|
|
$field->foreignKey = $foreignKey; |
|
553
|
|
|
$field->relationshipType = $relationshipType; |
|
554
|
|
|
} |
|
555
|
|
|
} |
|
556
|
|
|
} |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
return $records; |
|
560
|
|
|
} |
|
561
|
|
|
} |
|
562
|
|
|
|
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