1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coyote\Http\Controllers\Job; |
4
|
|
|
|
5
|
|
|
use Coyote\Http\Controllers\Controller; |
6
|
|
|
use Coyote\Http\Factories\MailFactory; |
7
|
|
|
use Coyote\Http\Requests\ApplicationRequest; |
8
|
|
|
use Coyote\Job; |
9
|
|
|
use Coyote\Notifications\Job\ApplicationConfirmationNotification; |
10
|
|
|
use Coyote\Notifications\Job\ApplicationSentNotification; |
11
|
|
|
use Coyote\Services\UrlBuilder; |
12
|
|
|
use Illuminate\Filesystem\FilesystemManager; |
13
|
|
|
use Illuminate\Http\Request; |
14
|
|
|
use Coyote\Services\Stream\Activities\Create as Stream_Create; |
15
|
|
|
use Coyote\Services\Stream\Objects\Job as Stream_Job; |
16
|
|
|
use Coyote\Services\Stream\Objects\Application as Stream_Application; |
17
|
|
|
use Illuminate\Support\Str; |
18
|
|
|
|
19
|
|
|
class ApplicationController extends Controller |
20
|
|
|
{ |
21
|
|
|
use MailFactory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param Job $job |
25
|
|
|
* @return \Illuminate\View\View |
26
|
|
|
*/ |
27
|
|
|
public function submit($job) |
28
|
|
|
{ |
29
|
|
|
abort_if(!$job->enable_apply, 404); |
30
|
|
|
|
31
|
|
|
$this->breadcrumb->push([ |
32
|
|
|
'Praca' => route('job.home'), |
33
|
|
|
$job->title => UrlBuilder::job($job), |
34
|
|
|
'Aplikuj na to stanowisko pracy' => null |
35
|
|
|
]); |
36
|
|
|
|
37
|
|
|
$application = new Job\Application(); |
38
|
|
|
|
39
|
|
|
if ($this->userId) { |
40
|
|
|
$application->email = $this->auth->email; |
41
|
|
|
$application->github = $this->auth->github; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// set default message |
45
|
|
|
$application->text = view('job.partials.application', compact('job'))->render(); |
|
|
|
|
46
|
|
|
|
47
|
|
|
if ($this->getSetting('job.application')) { |
48
|
|
|
$application->forceFill((array) json_decode($this->getSetting('job.application'))); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->view('job.application', compact('job', 'application'))->with([ |
52
|
|
|
'subscribed' => $this->userId ? $job->subscribers()->forUser($this->userId)->exists() : false |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param Job $job |
58
|
|
|
* @param ApplicationRequest $request |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function save(Job $job, ApplicationRequest $request) |
62
|
|
|
{ |
63
|
|
|
$application = $this->transaction(function () use ($job, $request) { |
64
|
|
|
$target = (new Stream_Job)->map($job); |
65
|
|
|
|
66
|
|
|
/** @var \Coyote\Job\Application $application */ |
67
|
|
|
$application = $job->applications()->create($request->all() + ['guest_id' => $this->guestId]); |
68
|
|
|
$this->setSetting('job.application', $request->get('remember') ? json_encode($request->all()) : ''); |
69
|
|
|
|
70
|
|
|
stream(Stream_Create::class, new Stream_Application(['displayName' => $request->input('name')]), $target); |
71
|
|
|
|
72
|
|
|
return $application; |
73
|
|
|
}); |
74
|
|
|
|
75
|
|
|
$job->notify(new ApplicationSentNotification($application)); |
|
|
|
|
76
|
|
|
$application->notify(new ApplicationConfirmationNotification()); |
77
|
|
|
|
78
|
|
|
session()->flash('success', 'Zgłoszenie zostało prawidłowo wysłane.'); |
79
|
|
|
|
80
|
|
|
return UrlBuilder::job($job); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Upload cv/resume |
85
|
|
|
* |
86
|
|
|
* @param Request $request |
87
|
|
|
* @return \Illuminate\Http\JsonResponse |
88
|
|
|
*/ |
89
|
|
|
public function upload(Request $request) |
90
|
|
|
{ |
91
|
|
|
$this->validate($request, [ |
92
|
|
|
// only 5 MB file size limit. otherwise postfix may not handle it properly. |
93
|
|
|
'cv' => 'max:' . (5 * 1024) . '|mimes:pdf,doc,docx,rtf' |
94
|
|
|
]); |
95
|
|
|
|
96
|
|
|
$filename = uniqid() . '_' . Str::ascii($request->file('cv')->getClientOriginalName()); |
97
|
|
|
$request->file('cv')->storeAs('cv', $filename, 'local'); |
98
|
|
|
|
99
|
|
|
return response()->json([ |
100
|
|
|
'filename' => $filename, |
101
|
|
|
'name' => $request->file('cv')->getClientOriginalName() |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param FilesystemManager $filesystem |
107
|
|
|
* @param Job $job |
108
|
|
|
* @param $id |
109
|
|
|
* @return mixed |
110
|
|
|
*/ |
111
|
|
|
public function downloadApplication(FilesystemManager $filesystem, Job $job, $id) |
112
|
|
|
{ |
113
|
|
|
abort_if($job->user_id !== $this->userId, 403); |
114
|
|
|
|
115
|
|
|
/** @var \Coyote\Job\Application $application */ |
116
|
|
|
$application = $job->applications()->find($id); |
117
|
|
|
|
118
|
|
|
return $filesystem->disk('local')->download('cv/' . $application->cv, $application->realFilename()); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.