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 = [ |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
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() |
|||||
0 ignored issues
–
show
The method
getTitle() does not exist on Dynamic\Jobs\Page\JobController . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
46 | ), |
||||||
47 | 2 | 'FirstName' |
|||||
0 ignored issues
–
show
'FirstName' of type string is incompatible with the type SilverStripe\Forms\FormField expected by parameter $item of SilverStripe\Forms\FieldList::insertBefore() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
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) |
|||||
0 ignored issues
–
show
The parameter
$data is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
87 | { |
||||||
88 | 1 | $entry = new JobSubmission(); |
|||||
89 | 1 | $form->saveInto($entry); |
|||||
90 | |||||||
91 | 1 | $entry->JobID = $this->ID; |
|||||
0 ignored issues
–
show
The property
JobID does not exist on Dynamic\Jobs\Model\JobSubmission . Since you implemented __set , consider adding a @property annotation.
![]() |
|||||||
92 | |||||||
93 | // adds relation to uploaded file |
||||||
94 | /** @var FileField $fileField */ |
||||||
95 | 1 | $fileField = $form->Fields()->fieldByName('Resume'); |
|||||
0 ignored issues
–
show
Are you sure the assignment to
$fileField is correct as $form->Fields()->fieldByName('Resume') targeting SilverStripe\Forms\FieldList::fieldByName() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||||
96 | 1 | if ($fileField !== null) { |
|||||
97 | 1 | $file = $fileField->getUpload()->getFile(); |
|||||
98 | 1 | if ($file !== null && $file->exists()) { |
|||||
99 | $file->ShowInSearch = 0; |
||||||
0 ignored issues
–
show
|
|||||||
100 | $file->write(); |
||||||
101 | $entry->ResumeID = $file->ID; |
||||||
0 ignored issues
–
show
The property
ResumeID does not exist on Dynamic\Jobs\Model\JobSubmission . Since you implemented __set , consider adding a @property annotation.
![]() |
|||||||
102 | } |
||||||
103 | } |
||||||
104 | |||||||
105 | 1 | if ($entry->write()) { |
|||||
106 | 1 | $to = $this->parent()->EmailRecipient; |
|||||
0 ignored issues
–
show
The method
parent() does not exist on Dynamic\Jobs\Page\JobController . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
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 | |||||||
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 |