|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Utils\Candidates; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Requests\CandidatesCreateRequest; |
|
6
|
|
|
use App\Models\Candidate; |
|
7
|
|
|
use App\Models\Recruitment; |
|
8
|
|
|
use App\Models\Source; |
|
9
|
|
|
use App\Services\TenantManager; |
|
10
|
|
|
use App\Utils\StageHelper; |
|
11
|
|
|
|
|
12
|
|
|
class CandidateCreator |
|
13
|
|
|
{ |
|
14
|
|
|
public static function createCandidate(CandidatesCreateRequest $request, TenantManager $tenantManager) |
|
15
|
|
|
{ |
|
16
|
|
|
$key = $request->get('key'); |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
if (!empty($key)) { |
|
19
|
|
|
$source = Source::where('key', $key)->firstOrFail(); |
|
20
|
|
|
if ($source) { |
|
|
|
|
|
|
21
|
|
|
$recruitment = $source->recruitment; |
|
22
|
|
|
} |
|
23
|
|
|
} else { |
|
24
|
|
|
//TODO podanie rectruitment_id powinno być dozwolone tylko z poziomu panelu, a nie publicznej rekrutacji |
|
25
|
|
|
$recruitment_id = $request->get('recruitment_id'); |
|
26
|
|
|
$recruitment = Recruitment::find($recruitment_id); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if (empty($recruitment)) { |
|
30
|
|
|
return false; //TODO walidacja powinna być wyżej (chyba chodzilo mi o to, ze gdzies na poziomie requestu albo controllera) |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if ($request->file) { |
|
|
|
|
|
|
34
|
|
|
$path_to_cv = $request->file->store($tenantManager->getTenant()->subdomain.'/'.$recruitment->id, 's3'); |
|
|
|
|
|
|
35
|
|
|
} else { |
|
36
|
|
|
$path_to_cv = ''; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$candidate = new Candidate(); |
|
40
|
|
|
$candidate->name = $request->get('name'); |
|
41
|
|
|
$candidate->email = $request->get('email'); |
|
42
|
|
|
$candidate->phone_number = $request->get('phone_number'); |
|
43
|
|
|
$candidate->future_agreement = (bool) data_get($request->validated(), 'future_agreement'); |
|
44
|
|
|
$candidate->source_recruitment_id = $request->get('source_recruitment_id'); |
|
45
|
|
|
$candidate->stage_id = StageHelper::getFirstStage($recruitment->id)->id; |
|
46
|
|
|
$candidate->path_to_cv = $path_to_cv; |
|
47
|
|
|
$candidate->source_id = !empty($source) ? $source->id : null; |
|
48
|
|
|
$candidate->recruitment_id = $recruitment->id; |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$customData = []; |
|
51
|
|
|
foreach ($recruitment->formFields as $field) { |
|
52
|
|
|
if (!$field->system) { |
|
53
|
|
|
$customData[] = ['id' => $field->id, 'label' => $field->label, 'value' => $request->get($field->name)]; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
$candidate->custom_fields = json_encode($customData); |
|
57
|
|
|
|
|
58
|
|
|
$candidate->save(); |
|
59
|
|
|
$candidate = Candidate::find($candidate->id); |
|
60
|
|
|
|
|
61
|
|
|
return $candidate; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function fakeCandidate($recruitment) |
|
65
|
|
|
{ |
|
66
|
|
|
$candidate = new Candidate(); |
|
67
|
|
|
$candidate->name = 'Jan Nowak'; |
|
68
|
|
|
$candidate->email = '[email protected]'; |
|
69
|
|
|
$candidate->phone_number = '+48 600 600 600'; |
|
70
|
|
|
$candidate->future_agreement = false; |
|
71
|
|
|
$candidate->recruitment_id = $recruitment->id; |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
return $candidate; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.