LocationCategory::canView()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Dynamic\Locator\Model;
4
5
use Dynamic\Locator\Location;
6
use Dynamic\Locator\Page\Locator;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\GridField\GridField;
9
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
10
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
11
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
12
use SilverStripe\ORM\DataObject;
13
use SilverStripe\ORM\ManyManyList;
14
use SilverStripe\Security\Permission;
15
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
16
17
/**
18
 * Class LocationCategory
19
 *
20
 * @property string $Name
21
 * @method ManyManyList LocationSet()
22
 * @method ManyManyList Locators()
23
 */
24
class LocationCategory extends DataObject
25
{
26
    /**
27
     * @var string
28
     */
29
    private static $singular_name = 'Category';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
30
31
    /**
32
     * @var string
33
     */
34
    private static $plural_name = 'Categories';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
35
36
    /**
37
     * @var array
38
     */
39
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
40
        'Name' => 'Varchar(100)',
41
    ];
42
43
    /**
44
     * @var array
45
     */
46
    private static $belongs_many_many = [
0 ignored issues
show
introduced by
The private property $belongs_many_many is not used, and could be removed.
Loading history...
47
        'Locators' => Locator::class,
48
        'LocationSet' => Location::class,
49
    ];
50
51
    /**
52
     * @var string
53
     */
54
    private static $table_name = 'LocationCategory';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
55
56
    /**
57
     * @var string
58
     */
59
    private static $default_sort = 'Name';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
60
61
    /**
62
     * @return \SilverStripe\Forms\FieldList
63
     */
64
    public function getCMSFields()
65
    {
66
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
67
            $fields->removeByName([
68
                'Locations',
69
                'LocationSet',
70
                'Locators',
71
                'LinkTracking',
72
                'FileTracking',
73
            ]);
74
75
            if ($this->ID) {
76
                // Locations
77
                $config = GridFieldConfig_RelationEditor::create();
78
                $config->removeComponentsByType([
79
                    GridFieldAddExistingAutocompleter::class,
80
                    GridFieldAddNewButton::class,
81
                ])
82
                    ->addComponents([
83
                        new GridFieldAddExistingSearchButton(),
84
                    ]);
85
                $locations = $this->Locations();
86
                $locationField = GridField::create('Locations', 'Locations', $locations, $config);
87
88
                $fields->addFieldsToTab('Root.Main', [
89
                    $locationField,
90
                ]);
91
            }
92
        });
93
94
        $fields = parent::getCMSFields();
95
96
        return $fields;
97
    }
98
99
    /**
100
     * For backwards compatability
101
     * @return ManyManyList
102
     */
103
    public function Locations()
104
    {
105
        return $this->LocationSet();
106
    }
107
108
    /**
109
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
110
     * @param array $context
111
     * @return bool
112
     */
113
    public function canView($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

113
    public function canView($member = null, /** @scrutinizer ignore-unused */ $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
114
    {
115
        return true;
116
    }
117
118
    /**
119
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
120
     * @param array $context
121
     * @return bool|int
122
     */
123
    public function canEdit($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

123
    public function canEdit($member = null, /** @scrutinizer ignore-unused */ $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
124
    {
125
        return Permission::check('Location_EDIT', 'any', $member);
126
    }
127
128
    /**
129
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
130
     * @param array $context
131
     * @return bool|int
132
     */
133
    public function canDelete($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

133
    public function canDelete($member = null, /** @scrutinizer ignore-unused */ $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
134
    {
135
        return Permission::check('Location_DELETE', 'any', $member);
136
    }
137
138
    /**
139
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
140
     * @param array $context
141
     * @return bool|int
142
     */
143
    public function canCreate($member = null, $context = [])
144
    {
145
        return Permission::check('Location_CREATE', 'any', $member);
146
    }
147
}
148