1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Jobs\Page; |
4
|
|
|
|
5
|
|
|
use Dynamic\Jobs\Model\JobSubmission; |
6
|
|
|
use PageController; |
7
|
|
|
use SilverStripe\Control\Controller; |
8
|
|
|
use SilverStripe\Control\Email\Email; |
9
|
|
|
use SilverStripe\Forms\FieldList; |
10
|
|
|
use SilverStripe\Forms\FileField; |
11
|
|
|
use SilverStripe\Forms\Form; |
12
|
|
|
use SilverStripe\Forms\FormAction; |
13
|
|
|
use SilverStripe\Forms\HiddenField; |
14
|
|
|
use SilverStripe\Forms\ReadonlyField; |
15
|
|
|
use SilverStripe\Forms\RequiredFields; |
16
|
|
|
use SilverStripe\View\ViewableData_Customised; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class JobController |
20
|
|
|
* @package Dynamic\Jobs\Model |
21
|
|
|
*/ |
22
|
|
|
class JobController extends PageController |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private static $allowed_actions = [ |
|
|
|
|
28
|
|
|
'apply', |
29
|
|
|
'JobApp', |
30
|
|
|
'complete', |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return ViewableData_Customised |
35
|
|
|
*/ |
36
|
2 |
|
public function apply() |
37
|
|
|
{ |
38
|
2 |
|
$Form = $this->JobApp(); |
39
|
|
|
|
40
|
2 |
|
$Form->Fields()->insertBefore( |
41
|
2 |
|
ReadonlyField::create( |
42
|
2 |
|
'PositionName', |
43
|
2 |
|
'Position', |
44
|
2 |
|
$this->getTitle() |
|
|
|
|
45
|
|
|
), |
46
|
2 |
|
'FirstName' |
|
|
|
|
47
|
|
|
); |
48
|
2 |
|
$Form->Fields()->push(HiddenField::create('JobID', 'JobID', $this->ID)); |
49
|
|
|
|
50
|
2 |
|
$page = $this->customise([ |
51
|
2 |
|
'Form' => $Form, |
52
|
|
|
]); |
53
|
|
|
|
54
|
2 |
|
return $page; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return Form |
59
|
|
|
*/ |
60
|
3 |
|
public function JobApp() |
61
|
|
|
{ |
62
|
3 |
|
$App = singleton(JobSubmission::class); |
63
|
|
|
|
64
|
3 |
|
$fields = $App->getFrontEndFields(); |
65
|
|
|
|
66
|
3 |
|
$actions = FieldList::create( |
67
|
3 |
|
new FormAction('doApply', 'Apply') |
68
|
|
|
); |
69
|
|
|
|
70
|
3 |
|
$required = new RequiredFields([ |
71
|
3 |
|
'FirstName', |
72
|
|
|
'LastName', |
73
|
|
|
'Email', |
74
|
|
|
'Phone', |
75
|
|
|
]); |
76
|
|
|
|
77
|
|
|
|
78
|
3 |
|
return Form::create($this, "JobApp", $fields, $actions, $required); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $data |
83
|
|
|
* @param $form |
84
|
|
|
*/ |
85
|
1 |
|
public function doApply(array $data, Form $form) |
|
|
|
|
86
|
|
|
{ |
87
|
1 |
|
$entry = new JobSubmission(); |
88
|
1 |
|
$form->saveInto($entry); |
89
|
|
|
|
90
|
1 |
|
$entry->JobID = $this->ID; |
|
|
|
|
91
|
|
|
|
92
|
|
|
// adds relation to uploaded file |
93
|
|
|
/** @var FileField $fileField */ |
94
|
1 |
|
$fileField = $form->Fields()->fieldByName('Resume'); |
95
|
1 |
|
if ($fileField !== null) { |
96
|
1 |
|
$file = $fileField->getUpload()->getFile(); |
97
|
1 |
|
if ($file !== null && $file->exists()) { |
98
|
|
|
$entry->ResumeID = $file->ID; |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
if ($entry->write()) { |
103
|
1 |
|
$to = $this->parent()->EmailRecipient; |
|
|
|
|
104
|
1 |
|
$from = $this->parent()->FromAddress; |
105
|
1 |
|
$subject = $this->parent()->EmailSubject; |
106
|
1 |
|
$body = $this->parent()->EmailMessage; |
107
|
|
|
|
108
|
1 |
|
$email = new Email($from, $to, $subject, $body); |
109
|
1 |
|
$email->setHTMLTemplate('Dynamic\Jobs\Email\JobSubmission') |
110
|
1 |
|
->setData( |
111
|
1 |
|
JobSubmission::get() |
112
|
1 |
|
->byID($entry->ID) |
113
|
|
|
); |
114
|
|
|
|
115
|
1 |
|
$email->send(); |
116
|
|
|
|
117
|
1 |
|
$this->redirect(Controller::join_links($this->Link(), 'complete')); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return ViewableData_Customised |
123
|
|
|
*/ |
124
|
1 |
|
public function complete() |
125
|
|
|
{ |
126
|
1 |
|
return $this->customise([]); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|