Completed
Pull Request — master (#15)
by Jason
11:42
created

JobCategory::getCMSFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 0
loc 16
ccs 5
cts 5
cp 1
crap 2
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Jobs\Model;
4
5
use Dynamic\Jobs\Page\Job;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
8
use SilverStripe\ORM\DataObject;
9
use SilverStripe\Security\Permission;
10
11
/**
12
 * Class JobCategory
13
 * @package Dynamic\Jobs\Model
14
 */
15
class JobCategory extends DataObject
16
{
17
    /**
18
     * @var string
19
     */
20
    private static $table_name = 'Dynamic_JobCategory';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
21
22
    /**
23
     * @var array
24
     */
25
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
26
        'Name' => 'Varchar(255)',
27
        'Title' => 'Varchar(255)',
28
    ];
29
30
    /**
31
     * @var array
32
     */
33
    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...
34
        'Jobs' => Job::class,
35
    ];
36
37
    /**
38
     * @var array
39
     */
40
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
41
        'Name' => 'Name',
42
        'Title' => 'Title',
43
    ];
44
45
    /**
46
     * @var array
47
     */
48
    private static $searchable_fields = [
0 ignored issues
show
introduced by
The private property $searchable_fields is not used, and could be removed.
Loading history...
49
        'Name',
50
        'Title',
51
    ];
52
53
    /**
54
     * @param bool $includerelations
55
     * @return array
56
     */
57
    public function fieldLabels($includerelations = true)
58
    {
59
        $labels = parent::fieldLabels($includerelations);
60
61
        $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name');
62
        $labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Title');
63
        $labels['Jobs'] = _t(Job::class . '.PLURALNAME', 'Jobs');
64
65
        return $labels;
66 1
    }
67
68 1
    /**
69
     * @return FieldList
70 1
     */
71
    public function getCMSFields()
72 1
    {
73 1
        $fields = parent::getCMSFields();
74 1
75
        $fields->dataFieldByName('Name')
76
            ->setDescription(_t(
77 1
                __CLASS__ . '.NameDescription',
78
                'For internal reference only'
79
            ));
80
81
        if ($this->ID) {
82
            $fields->dataFieldByName('Jobs')->getConfig()
83
                ->removeComponentsByType(GridFieldAddNewButton::class);
84
        }
85 1
86
        return $fields;
87 1
    }
88
89
    /**
90
     * @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...
91
     *
92
     * @return bool|int
93
     */
94
    public function canEdit($member = null)
95 1
    {
96
        return Permission::check('JOB_MANAGE', 'any', $member);
97 1
    }
98
99
    /**
100
     * @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...
101
     *
102
     * @return bool|int
103
     */
104
    public function canDelete($member = null)
105 1
    {
106
        return Permission::check('JOB_MANAGE', 'any', $member);
107 1
    }
108
109
    /**
110
     * @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...
111
     *
112
     * @return bool|int
113
     */
114
    public function canCreate($member = null, $context = [])
115 8
    {
116
        return Permission::check('JOB_MANAGE', 'any', $member);
117 8
    }
118
119
    /**
120
     * @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...
121
     *
122
     * @return bool
123
     */
124
    public function canView($member = null)
125
    {
126
        return Permission::check('JOB_MANAGE', 'any', $member);
127
    }
128
}
129