1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Jobs\Page; |
4
|
|
|
|
5
|
|
|
use Dynamic\Jobs\Model\JobCategory; |
6
|
|
|
use Dynamic\Jobs\Model\JobSection; |
7
|
|
|
use Dynamic\Jobs\Model\JobSubmission; |
8
|
|
|
use \Page; |
9
|
|
|
use SilverStripe\Control\Controller; |
10
|
|
|
use SilverStripe\Forms\DateField; |
11
|
|
|
use SilverStripe\Forms\DropdownField; |
12
|
|
|
use SilverStripe\Forms\FieldList; |
13
|
|
|
use SilverStripe\Forms\GridField\GridField; |
14
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; |
15
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
16
|
|
|
use SilverStripe\Forms\GridField\GridFieldDeleteAction; |
17
|
|
|
use SilverStripe\Forms\ListboxField; |
18
|
|
|
use SilverStripe\Forms\TreeMultiselectField; |
19
|
|
|
use SilverStripe\ORM\Search\SearchContext; |
20
|
|
|
use SilverStripe\Security\Permission; |
21
|
|
|
use SilverStripe\Security\PermissionProvider; |
22
|
|
|
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; |
|
|
|
|
23
|
|
|
use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class Job |
27
|
|
|
* @package Dynamic\Jobs\Model |
28
|
|
|
*/ |
29
|
|
|
class Job extends Page implements PermissionProvider |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private static $singular_name = 'Job'; |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private static $plural_name = 'Jobs'; |
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private static $description = 'Job detail page allowing for application submissions'; |
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private static $table_name = 'Dynamic_Job'; |
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
private static $db = [ |
|
|
|
|
55
|
|
|
'PositionType' => "Enum(array('Full-time', 'Part-time', 'Freelance', 'Internship'))", |
56
|
|
|
'PostDate' => 'Date', |
57
|
|
|
'EndPostDate' => 'Date', |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
private static $has_many = [ |
|
|
|
|
64
|
|
|
'Sections' => JobSection::class, |
65
|
|
|
'Submissions' => JobSubmission::class, |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var array |
70
|
|
|
*/ |
71
|
|
|
private static $many_many = [ |
|
|
|
|
72
|
|
|
'Categories' => JobCategory::class, |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var array |
77
|
|
|
*/ |
78
|
|
|
private static $many_many_extraFields = [ |
|
|
|
|
79
|
|
|
'Categories' => [ |
80
|
|
|
'Sort' => 'Int', |
81
|
|
|
], |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var array |
86
|
|
|
*/ |
87
|
|
|
private static $searchable_fields = [ |
|
|
|
|
88
|
|
|
'Title', |
89
|
|
|
'Categories.ID' => [ |
90
|
|
|
'title' => 'Category', |
91
|
|
|
], |
92
|
|
|
'PositionType' => [ |
93
|
|
|
'title' => 'Type', |
94
|
|
|
], |
95
|
|
|
]; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var string |
99
|
|
|
*/ |
100
|
|
|
private static $default_parent = JobCollection::class; |
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var bool |
104
|
|
|
*/ |
105
|
|
|
private static $can_be_root = false; |
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var bool |
109
|
|
|
*/ |
110
|
|
|
private static $show_in_sitetree = false; |
|
|
|
|
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var array |
114
|
|
|
*/ |
115
|
|
|
private static $allowed_children = []; |
|
|
|
|
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return SearchContext |
119
|
|
|
*/ |
120
|
|
|
public function getCustomSearchContext() |
121
|
|
|
{ |
122
|
|
|
$fields = $this->scaffoldSearchFields([ |
123
|
|
|
'restrictFields' => [ |
124
|
|
|
'Title', |
125
|
|
|
'Categories.ID', |
126
|
|
|
'PositionType', |
127
|
|
|
], |
128
|
|
|
]); |
129
|
|
|
|
130
|
|
|
$filters = $this->defaultSearchFilters(); |
131
|
|
|
|
132
|
|
|
return new SearchContext( |
133
|
|
|
$this->ClassName, |
134
|
|
|
$fields, |
135
|
|
|
$filters |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* |
141
|
|
|
*/ |
142
|
14 |
|
public function populateDefaults() |
143
|
|
|
{ |
144
|
14 |
|
$this->PostDate = date('Y-m-d'); |
|
|
|
|
145
|
|
|
|
146
|
14 |
|
parent::populateDefaults(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return FieldList |
151
|
|
|
*/ |
152
|
1 |
|
public function getCMSFields() |
153
|
|
|
{ |
154
|
1 |
|
$fields = parent::getCMSFields(); |
155
|
|
|
|
156
|
1 |
|
$fields->addFieldsToTab('Root.Details.Info', [ |
157
|
1 |
|
DropdownField::create( |
158
|
1 |
|
'PositionType', |
159
|
1 |
|
'Position Type', |
160
|
1 |
|
Job::singleton()->dbObject('PositionType')->enumValues() |
161
|
1 |
|
)->setEmptyString('--select--'), |
162
|
1 |
|
DateField::create('PostDate', 'Position Post Date'), |
163
|
1 |
|
DateField::create('EndPostDate', 'Position Post End Date'), |
164
|
|
|
]); |
165
|
|
|
|
166
|
1 |
|
if ($this->ID) { |
167
|
|
|
// sections |
168
|
1 |
|
$config = GridFieldConfig_RelationEditor::create(); |
169
|
1 |
|
if (class_exists(GridFieldOrderableRows::class)) { |
170
|
|
|
$config->addComponent(new GridFieldOrderableRows('Sort')); |
171
|
|
|
} |
172
|
1 |
|
$config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
173
|
1 |
|
$config->removeComponentsByType(GridFieldDeleteAction::class); |
174
|
1 |
|
$config->addComponent(new GridFieldDeleteAction(false)); |
175
|
1 |
|
$sections = $this->Sections()->sort('Sort'); |
|
|
|
|
176
|
1 |
|
$sectionsField = GridField::create('Sections', 'Sections', $sections, $config); |
177
|
1 |
|
$fields->addFieldsToTab('Root.Details.Sections', [ |
178
|
1 |
|
$sectionsField, |
179
|
|
|
]); |
180
|
|
|
|
181
|
|
|
// categories |
182
|
1 |
|
$config = GridFieldConfig_RelationEditor::create(); |
183
|
1 |
|
if (class_exists(GridFieldOrderableRows::class)) { |
184
|
|
|
$config->addComponent(new GridFieldOrderableRows('Sort')); |
185
|
|
|
} |
186
|
1 |
|
if (class_exists(GridFieldAddExistingSearchButton::class)) { |
187
|
|
|
$config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
188
|
|
|
$config->addComponent(new GridFieldAddExistingSearchButton()); |
189
|
|
|
} |
190
|
1 |
|
$categories = $this->Categories()->sort('Sort'); |
|
|
|
|
191
|
1 |
|
$categoriesField = GridField::create('Categories', 'Categories', $categories, $config); |
|
|
|
|
192
|
|
|
|
193
|
1 |
|
$categoriesField = ListboxField::create( |
194
|
1 |
|
'Categories', |
195
|
1 |
|
'Categories', |
196
|
1 |
|
JobCategory::get()->map() |
197
|
|
|
); |
198
|
|
|
|
199
|
1 |
|
$fields->addFieldsToTab('Root.Details.Categories', [ |
200
|
1 |
|
$categoriesField, |
201
|
|
|
]); |
202
|
|
|
} |
203
|
|
|
|
204
|
1 |
|
return $fields; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return string |
209
|
|
|
*/ |
210
|
1 |
|
public function getApplyButton() |
211
|
|
|
{ |
212
|
1 |
|
$apply = Controller::join_links( |
213
|
1 |
|
$this->Link(), |
214
|
1 |
|
'apply' |
215
|
|
|
); |
216
|
1 |
|
return $apply; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return mixed |
221
|
|
|
*/ |
222
|
1 |
|
public function getApplicationLink() |
223
|
|
|
{ |
224
|
1 |
|
if ($this->parent()->Application()->ID != 0) { |
225
|
|
|
return $this->parent()->Application()->URL; |
226
|
|
|
} |
227
|
1 |
|
return false; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return mixed |
232
|
|
|
*/ |
233
|
|
|
public function getCategoryList() |
234
|
|
|
{ |
235
|
|
|
return $this->Categories()->sort('Sort'); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @return bool |
240
|
|
|
*/ |
241
|
|
|
public function getPrimaryCategory() |
242
|
|
|
{ |
243
|
|
|
if ($this->Categories()->exists()) { |
244
|
|
|
return $this->Categories()->first(); |
245
|
|
|
} |
246
|
|
|
return false; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @return array |
251
|
|
|
*/ |
252
|
1 |
|
public function providePermissions() |
253
|
|
|
{ |
254
|
|
|
return [ |
255
|
1 |
|
'Job_EDIT' => 'Edit a Job', |
256
|
|
|
'Job_DELETE' => 'Delete a Job', |
257
|
|
|
'Job_CREATE' => 'Create a Job', |
258
|
|
|
]; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @param null $member |
|
|
|
|
263
|
|
|
* |
264
|
|
|
* @return bool|int |
265
|
|
|
*/ |
266
|
1 |
|
public function canEdit($member = null) |
267
|
|
|
{ |
268
|
1 |
|
return Permission::check('Job_EDIT', 'any', $member); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @param null $member |
|
|
|
|
273
|
|
|
* |
274
|
|
|
* @return bool|int |
275
|
|
|
*/ |
276
|
1 |
|
public function canDelete($member = null) |
277
|
|
|
{ |
278
|
1 |
|
return Permission::check('Job_DELETE', 'any', $member); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @param null $member |
|
|
|
|
283
|
|
|
* |
284
|
|
|
* @return bool|int |
285
|
|
|
*/ |
286
|
1 |
|
public function canCreate($member = null, $context = []) |
287
|
|
|
{ |
288
|
1 |
|
return Permission::check('Job_CREATE', 'any', $member); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @param null $member |
|
|
|
|
293
|
|
|
* |
294
|
|
|
* @return bool |
295
|
|
|
*/ |
296
|
4 |
|
public function canView($member = null) |
297
|
|
|
{ |
298
|
4 |
|
return true; |
299
|
|
|
} |
300
|
|
|
} |
301
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths