1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use App\Models\Applicant; |
4
|
|
|
use App\Models\Assessment; |
5
|
|
|
use App\Models\Course; |
6
|
|
|
use App\Models\Degree; |
7
|
|
|
use App\Models\ExperienceSkill; |
8
|
|
|
use App\Models\ExperienceWork; |
9
|
|
|
use App\Models\HrAdvisor; |
10
|
|
|
use App\Models\JobApplication; |
11
|
|
|
use App\Models\JobPoster; |
12
|
|
|
use App\Models\Manager; |
13
|
|
|
use App\Models\Reference; |
14
|
|
|
use App\Models\User; |
15
|
|
|
use App\Models\WorkExperience; |
16
|
|
|
use Illuminate\Database\Seeder; |
17
|
|
|
|
18
|
|
|
class DevSeeder extends Seeder // phpcs:ignore |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* This seeder uses this email for an admin user. |
22
|
|
|
* Note: all seeded users have 'password' for a password. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $adminEmail = '[email protected]'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* This seeder connects all manager objects to this user. |
30
|
|
|
* Note: all seeded users have 'password' for a password. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $managerEmail = '[email protected]'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* This seeder attaches all applicant objects to this user. |
38
|
|
|
* Note: all seeded users have 'password' for a password. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $applicantEmail = '[email protected]'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* This seeder attaches all hr_advisor objects to this user. |
46
|
|
|
* Note: all seeded users have 'password' for a password. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $hrAdvisorEmail = '[email protected]'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Note: all seeded users have 'password' for a password. |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $newApplicantEmail = '[email protected]'; |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Run the database seeds. |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function run(): void |
66
|
|
|
{ |
67
|
|
|
$adminUser = User::where('email', $this->adminEmail)->first(); |
68
|
|
|
if ($adminUser === null) { |
69
|
|
|
$adminUser = factory(User::class)->state('admin')->create(['email' => $this->adminEmail]); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$hrUser = User::where('email', $this->hrAdvisorEmail)->first(); |
73
|
|
|
if ($hrUser === null) { |
74
|
|
|
$hrUser = factory(User::class)->state('hr_advisor')->create([ |
75
|
|
|
'email' => $this->hrAdvisorEmail, |
76
|
|
|
]); |
77
|
|
|
$hrUser->hr_advisor()->save(factory(HrAdvisor::class)->create([ |
78
|
|
|
'user_id' => $hrUser->id, |
79
|
|
|
])); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$managerUser = User::where('email', $this->managerEmail)->first(); |
83
|
|
|
// Create the test manager if it does not exist yet. |
84
|
|
|
if ($managerUser === null) { |
85
|
|
|
$managerUser = factory(User::class)->state('upgradedManager')->create(['email' => $this->managerEmail]); |
86
|
|
|
$managerUser->manager()->save(factory(Manager::class)->create([ |
87
|
|
|
'user_id' => $managerUser->id |
88
|
|
|
])); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
factory(JobPoster::class, 3)->state('live')->create([ |
92
|
|
|
'manager_id' => $managerUser->manager->id |
93
|
|
|
])->each(function ($job): void { |
94
|
|
|
$job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
|
|
|
|
95
|
|
|
'job_poster_id' => $job->id |
96
|
|
|
]); |
97
|
|
|
// Then create one application with a priority user. |
98
|
|
|
$job->job_applications()->save(factory(JobApplication::class)->create([ |
99
|
|
|
'job_poster_id' => $job->id, |
100
|
|
|
'applicant_id' => factory(Applicant::class)->create([ |
101
|
|
|
'user_id' => factory(User::class)->state('priority')->create()->id |
102
|
|
|
])->id |
103
|
|
|
])); |
104
|
|
|
}); |
105
|
|
|
factory(JobPoster::class, 3)->state('closed')->create([ |
106
|
|
|
'manager_id' => $managerUser->manager->id |
107
|
|
|
])->each(function ($job): void { |
108
|
|
|
$job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
|
|
|
|
109
|
|
|
'job_poster_id' => $job->id |
110
|
|
|
]); |
111
|
|
|
// Then create one application with a priority user. |
112
|
|
|
$job->job_applications()->save(factory(JobApplication::class)->create([ |
113
|
|
|
'job_poster_id' => $job->id, |
114
|
|
|
'applicant_id' => factory(Applicant::class)->create([ |
115
|
|
|
'user_id' => factory(User::class)->state('priority')->create()->id |
116
|
|
|
])->id |
117
|
|
|
])); |
118
|
|
|
}); |
119
|
|
|
factory(JobPoster::class, 3)->state('draft')->create([ |
120
|
|
|
'manager_id' => $managerUser->manager->id |
121
|
|
|
]); |
122
|
|
|
factory(JobPoster::class, 3)->state('review_requested')->create([ |
123
|
|
|
'manager_id' => $managerUser->manager->id |
124
|
|
|
]); |
125
|
|
|
|
126
|
|
|
// Create a Job Poster with an Assessment Plan. |
127
|
|
|
$jobWithAssessment = factory(JobPoster::class)->state('draft')->create([ |
128
|
|
|
'manager_id' => $managerUser->manager->id, |
129
|
|
|
]); |
130
|
|
|
foreach ($jobWithAssessment->criteria as $criterion) { |
131
|
|
|
// Create an assessment for each criterion. |
132
|
|
|
factory(Assessment::class)->state('withRatingGuide')->create([ |
133
|
|
|
'criterion_id' => $criterion->id, |
134
|
|
|
]); |
135
|
|
|
}; |
136
|
|
|
|
137
|
|
|
$applicantUser = User::where('email', $this->applicantEmail)->first(); |
138
|
|
|
if ($applicantUser === null) { |
139
|
|
|
$applicantUser = factory(User::class)->state('applicant')->create([ |
140
|
|
|
'email' => $this->applicantEmail |
141
|
|
|
]); |
142
|
|
|
$applicantUser->applicant()->save(factory(Applicant::class)->create([ |
143
|
|
|
'user_id' => $applicantUser->id |
144
|
|
|
])); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
$newApplicantUser = User::where('email', $this->newApplicantEmail)->first(); |
148
|
|
|
if ($newApplicantUser === null) { |
149
|
|
|
$newApplicantUser = factory(User::class)->state('applicant')->create([ |
150
|
|
|
'email' => $this->newApplicantEmail |
151
|
|
|
]); |
152
|
|
|
$newApplicantUser->applicant()->save(factory(Applicant::class)->create([ |
153
|
|
|
'user_id' => $newApplicantUser->id |
154
|
|
|
])); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
// Add to application profile. |
158
|
|
|
$applicantUser->applicant->references()->saveMany(factory(Reference::class, 3)->create([ |
159
|
|
|
'referenceable_id' => $applicantUser->applicant->id |
160
|
|
|
])); |
161
|
|
|
$applicantUser->applicant->degrees()->saveMany(factory(Degree::class, 2)->create([ |
162
|
|
|
'degreeable_id' => $applicantUser->applicant->id |
163
|
|
|
])); |
164
|
|
|
$applicantUser->applicant->courses()->saveMany(factory(Course::class, 3)->create([ |
165
|
|
|
'courseable_id' => $applicantUser->applicant->id |
166
|
|
|
])); |
167
|
|
|
$applicantUser->applicant->work_experiences()->saveMany(factory(WorkExperience::class, 3)->create([ |
168
|
|
|
'experienceable_id' => $applicantUser->applicant->id |
169
|
|
|
])); |
170
|
|
|
|
171
|
|
|
// Create several applications for test user. |
172
|
|
|
$applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 3)->create([ |
173
|
|
|
'applicant_id' => $applicantUser->applicant->id, |
174
|
|
|
])); |
175
|
|
|
$applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 2)->state('draft')->create([ |
176
|
|
|
'applicant_id' => $applicantUser->applicant->id, |
177
|
|
|
])); |
178
|
|
|
|
179
|
|
|
// Ensure there are several jobs the hr advisor can claim. |
180
|
|
|
$hrDepartment = $hrUser->department_id; |
181
|
|
|
factory(JobPoster::class)->states(['byUpgradedManager', 'draft']) |
182
|
|
|
->create(['department_id' => $hrDepartment]); |
183
|
|
|
factory(JobPoster::class)->states(['byUpgradedManager', 'review_requested']) |
184
|
|
|
->create(['department_id' => $hrDepartment]); |
185
|
|
|
$hrOpenJob = factory(JobPoster::class)->states(['byUpgradedManager', 'live']) |
186
|
|
|
->create(['department_id' => $hrDepartment]); |
187
|
|
|
$hrClosedJob = factory(JobPoster::class)->states(['byUpgradedManager', 'closed']) |
188
|
|
|
->create(['department_id' => $hrDepartment]); |
189
|
|
|
|
190
|
|
|
$hrOpenJob->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
191
|
|
|
'job_poster_id' => $hrOpenJob->id |
192
|
|
|
]); |
193
|
|
|
$hrClosedJob->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
194
|
|
|
'job_poster_id' => $hrClosedJob->id |
195
|
|
|
]); |
196
|
|
|
|
197
|
|
|
// Ensure applicant user has some Experience relevant to a job |
198
|
|
|
foreach ($applicantUser->applicant->job_applications->where('application_status_id', 1) as $application) { |
199
|
|
|
$job = $application->job_poster; |
200
|
|
|
$criterion = $job->criteria->first(); |
201
|
|
|
if ($criterion) { |
202
|
|
|
$work = factory(ExperienceWork::class)->create([ |
203
|
|
|
'experienceable_id' => $application->applicant_id, |
204
|
|
|
'experienceable_type' => 'applicant', |
205
|
|
|
]); |
206
|
|
|
factory(ExperienceSkill::class)->create([ |
207
|
|
|
'skill_id' => $criterion->skill_id, |
208
|
|
|
'experience_type' => 'experience_work', |
209
|
|
|
'experience_id' => $work->id, |
210
|
|
|
]); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|