Passed
Push — master ( 22e57b...b32123 )
by Will
03:20
created

ElementList::inlineEditable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DNADesign\ElementalList\Model;
4
5
use DNADesign\Elemental\Models\BaseElement;
6
use DNADesign\Elemental\Models\ElementalArea;
7
use DNADesign\Elemental\Extensions\ElementalAreasExtension;
8
9
use SilverStripe\Core\Config\Config;
10
use SilverStripe\ORM\ArrayList;
11
use SilverStripe\ORM\FieldType\DBField;
12
13
class ElementList extends BaseElement
14
{
15
    private static $icon = 'font-icon-block-file-list';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
16
17
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
18
        'Elements' => ElementalArea::class
19
    ];
20
21
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
22
        'Elements'
23
    ];
24
25
    private static $cascade_deletes = [
0 ignored issues
show
introduced by
The private property $cascade_deletes is not used, and could be removed.
Loading history...
26
        'Elements'
27
    ];
28
29
    private static $cascade_duplicates = [
0 ignored issues
show
introduced by
The private property $cascade_duplicates is not used, and could be removed.
Loading history...
30
        'Elements'
31
    ];
32
33
    private static $extensions = [
0 ignored issues
show
introduced by
The private property $extensions is not used, and could be removed.
Loading history...
34
        ElementalAreasExtension::class
35
    ];
36
37
    private static $table_name = 'ElementList';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
38
39
    private static $title = 'Group';
0 ignored issues
show
introduced by
The private property $title is not used, and could be removed.
Loading history...
40
41
    private static $description = 'Orderable list of elements';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
42
43
    private static $singular_name = 'list';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
44
45
    private static $plural_name = 'lists';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
46
47
    public function getType()
48
    {
49
        return _t(__CLASS__ . '.BlockType', 'List');
50
    }
51
52
    /**
53
     * @return DBField
54
     */
55
    public function getSummary()
56
    {
57
        $count = $this->Elements()->Elements()->Count();
0 ignored issues
show
Bug introduced by
The method Elements() does not exist on DNADesign\ElementalList\Model\ElementList. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

57
        $count = $this->/** @scrutinizer ignore-call */ Elements()->Elements()->Count();
Loading history...
58
        $suffix = $count === 1 ? 'element': 'elements';
59
        $summary = $this->ListDescription ? DBField::create_field('HTMLText', $this->ListDescription)->Summary(10) . '<br />': '';
0 ignored issues
show
Bug Best Practice introduced by
The property ListDescription does not exist on DNADesign\ElementalList\Model\ElementList. Since you implemented __get, consider adding a @property annotation.
Loading history...
60
61
        return DBField::create_field('HTMLText', $summary . ' <span class="el-meta">Contains ' . $count . ' ' . $suffix . '</span>');
62
    }
63
64
    /**
65
     * Retrieve a elemental area relation name which this element owns
66
     *
67
     * @return string
68
     */
69
    public function getOwnedAreaRelationName()
70
    {
71
        $has_one = $this->config()->get('has_one');
72
73
        foreach ($has_one as $relationName => $relationClass) {
74
            if ($relationClass === ElementalArea::class && $relationName !== 'Parent') {
75
                return $relationName;
76
            }
77
        }
78
79
        return 'Elements';
80
    }
81
82
    public function inlineEditable()
83
    {
84
        return false;
85
    }
86
}
87