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\Lang; |
14
|
|
|
use Jenssegers\Date\Date; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class JobPoster |
18
|
|
|
* |
19
|
|
|
* @property int $id |
20
|
|
|
* @property int $job_term_id |
21
|
|
|
* @property int $term_qty |
22
|
|
|
* @property \Jenssegers\Date\Date $open_date_time |
23
|
|
|
* @property \Jenssegers\Date\Date $close_date_time |
24
|
|
|
* @property \Jenssegers\Date\Date $start_date_time |
25
|
|
|
* @property \Jenssegers\Date\Date $review_requested_at |
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
|
|
|
use \Dimsav\Translatable\Translatable; |
|
|
|
|
71
|
|
|
use Notifiable; |
|
|
|
|
72
|
|
|
|
73
|
|
|
public $translatedAttributes = ['city', 'title', 'impact', 'branch', 'division', 'education']; |
74
|
|
|
protected $casts = [ |
75
|
|
|
'job_term_id' => 'int', |
76
|
|
|
'department_id' => 'int', |
77
|
|
|
'province_id' => 'int', |
78
|
|
|
'salary_min' => 'int', |
79
|
|
|
'salary_max' => 'int', |
80
|
|
|
'noc' => 'int', |
81
|
|
|
'security_clearance_id' => 'int', |
82
|
|
|
'language_requirement_id' => 'int', |
83
|
|
|
'remote_work_allowed' => 'boolean', |
84
|
|
|
'manager_id' => 'int', |
85
|
|
|
'published' => 'boolean' |
86
|
|
|
]; |
87
|
|
|
protected $dates = [ |
88
|
|
|
'open_date_time', |
89
|
|
|
'close_date_time', |
90
|
|
|
'start_date_time', |
91
|
|
|
'review_requested_at' |
92
|
|
|
]; |
93
|
|
|
protected $fillable = [ |
94
|
|
|
'job_term_id', |
95
|
|
|
'term_qty', |
96
|
|
|
'open_date_time', |
97
|
|
|
'close_date_time', |
98
|
|
|
'start_date_time', |
99
|
|
|
'department_id', |
100
|
|
|
'province_id', |
101
|
|
|
'salary_min', |
102
|
|
|
'salary_max', |
103
|
|
|
'noc', |
104
|
|
|
'classification', |
105
|
|
|
'security_clearance_id', |
106
|
|
|
'language_requirement_id', |
107
|
|
|
'remote_work_allowed', |
108
|
|
|
'published' |
109
|
|
|
]; |
110
|
|
|
protected $withCount = ['submitted_applications']; |
111
|
|
|
|
112
|
|
|
protected $dispatchesEvents = [ |
113
|
|
|
'saved' => JobSaved::class, |
114
|
|
|
]; |
115
|
|
|
|
116
|
6 |
|
public function department() { |
|
|
|
|
117
|
6 |
|
return $this->belongsTo(\App\Models\Lookup\Department::class); |
118
|
|
|
} |
119
|
|
|
|
120
|
6 |
|
public function job_term() { |
|
|
|
|
121
|
6 |
|
return $this->belongsTo(\App\Models\Lookup\JobTerm::class); |
122
|
|
|
} |
123
|
|
|
|
124
|
6 |
|
public function language_requirement() { |
|
|
|
|
125
|
6 |
|
return $this->belongsTo(\App\Models\Lookup\LanguageRequirement::class); |
126
|
|
|
} |
127
|
|
|
|
128
|
16 |
|
public function manager() { |
|
|
|
|
129
|
16 |
|
return $this->belongsTo(\App\Models\Manager::class); |
130
|
|
|
} |
131
|
|
|
|
132
|
6 |
|
public function province() { |
|
|
|
|
133
|
6 |
|
return $this->belongsTo(\App\Models\Lookup\Province::class); |
134
|
|
|
} |
135
|
|
|
|
136
|
6 |
|
public function security_clearance() { |
|
|
|
|
137
|
6 |
|
return $this->belongsTo(\App\Models\Lookup\SecurityClearance::class); |
138
|
|
|
} |
139
|
|
|
|
140
|
12 |
|
public function criteria() { |
|
|
|
|
141
|
12 |
|
return $this->hasMany(\App\Models\Criteria::class); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function job_applications() { |
|
|
|
|
145
|
|
|
return $this->hasMany(\App\Models\JobApplication::class); |
146
|
|
|
} |
147
|
|
|
|
148
|
12 |
|
public function job_poster_key_tasks() { |
|
|
|
|
149
|
12 |
|
return $this->hasMany(\App\Models\JobPosterKeyTask::class); |
150
|
|
|
} |
151
|
|
|
|
152
|
12 |
|
public function job_poster_questions() { |
|
|
|
|
153
|
12 |
|
return $this->hasMany(\App\Models\JobPosterQuestion::class); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function job_poster_translations() { |
|
|
|
|
157
|
|
|
return $this->hasMany(\App\Models\JobPosterTranslation::class); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function screening_plans() |
|
|
|
|
161
|
|
|
{ |
162
|
|
|
return $this->hasMany(\App\Models\ScreeningPlan::class); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
// Artificial Relations |
166
|
|
|
|
167
|
16 |
|
public function submitted_applications() { |
|
|
|
|
168
|
|
|
return $this->hasMany(\App\Models\JobApplication::class)->whereHas('application_status', function ($query) { |
|
|
|
|
169
|
16 |
|
$query->where('name', '!=', 'draft'); |
170
|
16 |
|
}); |
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
// Accessors |
174
|
|
|
|
175
|
|
|
// Methods |
176
|
|
|
|
177
|
8 |
|
public function isOpen() { |
|
|
|
|
178
|
8 |
|
return $this->published |
179
|
8 |
|
&& $this->open_date_time->isPast() |
180
|
8 |
|
&& $this->close_date_time->isFuture(); |
181
|
|
|
} |
182
|
|
|
|
183
|
4 |
|
public function isClosed() { |
|
|
|
|
184
|
4 |
|
return $this->published |
185
|
4 |
|
&& $this->open_date_time->isPast() |
186
|
4 |
|
&& $this->close_date_time->isPast(); |
187
|
|
|
} |
188
|
|
|
|
189
|
6 |
|
public function timeRemaining() { |
|
|
|
|
190
|
6 |
|
$interval = $this->close_date_time->diff(Date::now()); |
191
|
|
|
|
192
|
6 |
|
$d = $interval->d; |
193
|
6 |
|
$h = $interval->h; |
194
|
6 |
|
$m = $interval->i; |
195
|
6 |
|
$s = $interval->s; |
196
|
|
|
|
197
|
6 |
|
if ($d > 0) { |
198
|
6 |
|
$unit = 'day'; |
199
|
6 |
|
$count = $d; |
200
|
2 |
|
} else if ($h > 0) { |
201
|
2 |
|
$unit = 'hour'; |
202
|
2 |
|
$count = $h; |
203
|
|
|
} else if ($m > 0) { |
204
|
|
|
$unit = 'minute'; |
205
|
|
|
$count = $m; |
206
|
|
|
} else { |
207
|
|
|
$unit = 'second'; |
208
|
|
|
$count = $s; |
209
|
|
|
} |
210
|
|
|
|
211
|
6 |
|
$key = "common/time.$unit"; |
212
|
|
|
|
213
|
6 |
|
return Lang::choice($key, $count); |
214
|
|
|
} |
215
|
|
|
|
216
|
2 |
|
public function status() |
|
|
|
|
217
|
|
|
{ |
218
|
2 |
|
$status = 'draft'; |
219
|
2 |
|
if ($this->isOpen()) { |
220
|
2 |
|
$status = 'posted'; |
221
|
2 |
|
} else if ($this->isClosed()) { |
222
|
2 |
|
$status = 'closed'; |
223
|
2 |
|
} else if ($this->review_requested_at !== null) { |
224
|
2 |
|
$status = 'submitted'; |
225
|
|
|
} else { |
226
|
2 |
|
$status = 'draft'; |
227
|
|
|
} |
228
|
|
|
|
229
|
2 |
|
return $status; |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|