1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Created by Reliese Model. |
5
|
|
|
* Date: Thu, 12 Jul 2018 22:39:27 +0000. |
6
|
|
|
*/ |
|
|
|
|
7
|
|
|
|
8
|
|
|
namespace App\Models; |
9
|
|
|
|
10
|
|
|
use App\Events\JobSaved; |
11
|
|
|
use App\Models\JobApplication; |
12
|
|
|
use Illuminate\Notifications\Notifiable; |
13
|
|
|
use Illuminate\Support\Facades\App; |
14
|
|
|
use Illuminate\Support\Facades\Lang; |
15
|
|
|
use Jenssegers\Date\Date; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class JobPoster |
19
|
|
|
* |
20
|
|
|
* @property int $id |
21
|
|
|
* @property int $job_term_id |
22
|
|
|
* @property int $term_qty |
23
|
|
|
* @property \Jenssegers\Date\Date $open_date_time |
24
|
|
|
* @property \Jenssegers\Date\Date $close_date_time |
25
|
|
|
* @property \Jenssegers\Date\Date $start_date_time |
26
|
|
|
* @property int $department_id |
27
|
|
|
* @property int $province_id |
28
|
|
|
* @property int $salary_min |
29
|
|
|
* @property int $salary_max |
30
|
|
|
* @property int $noc |
31
|
|
|
* @property string $classification |
32
|
|
|
* @property int $security_clearance_id |
33
|
|
|
* @property int $language_requirement_id |
34
|
|
|
* @property boolean $remote_work_allowed |
35
|
|
|
* @property int $manager_id |
36
|
|
|
* @property boolean $published |
37
|
|
|
* @property \Jenssegers\Date\Date $created_at |
38
|
|
|
* @property \Jenssegers\Date\Date $updated_at |
39
|
|
|
* |
40
|
|
|
* @property int $submitted_applications_count |
41
|
|
|
* |
42
|
|
|
* @property \App\Models\Lookup\Department $department |
43
|
|
|
* @property \App\Models\Lookup\JobTerm $job_term |
44
|
|
|
* @property \App\Models\Lookup\LanguageRequirement $language_requirement |
45
|
|
|
* @property \App\Models\Manager $manager |
46
|
|
|
* @property \App\Models\Lookup\Province $province |
47
|
|
|
* @property \App\Models\Lookup\SecurityClearance $security_clearance |
48
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $criteria |
49
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_applications |
50
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_poster_key_tasks |
51
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_poster_questions |
52
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_poster_translations |
53
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $submitted_applications |
54
|
|
|
* @property \Illuminate\Database\Eloquent\Collection[ScreeningPlan] $screening_plans |
55
|
|
|
* |
56
|
|
|
* Localized Properties: |
57
|
|
|
* @property string $city |
58
|
|
|
* @property string $title |
59
|
|
|
* @property string $impact |
60
|
|
|
* @property string $branch |
61
|
|
|
* @property string $division |
62
|
|
|
* @property string $education |
63
|
|
|
* |
64
|
|
|
* Methods |
65
|
|
|
* @method boolean isOpen() |
|
|
|
|
66
|
|
|
* @method string timeRemaining() |
|
|
|
|
67
|
|
|
*/ |
|
|
|
|
68
|
|
|
class JobPoster extends BaseModel |
69
|
|
|
{ |
70
|
|
|
|
71
|
|
|
use \Dimsav\Translatable\Translatable; |
|
|
|
|
72
|
|
|
use Notifiable; |
|
|
|
|
73
|
|
|
|
74
|
|
|
const DATE_FORMAT = [ |
75
|
|
|
'en' => 'M jS, Y', |
76
|
|
|
'fr' => 'd M Y', |
77
|
|
|
]; |
78
|
|
|
const TIME_FORMAT = [ |
79
|
|
|
'en' => 'h:i A T', |
80
|
|
|
'fr' => 'H \h i T', |
81
|
|
|
]; |
82
|
|
|
const TIMEZONE = 'America/Toronto'; |
83
|
|
|
|
84
|
|
|
/** |
|
|
|
|
85
|
|
|
* @var string[] $translatedAttributes |
86
|
|
|
*/ |
87
|
|
|
public $translatedAttributes = [ |
88
|
|
|
'city', |
89
|
|
|
'title', |
90
|
|
|
'impact', |
91
|
|
|
'branch', |
92
|
|
|
'division', |
93
|
|
|
'education' |
94
|
|
|
]; |
95
|
|
|
|
96
|
|
|
/** |
|
|
|
|
97
|
|
|
* @var string[] $casts |
98
|
|
|
*/ |
99
|
|
|
protected $casts = [ |
100
|
|
|
'job_term_id' => 'int', |
101
|
|
|
'department_id' => 'int', |
102
|
|
|
'province_id' => 'int', |
103
|
|
|
'salary_min' => 'int', |
104
|
|
|
'salary_max' => 'int', |
105
|
|
|
'noc' => 'int', |
106
|
|
|
'security_clearance_id' => 'int', |
107
|
|
|
'language_requirement_id' => 'int', |
108
|
|
|
'remote_work_allowed' => 'boolean', |
109
|
|
|
'manager_id' => 'int', |
110
|
|
|
'published' => 'boolean' |
111
|
|
|
]; |
112
|
|
|
|
113
|
|
|
/** |
|
|
|
|
114
|
|
|
* @var string[] $dates |
115
|
|
|
*/ |
116
|
|
|
protected $dates = [ |
117
|
|
|
'open_date_time', |
118
|
|
|
'close_date_time', |
119
|
|
|
'start_date_time' |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
/** |
|
|
|
|
123
|
|
|
* @var string[] $fillable |
124
|
|
|
*/ |
125
|
|
|
protected $fillable = [ |
126
|
|
|
'job_term_id', |
127
|
|
|
'term_qty', |
128
|
|
|
'open_date_time', |
129
|
|
|
'close_date_time', |
130
|
|
|
'start_date_time', |
131
|
|
|
'department_id', |
132
|
|
|
'province_id', |
133
|
|
|
'salary_min', |
134
|
|
|
'salary_max', |
135
|
|
|
'noc', |
136
|
|
|
'classification', |
137
|
|
|
'security_clearance_id', |
138
|
|
|
'language_requirement_id', |
139
|
|
|
'remote_work_allowed', |
140
|
|
|
'published' |
141
|
|
|
]; |
142
|
|
|
|
143
|
|
|
/** |
|
|
|
|
144
|
|
|
* @var string[] $withCount |
145
|
|
|
*/ |
146
|
|
|
protected $withCount = ['submitted_applications']; |
147
|
|
|
|
148
|
|
|
/** |
|
|
|
|
149
|
|
|
* @var mixed[] $dispatchesEvents |
150
|
|
|
*/ |
151
|
|
|
protected $dispatchesEvents = [ |
152
|
|
|
'saved' => JobSaved::class, |
153
|
|
|
]; |
154
|
|
|
|
155
|
|
|
// @codeCoverageIgnoreStart |
156
|
|
|
|
157
|
|
|
public function department() // phpcs:ignore |
158
|
|
|
{ |
159
|
|
|
return $this->belongsTo(\App\Models\Lookup\Department::class); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function job_term() // phpcs:ignore |
163
|
|
|
{ |
164
|
|
|
return $this->belongsTo(\App\Models\Lookup\JobTerm::class); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function language_requirement() // phpcs:ignore |
168
|
|
|
{ |
169
|
|
|
return $this->belongsTo(\App\Models\Lookup\LanguageRequirement::class); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function manager() // phpcs:ignore |
173
|
|
|
{ |
174
|
|
|
return $this->belongsTo(\App\Models\Manager::class); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function province() // phpcs:ignore |
178
|
|
|
{ |
179
|
|
|
return $this->belongsTo(\App\Models\Lookup\Province::class); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function security_clearance() // phpcs:ignore |
183
|
|
|
{ |
184
|
|
|
return $this->belongsTo(\App\Models\Lookup\SecurityClearance::class); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function criteria() // phpcs:ignore |
188
|
|
|
{ |
189
|
|
|
return $this->hasMany(\App\Models\Criteria::class); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function job_applications() // phpcs:ignore |
193
|
|
|
{ |
194
|
|
|
return $this->hasMany(\App\Models\JobApplication::class); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function job_poster_key_tasks() // phpcs:ignore |
198
|
|
|
{ |
199
|
|
|
return $this->hasMany(\App\Models\JobPosterKeyTask::class); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function job_poster_questions() // phpcs:ignore |
203
|
|
|
{ |
204
|
|
|
return $this->hasMany(\App\Models\JobPosterQuestion::class); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function job_poster_translations() // phpcs:ignore |
208
|
|
|
{ |
209
|
|
|
return $this->hasMany(\App\Models\JobPosterTranslation::class); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
public function screening_plans() // phpcs:ignore |
213
|
|
|
{ |
214
|
|
|
return $this->hasMany(\App\Models\ScreeningPlan::class); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
// Artificial Relations |
218
|
|
|
|
219
|
|
|
public function submitted_applications() // phpcs:ignore |
220
|
|
|
{ |
221
|
|
|
return $this->hasMany(\App\Models\JobApplication::class)->whereHas('application_status', function ($query) { |
|
|
|
|
222
|
|
|
$query->where('name', '!=', 'draft'); |
223
|
|
|
}); |
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
// @codeCoverageIgnoreEnd |
227
|
|
|
|
228
|
|
|
// Accessors |
229
|
|
|
|
230
|
|
|
// Methods |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Formatted and localized date and time the Job Poster closes. |
234
|
|
|
* |
235
|
|
|
* @return string[] |
236
|
|
|
*/ |
237
|
6 |
|
public function applyBy() : array |
238
|
|
|
{ |
239
|
6 |
|
$localCloseDate = new Date($this->close_date_time); // This initializes the date object in UTC time |
240
|
6 |
|
$localCloseDate->setTimezone(new \DateTimeZone(self::TIMEZONE)); // Then set the time zone for display |
241
|
|
|
$displayDate = [ |
242
|
6 |
|
'date' => $localCloseDate->format(self::DATE_FORMAT[App::getLocale()]), |
243
|
6 |
|
'time' => $localCloseDate->format(self::TIME_FORMAT[App::getLocale()]) |
244
|
|
|
]; |
245
|
|
|
|
246
|
6 |
|
if (App::isLocale('fr')) { |
247
|
|
|
$displayDate['time'] = str_replace(['EST', 'EDT'], ['HNE', 'HAE'], $displayDate['time']); |
248
|
|
|
} |
249
|
|
|
|
250
|
6 |
|
return $displayDate; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Check if a Job Poster is open for applications. |
255
|
|
|
* |
256
|
|
|
* @return boolean |
257
|
|
|
*/ |
258
|
6 |
|
public function isOpen() : bool |
259
|
|
|
{ |
260
|
6 |
|
return $this->published |
261
|
6 |
|
&& $this->open_date_time->isPast() |
262
|
6 |
|
&& $this->close_date_time->isFuture(); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Calculate the remaining time a Job Poster is open. |
267
|
|
|
* |
268
|
|
|
* @return string |
269
|
|
|
*/ |
270
|
2 |
|
public function timeRemaining() : string |
271
|
|
|
{ |
272
|
2 |
|
$interval = $this->close_date_time->diff(Date::now()); |
273
|
|
|
|
274
|
2 |
|
$d = $interval->d; |
275
|
2 |
|
$h = $interval->h; |
276
|
2 |
|
$m = $interval->i; |
277
|
2 |
|
$s = $interval->s; |
278
|
|
|
|
279
|
2 |
|
if ($d > 0) { |
280
|
2 |
|
$unit = 'day'; |
281
|
2 |
|
$count = $d; |
282
|
2 |
|
} elseif ($h > 0) { |
283
|
2 |
|
$unit = 'hour'; |
284
|
2 |
|
$count = $h; |
285
|
2 |
|
} elseif ($m > 0) { |
286
|
2 |
|
$unit = 'minute'; |
287
|
2 |
|
$count = $m; |
288
|
|
|
} else { |
289
|
2 |
|
$unit = 'second'; |
290
|
2 |
|
$count = $s; |
291
|
|
|
} |
292
|
|
|
|
293
|
2 |
|
$key = "common/time.$unit"; |
294
|
|
|
|
295
|
2 |
|
return Lang::choice($key, $count); |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
|