-
Notifications
You must be signed in to change notification settings - Fork 554
/
NestedModuleController.php
59 lines (50 loc) · 1.45 KB
/
NestedModuleController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace A17\Twill\Http\Controllers\Admin;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
abstract class NestedModuleController extends ModuleController
{
/**
* Indicates if only parent items should be displayed when browsing for this module
* within a browser field.
*
* @var bool
*/
protected $showOnlyParentItemsInBrowsers = true;
/**
* The maximum depth allowed for nested items. A value of `1` means parent & child.
*
* @var int
*/
protected $nestedItemsDepth = 1;
protected function indexData($request)
{
return [
'nested' => true,
'nestedDepth' => $this->nestedItemsDepth,
];
}
protected function transformIndexItems(Collection|LengthAwarePaginator $items): Collection|LengthAwarePaginator
{
return $items->toTree();
}
protected function indexItemData($item)
{
return ($item->children ? [
'children' => $this->getIndexTableData($item->children),
] : []);
}
protected function getBrowserItems($scopes = [])
{
if ($this->showOnlyParentItemsInBrowsers) {
return $this->getIndexItems($scopes, true);
}
return $this->repository->get(
$this->indexWith,
$scopes,
$this->orderScope(),
request('offset') ?? $this->perPage ?? 50,
true
);
}
}