1 | <?php |
||
2 | |||
3 | namespace Dynamic\Jobs\Model; |
||
4 | |||
5 | use Dynamic\Jobs\Page\Job; |
||
6 | use SilverStripe\Forms\FieldList; |
||
7 | use SilverStripe\ORM\DataObject; |
||
8 | use SilverStripe\ORM\ValidationResult; |
||
9 | use SilverStripe\Security\Permission; |
||
10 | |||
11 | /** |
||
12 | * Class JobSection |
||
13 | * @package Dynamic\Jobs\Model |
||
14 | */ |
||
15 | class JobSection extends DataObject |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private static $table_name = 'Dynamic_JobSection'; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private static $db = [ |
||
0 ignored issues
–
show
|
|||
26 | 'Name' => 'Varchar(255)', |
||
27 | 'Title' => 'Varchar(255)', |
||
28 | 'Content' => 'HTMLText', |
||
29 | 'Sort' => 'Int', |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private static $has_one = [ |
||
0 ignored issues
–
show
|
|||
36 | 'Job' => Job::class, |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private static $default_sort = 'Sort'; |
||
0 ignored issues
–
show
|
|||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | private static $summary_fields = [ |
||
0 ignored issues
–
show
|
|||
48 | 'Name' => 'Name', |
||
49 | 'Title' => 'Title', |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * @var array |
||
54 | */ |
||
55 | private static $searchable_fields = [ |
||
0 ignored issues
–
show
|
|||
56 | 'Name', |
||
57 | 'Title', |
||
58 | 'Content', |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * @param bool $includerelations |
||
63 | * @return array |
||
64 | */ |
||
65 | 1 | public function fieldLabels($includerelations = true) |
|
66 | { |
||
67 | 1 | $labels = parent::fieldLabels($includerelations); |
|
68 | |||
69 | 1 | $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); |
|
70 | 1 | $labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Title'); |
|
71 | |||
72 | 1 | return $labels; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return FieldList |
||
77 | */ |
||
78 | 1 | public function getCMSFields() |
|
79 | { |
||
80 | 1 | $fields = parent::getCMSFields(); |
|
81 | |||
82 | 1 | $fields->removeByName([ |
|
83 | 1 | 'Sort', |
|
84 | 'JobID', |
||
85 | ]); |
||
86 | |||
87 | 1 | $fields->dataFieldByName('Name')->setDescription('For internal reference only'); |
|
88 | |||
89 | 1 | return $fields; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return ValidationResult |
||
94 | */ |
||
95 | 1 | public function validate() |
|
96 | { |
||
97 | 1 | $result = parent::validate(); |
|
98 | |||
99 | 1 | if (!$this->Name) { |
|
0 ignored issues
–
show
The property
Name does not exist on Dynamic\Jobs\Model\JobSection . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
100 | 1 | $result->addError('Name is required before you can save'); |
|
101 | } |
||
102 | |||
103 | 1 | return $result; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * @param null $member |
||
0 ignored issues
–
show
|
|||
108 | * |
||
109 | * @return bool|int |
||
110 | */ |
||
111 | 1 | public function canEdit($member = null) |
|
112 | { |
||
113 | 1 | return Permission::check('JOB_MANAGE', 'any', $member); |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * @param null $member |
||
0 ignored issues
–
show
|
|||
118 | * |
||
119 | * @return bool|int |
||
120 | */ |
||
121 | 1 | public function canDelete($member = null) |
|
122 | { |
||
123 | 1 | return Permission::check('JOB_MANAGE', 'any', $member); |
|
124 | } |
||
125 | |||
126 | /** |
||
127 | * @param null $member |
||
0 ignored issues
–
show
|
|||
128 | * |
||
129 | * @return bool|int |
||
130 | */ |
||
131 | 1 | public function canCreate($member = null, $context = []) |
|
132 | { |
||
133 | 1 | return Permission::check('JOB_MANAGE', 'any', $member); |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * @param null $member |
||
0 ignored issues
–
show
|
|||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | 2 | public function canView($member = null) |
|
142 | { |
||
143 | 2 | return Permission::check('JOB_MANAGE', 'any', $member); |
|
144 | } |
||
145 | } |
||
146 |