|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Utils\Recruitments; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Requests\RecruitmentCloseRequest; |
|
6
|
|
|
use App\Http\Requests\RecruitmentUpdateRequest; |
|
7
|
|
|
use App\Models\Recruitment; |
|
8
|
|
|
use App\Utils\SourceCreator; |
|
9
|
|
|
|
|
10
|
|
|
class RecruitmentCreator |
|
11
|
|
|
{ |
|
12
|
|
|
const DEFAULT_SOURCE_NAME = 'Corporate website'; |
|
13
|
|
|
|
|
14
|
|
|
public static function create(array $data): Recruitment |
|
15
|
|
|
{ |
|
16
|
|
|
$recruitment = new Recruitment(); |
|
17
|
|
|
$recruitment->name = $data['name']; |
|
18
|
|
|
$recruitment->job_title = $data['job_title']; |
|
19
|
|
|
$recruitment->notification_email = $data['notification_email']; |
|
20
|
|
|
$recruitment->is_draft = $data['is_draft'] ?? true; |
|
21
|
|
|
$recruitment->save(); |
|
22
|
|
|
|
|
23
|
|
|
self::seedData($recruitment); |
|
24
|
|
|
|
|
25
|
|
|
return Recruitment::with('sources')->with('predefinedMessages')->where('id', $recruitment->id)->get()->first(); |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
private static function seedData(Recruitment $recruitment) |
|
29
|
|
|
{ |
|
30
|
|
|
SourceCreator::create(['recruitment_id' => $recruitment->id, 'name' => self::defaultSourceName()]); |
|
31
|
|
|
|
|
32
|
|
|
$connection = 'tenant'; |
|
33
|
|
|
|
|
34
|
|
|
$seeder = new \StagesSeeder($connection); |
|
35
|
|
|
$seeder->setRecruitment($recruitment)->run(); |
|
36
|
|
|
|
|
37
|
|
|
$seeder = new \PredefinedMessagesSeeder($connection); |
|
38
|
|
|
$seeder->setRecruitment($recruitment)->run(); |
|
39
|
|
|
|
|
40
|
|
|
$seeder = new \FormFieldsSeeder($connection); |
|
41
|
|
|
$seeder->setRecruitment($recruitment)->run(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public static function defaultSourceName(): string |
|
45
|
|
|
{ |
|
46
|
|
|
return self::DEFAULT_SOURCE_NAME; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public static function updateRecruitment($recruitmentId, RecruitmentUpdateRequest $request) |
|
50
|
|
|
{ |
|
51
|
|
|
$recruitment = Recruitment::findOrFail($recruitmentId); |
|
52
|
|
|
$input = $request->validated(); |
|
53
|
|
|
$recruitment->fill($input)->save(); |
|
54
|
|
|
|
|
55
|
|
|
return $recruitment; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public static function close($recruitmentId, RecruitmentCloseRequest $request) |
|
59
|
|
|
{ |
|
60
|
|
|
$recruitment = Recruitment::findOrFail($recruitmentId); |
|
61
|
|
|
$recruitment->state = $request->get('keep_form_open') ? Recruitment::STATE_FINISHED : Recruitment::STATE_CLOSED; |
|
|
|
|
|
|
62
|
|
|
$recruitment->save(); |
|
63
|
|
|
|
|
64
|
|
|
return $recruitment; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function reopen($recruitmentId) |
|
68
|
|
|
{ |
|
69
|
|
|
$recruitment = Recruitment::findOrFail($recruitmentId); |
|
70
|
|
|
$recruitment->state = Recruitment::STATE_PUBLISHED; |
|
|
|
|
|
|
71
|
|
|
$recruitment->save(); |
|
72
|
|
|
|
|
73
|
|
|
return $recruitment; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|