|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Uccello\Core\Http\Controllers\Core; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
|
|
6
|
|
|
use Uccello\Core\Models\Domain; |
|
7
|
|
|
use Uccello\Core\Models\Module; |
|
8
|
|
|
|
|
9
|
|
|
class TreeController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
protected $viewName = 'tree.main'; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Check user permissions |
|
15
|
|
|
*/ |
|
16
|
|
|
protected function checkPermissions() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->middleware('uccello.permissions:retrieve'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @inheritDoc |
|
23
|
|
|
*/ |
|
24
|
|
|
public function process(?Domain $domain, Module $module, Request $request) |
|
25
|
|
|
{ |
|
26
|
|
|
// Pre-process |
|
27
|
|
|
$this->preProcess($domain, $module, $request); |
|
28
|
|
|
|
|
29
|
|
|
if (!app('uccello')->isTreeModule($module)) { |
|
|
|
|
|
|
30
|
|
|
abort(404); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
// Get model class |
|
34
|
|
|
$modelClass = $module->model_class; |
|
35
|
|
|
|
|
36
|
|
|
// Total count |
|
37
|
|
|
$totalCount = $modelClass::inDomain($domain, $this->request->session()->get('descendants'))->count(); |
|
38
|
|
|
|
|
39
|
|
|
return $this->autoView(compact('totalCount')); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns all root records where the user can access |
|
44
|
|
|
* |
|
45
|
|
|
* @return array |
|
46
|
|
|
*/ |
|
47
|
|
|
public function root(?Domain $domain, Module $module, Request $request) |
|
48
|
|
|
{ |
|
49
|
|
|
// Pre-process |
|
50
|
|
|
$this->preProcess($domain, $module, $request); |
|
51
|
|
|
|
|
52
|
|
|
// Get model class |
|
53
|
|
|
$modelClass = $module->model_class; |
|
54
|
|
|
|
|
55
|
|
|
// Get all roots records (according to the current domain) |
|
56
|
|
|
$rootRecords = $modelClass::getRoots() |
|
57
|
|
|
->inDomain($domain, $this->request->session()->get('descendants')) |
|
58
|
|
|
->get(); |
|
59
|
|
|
|
|
60
|
|
|
$roots = collect(); |
|
|
|
|
|
|
61
|
|
|
foreach ($rootRecords as $record) { |
|
62
|
|
|
$roots[] = $this->getFormattedRecordToAdd($record); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $roots; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Returns all record's children. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function children(?Domain $domain, Module $module, Request $request) |
|
74
|
|
|
{ |
|
75
|
|
|
// Pre-process |
|
76
|
|
|
$this->preProcess($domain, $module, $request); |
|
77
|
|
|
|
|
78
|
|
|
// Get model class |
|
79
|
|
|
$modelClass = $module->model_class; |
|
80
|
|
|
|
|
81
|
|
|
// Get parent record (according to the current domain) |
|
82
|
|
|
$parentRecord = $modelClass::inDomain($domain, $this->request->session()->get('descendants')) |
|
83
|
|
|
->find(request('id')); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
$children = collect(); |
|
|
|
|
|
|
86
|
|
|
if ($parentRecord) { |
|
87
|
|
|
foreach ($parentRecord->children()->get() as $record) { |
|
88
|
|
|
$children[] = $this->getFormattedRecordToAdd($record); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $children; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get formatted record to add to the tree |
|
97
|
|
|
* |
|
98
|
|
|
* @param mixed $record |
|
99
|
|
|
* @return array|null |
|
100
|
|
|
*/ |
|
101
|
|
|
protected function getFormattedRecordToAdd($record) |
|
102
|
|
|
{ |
|
103
|
|
|
return [ |
|
104
|
|
|
"id" => $record->getKey(), |
|
105
|
|
|
"text" => $record->recordLabel, |
|
106
|
|
|
"children" => $record->children->count() > 0, |
|
107
|
|
|
"a_attr" => [ |
|
108
|
|
|
"href" => ucroute('uccello.detail', $this->domain, $this->module, [ 'id' => $record->getKey() ]) |
|
109
|
|
|
] |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
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