|
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 $table_name = 'Dynamic_Job'; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var array |
|
38
|
|
|
*/ |
|
39
|
|
|
private static $db = [ |
|
|
|
|
|
|
40
|
|
|
'PositionType' => "Enum(array('Full-time', 'Part-time', 'Freelance', 'Internship'))", |
|
41
|
|
|
'PostDate' => 'Date', |
|
42
|
|
|
'EndPostDate' => 'Date', |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var array |
|
47
|
|
|
*/ |
|
48
|
|
|
private static $has_many = [ |
|
|
|
|
|
|
49
|
|
|
'Sections' => JobSection::class, |
|
50
|
|
|
'Submissions' => JobSubmission::class, |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var array |
|
55
|
|
|
*/ |
|
56
|
|
|
private static $many_many = [ |
|
|
|
|
|
|
57
|
|
|
'Categories' => JobCategory::class, |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
private static $many_many_extraFields = [ |
|
|
|
|
|
|
64
|
|
|
'Categories' => [ |
|
65
|
|
|
'Sort' => 'Int', |
|
66
|
|
|
], |
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var array |
|
71
|
|
|
*/ |
|
72
|
|
|
private static $searchable_fields = [ |
|
|
|
|
|
|
73
|
|
|
'Title', |
|
74
|
|
|
'Categories.ID' => [ |
|
75
|
|
|
'title' => 'Category', |
|
76
|
|
|
], |
|
77
|
|
|
'PositionType' => [ |
|
78
|
|
|
'title' => 'Type', |
|
79
|
|
|
], |
|
80
|
|
|
]; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var string |
|
84
|
|
|
*/ |
|
85
|
|
|
private static $default_parent = JobCollection::class; |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @var bool |
|
89
|
|
|
*/ |
|
90
|
|
|
private static $can_be_root = false; |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @var bool |
|
94
|
|
|
*/ |
|
95
|
|
|
private static $show_in_sitetree = false; |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @var array |
|
99
|
|
|
*/ |
|
100
|
|
|
private static $allowed_children = []; |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return SearchContext |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getCustomSearchContext() |
|
106
|
|
|
{ |
|
107
|
|
|
$fields = $this->scaffoldSearchFields([ |
|
108
|
|
|
'restrictFields' => [ |
|
109
|
|
|
'Title', |
|
110
|
|
|
'Categories.ID', |
|
111
|
|
|
'PositionType', |
|
112
|
|
|
], |
|
113
|
|
|
]); |
|
114
|
|
|
|
|
115
|
|
|
$filters = $this->defaultSearchFilters(); |
|
116
|
|
|
|
|
117
|
|
|
return new SearchContext( |
|
118
|
|
|
$this->ClassName, |
|
119
|
|
|
$fields, |
|
120
|
|
|
$filters |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* |
|
126
|
|
|
*/ |
|
127
|
|
|
public function populateDefaults() |
|
128
|
|
|
{ |
|
129
|
|
|
$this->PostDate = date('Y-m-d'); |
|
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
parent::populateDefaults(); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param bool $includerelations |
|
136
|
|
|
* @return array |
|
137
|
|
|
*/ |
|
138
|
|
|
public function fieldLabels($includerelations = true) |
|
139
|
|
|
{ |
|
140
|
|
|
$labels = parent::fieldLabels($includerelations); |
|
141
|
|
|
|
|
142
|
14 |
|
$labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Position Name'); |
|
143
|
|
|
$labels['Content'] = _t(__CLASS__ . '.ContentLabel', 'Introduction'); |
|
144
|
14 |
|
$labels['PositionType'] = _t(__CLASS__ . '.PositionTypeLabel', 'Position Type'); |
|
145
|
|
|
$labels['PostDate'] = _t(__CLASS__ . '.PostDateLabel', 'Post Start Date'); |
|
146
|
14 |
|
$labels['EndPostDate'] = _t(__CLASS__ . '.EndPostDateLabel', 'Post End Date'); |
|
147
|
|
|
$labels['Details'] = _t(__CLASS__ . '.DetailsTab', "Details"); |
|
148
|
|
|
$labels['Submissions'] = _t(__CLASS__ . '.SubmissionsTab', 'Submissions'); |
|
149
|
|
|
//$labels['Categories'] = _t(JobCategory::class . '.SlideType', 'Image or Video'); |
|
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
return $labels; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
1 |
|
/** |
|
155
|
1 |
|
* @return FieldList |
|
156
|
1 |
|
*/ |
|
157
|
|
|
public function getCMSFields() |
|
158
|
1 |
|
{ |
|
159
|
1 |
|
$this->beforeUpdateCMSFields(function ($fields) { |
|
160
|
1 |
|
$fields->dataFieldByName('Content') |
|
161
|
|
|
->setTitle($this->fieldLabel('Content')) |
|
162
|
1 |
|
->setRows(10); |
|
163
|
1 |
|
|
|
164
|
1 |
|
$fields->addFieldsToTab('Root.' . $this->fieldLabel('Details'), [ |
|
165
|
1 |
|
DropdownField::create( |
|
166
|
1 |
|
'PositionType', |
|
167
|
1 |
|
$this->fieldLabel('PositionType'), |
|
168
|
1 |
|
Job::singleton()->dbObject('PositionType')->enumValues() |
|
169
|
1 |
|
)->setEmptyString('--select--'), |
|
170
|
1 |
|
DateField::create('PostDate', $this->fieldLabel('PostDate')) |
|
171
|
1 |
|
->setDescription(_t( |
|
172
|
|
|
__CLASS__ . '.PostDateDescription', |
|
173
|
|
|
'Date position should appear on website' |
|
174
|
1 |
|
)), |
|
175
|
|
|
DateField::create('EndPostDate', $this->fieldLabel('EndPostDate')) |
|
176
|
1 |
|
->setDescription(_t( |
|
177
|
1 |
|
__CLASS__ . '.EndPostDateDescription', |
|
178
|
1 |
|
'Date position should be removed from website' |
|
179
|
1 |
|
)), |
|
180
|
|
|
]); |
|
181
|
|
|
|
|
182
|
1 |
|
if ($this->ID) { |
|
183
|
1 |
|
// categories |
|
184
|
|
|
$categoriesField = ListboxField::create( |
|
185
|
|
|
'Categories', |
|
186
|
|
|
_t(JobCategory::class . '.PLURALNAME', 'Categories'), |
|
187
|
1 |
|
JobCategory::get()->map() |
|
188
|
|
|
); |
|
189
|
1 |
|
|
|
190
|
1 |
|
$fields->addFieldsToTab('Root.' . $this->fieldLabel('Details'), [ |
|
191
|
1 |
|
$categoriesField, |
|
192
|
1 |
|
]); |
|
193
|
|
|
|
|
194
|
1 |
|
// sections |
|
195
|
1 |
|
$config = GridFieldConfig_RelationEditor::create(); |
|
196
|
1 |
|
$config |
|
197
|
1 |
|
->addComponent(new GridFieldOrderableRows('Sort')) |
|
198
|
1 |
|
->addComponent(new GridFieldDeleteAction(false)) |
|
199
|
|
|
->removeComponentsByType(GridFieldAddExistingAutocompleter::class) |
|
200
|
|
|
->removeComponentsByType(GridFieldDeleteAction::class); |
|
201
|
|
|
|
|
202
|
1 |
|
$sections = $this->Sections()->sort('Sort'); |
|
|
|
|
|
|
203
|
|
|
$sectionsField = GridField::create( |
|
204
|
1 |
|
'Sections', |
|
205
|
1 |
|
_t(JobSection::class . '.PLURALNAME', 'Sections'), |
|
206
|
1 |
|
$sections, |
|
207
|
|
|
$config |
|
208
|
1 |
|
) |
|
209
|
1 |
|
->setDescription(_t( |
|
210
|
1 |
|
__CLASS__ . '.SectionsDescription', |
|
211
|
1 |
|
'ex: Requirements, Education, Duties, etc.' |
|
212
|
|
|
)); |
|
213
|
|
|
|
|
214
|
1 |
|
$fields->addFieldsToTab('Root.Main', [ |
|
215
|
|
|
$sectionsField, |
|
216
|
1 |
|
]); |
|
217
|
|
|
|
|
218
|
|
|
// submissions |
|
219
|
|
|
$config = GridFieldConfig_RelationEditor::create(); |
|
220
|
|
|
$config |
|
221
|
|
|
->addComponent(new GridFieldDeleteAction(false)) |
|
222
|
1 |
|
->removeComponentsByType(GridFieldAddExistingAutocompleter::class) |
|
223
|
|
|
->removeComponentsByType(GridFieldDeleteAction::class); |
|
224
|
1 |
|
|
|
225
|
1 |
|
$submissions = $this->Submissions(); |
|
|
|
|
|
|
226
|
1 |
|
$submissionsField = GridField::create( |
|
227
|
|
|
'Submissions', |
|
228
|
1 |
|
_t(JobSubmission::class . '.PLURALNAME', 'Submissions'), |
|
229
|
|
|
$submissions, |
|
230
|
|
|
$config) |
|
231
|
|
|
; |
|
232
|
|
|
$fields->addFieldsToTab('Root.' . $this->fieldLabel('Submissions'), [ |
|
233
|
|
|
$submissionsField, |
|
234
|
1 |
|
]); |
|
235
|
|
|
} |
|
236
|
1 |
|
}); |
|
237
|
|
|
|
|
238
|
|
|
return parent::getCMSFields(); |
|
239
|
1 |
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* @return string |
|
243
|
|
|
*/ |
|
244
|
|
|
public function getApplyButton() |
|
245
|
|
|
{ |
|
246
|
|
|
$apply = Controller::join_links( |
|
247
|
|
|
$this->Link(), |
|
248
|
|
|
'apply' |
|
249
|
|
|
); |
|
250
|
|
|
return $apply; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* @return mixed |
|
255
|
|
|
*/ |
|
256
|
|
|
public function getApplicationLink() |
|
257
|
|
|
{ |
|
258
|
|
|
if ($this->parent()->Application()->ID != 0) { |
|
259
|
|
|
return $this->parent()->Application()->URL; |
|
260
|
|
|
} |
|
261
|
|
|
return false; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
1 |
|
/** |
|
265
|
|
|
* @return mixed |
|
266
|
|
|
*/ |
|
267
|
1 |
|
public function getCategoryList() |
|
268
|
|
|
{ |
|
269
|
|
|
return $this->Categories()->sort('Sort'); |
|
|
|
|
|
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* @return bool |
|
274
|
|
|
*/ |
|
275
|
|
|
public function getPrimaryCategory() |
|
276
|
|
|
{ |
|
277
|
|
|
if ($this->Categories()->exists()) { |
|
278
|
1 |
|
return $this->Categories()->first(); |
|
279
|
|
|
} |
|
280
|
1 |
|
return false; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @return array |
|
285
|
|
|
*/ |
|
286
|
|
|
public function providePermissions() |
|
287
|
|
|
{ |
|
288
|
1 |
|
return [ |
|
289
|
|
|
'JOB_MANAGE' => [ |
|
290
|
1 |
|
'name' => _t( |
|
291
|
|
|
__CLASS__ . '.JOB_MANAGE', |
|
292
|
|
|
'Manage Jobs' |
|
293
|
|
|
), |
|
294
|
|
|
'category' => _t( |
|
295
|
|
|
__CLASS__ . '.JOB_MANAGE_CATEGORY', |
|
296
|
|
|
'Jobs' |
|
297
|
|
|
), |
|
298
|
1 |
|
'help' => _t( |
|
299
|
|
|
__CLASS__ . '.JOB_MANAGE_HELP', |
|
300
|
1 |
|
'Access to add, edit and delete Jobs' |
|
301
|
|
|
), |
|
302
|
|
|
'sort' => 400, |
|
303
|
|
|
], |
|
304
|
|
|
]; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
4 |
|
* @param null $member |
|
|
|
|
|
|
309
|
|
|
* |
|
310
|
4 |
|
* @return bool|int |
|
311
|
|
|
*/ |
|
312
|
|
|
public function canEdit($member = null) |
|
313
|
|
|
{ |
|
314
|
|
|
return Permission::check('JOB_MANAGE', 'any', $member); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* @param null $member |
|
|
|
|
|
|
319
|
|
|
* |
|
320
|
|
|
* @return bool|int |
|
321
|
|
|
*/ |
|
322
|
|
|
public function canDelete($member = null) |
|
323
|
|
|
{ |
|
324
|
|
|
return Permission::check('JOB_MANAGE', 'any', $member); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* @param null $member |
|
|
|
|
|
|
329
|
|
|
* |
|
330
|
|
|
* @return bool|int |
|
331
|
|
|
*/ |
|
332
|
|
|
public function canCreate($member = null, $context = []) |
|
333
|
|
|
{ |
|
334
|
|
|
return Permission::check('JOB_MANAGE', 'any', $member); |
|
335
|
|
|
} |
|
336
|
|
|
} |
|
337
|
|
|
|