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