Completed
Pull Request — master (#15)
by Jason
03:16
created

JobCategory::fieldLabels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
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 1
    public function fieldLabels($includerelations = true)
58
    {
59 1
        $labels = parent::fieldLabels($includerelations);
60
61 1
        $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name');
62 1
        $labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Title');
63 1
        $labels['Jobs'] = _t(Job::class . '.PLURALNAME', 'Jobs');
64
65 1
        return $labels;
66
    }
67
68
    /**
69
     * @return FieldList
70
     */
71 1
    public function getCMSFields()
72
    {
73 1
        $fields = parent::getCMSFields();
74
75 1
        $fields->dataFieldByName('Name')
76 1
            ->setDescription(_t(
77 1
                __CLASS__ . '.NameDescription',
78 1
                'For internal reference only'
79
            ));
80
81 1
        if ($this->ID) {
82 1
            $fields->dataFieldByName('Jobs')->getConfig()
83 1
                ->removeComponentsByType(GridFieldAddNewButton::class);
84
        }
85
86 1
        return $fields;
87
    }
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 1
    public function canEdit($member = null)
95
    {
96 1
        return Permission::check('JOB_MANAGE', 'any', $member);
97
    }
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 1
    public function canDelete($member = null)
105
    {
106 1
        return Permission::check('JOB_MANAGE', 'any', $member);
107
    }
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 1
    public function canCreate($member = null, $context = [])
115
    {
116 1
        return Permission::check('JOB_MANAGE', 'any', $member);
117
    }
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 8
    public function canView($member = null)
125
    {
126 8
        return Permission::check('JOB_MANAGE', 'any', $member);
127
    }
128
}
129