Completed
Push — master ( 843223...7f5174 )
by
unknown
08:52
created

HierarchicalTableWidget   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setupDisplayPropertyValue() 0 8 2
A template() 0 3 1
A sortObjects() 0 9 1
1
<?php
2
3
namespace Charcoal\Admin\Widget;
4
5
// From `charcoal-core`
6
use Charcoal\Model\ModelInterface;
7
8
// From `charcoal-property`
9
use Charcoal\Property\PropertyInterface;
10
11
// From `charcoal-object`
12
use Charcoal\Object\HierarchicalCollection;
13
14
// From `charcoal-admin`
15
use Charcoal\Admin\Property\Display\HierarchicalDisplay;
16
use Charcoal\Admin\Widget\TableWidget;
17
18
/**
19
 * The hierarchical table widget displays a collection in a tabular (table) format.
20
 */
21
class HierarchicalTableWidget extends TableWidget
22
{
23
    /**
24
     * Provide a template to fullfill UIItem interface.
25
     *
26
     * @return string
27
     */
28
    public function template()
29
    {
30
        return 'charcoal/admin/widget/table';
31
    }
32
33
    /**
34
     * Setup the property's display value before its assigned to the object row.
35
     *
36
     * This method is useful for classes using this trait.
37
     *
38
     * @param  ModelInterface    $object   The current row's object.
39
     * @param  PropertyInterface $property The current property.
40
     * @return void
41
     */
42
    protected function setupDisplayPropertyValue(
43
        ModelInterface $object,
44
        PropertyInterface $property
45
    ) {
46
        parent::setupDisplayPropertyValue($object, $property);
47
48
        if ($this->display instanceof HierarchicalDisplay) {
49
            $this->display->setCurrentLevel($object->hierarchyLevel());
0 ignored issues
show
Bug introduced by
The method hierarchyLevel() does not exist on Charcoal\Model\ModelInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
            $this->display->setCurrentLevel($object->/** @scrutinizer ignore-call */ hierarchyLevel());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
        }
51
    }
52
53
    /**
54
     * Sort the objects before they are displayed as rows.
55
     *
56
     * @see \Charcoal\Admin\Ui\CollectionContainerTrait::sortObjects()
57
     * @return array
58
     */
59
    public function sortObjects()
60
    {
61
        $collection = new HierarchicalCollection($this->objects(), false);
62
        $collection
63
            ->setPage($this->page())
64
            ->setNumPerPage($this->numPerPage())
65
            ->sortTree();
66
67
        return $collection->all();
68
    }
69
}
70