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