Passed
Push — feature/permissions-management ( 3c8a9f...1cc208 )
by Harings
19:21 queued 10s
created

NestedModuleController::transformIndexItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace A17\Twill\Http\Controllers\Admin;
4
5
abstract class NestedModuleController extends ModuleController
6
{
7
    /**
8
     * Indicates if only parent items should be displayed when browsing for this module
9
     * within a browser field.
10
     *
11
     * @var bool
12
     */
13
    protected $showOnlyParentItemsInBrowsers = true;
14
15
    /**
16
     * The maximum depth allowed for nested items. A value of `1` means parent & child.
17
     *
18
     * @var int
19
     */
20
    protected $nestedItemsDepth = 1;
21
22
    protected function indexData($request)
23
    {
24
        return [
25
            'nested' => true,
26
            'nestedDepth' => $this->nestedItemsDepth,
27
        ];
28
    }
29
30
    protected function transformIndexItems($items)
31
    {
32
        return $items->toTree();
33
    }
34
35
    protected function indexItemData($item)
36
    {
37
        return ($item->children ? [
38
            'children' => $this->getIndexTableData($item->children),
39
        ] : []);
40
    }
41
42
    protected function getBrowserItems($scopes = [])
43
    {
44
        if ($this->showOnlyParentItemsInBrowsers) {
45
            return $this->getIndexItems($scopes, true);
46
        }
47
48
        return $this->repository->get(
49
            $this->indexWith,
50
            $scopes,
51
            $this->orderScope(),
52
            request('offset') ?? $this->perPage ?? 50,
53
            true
54
        );
55
    }
56
}
57