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 int $department_id |
26
|
|
|
* @property int $province_id |
27
|
|
|
* @property int $salary_min |
28
|
|
|
* @property int $salary_max |
29
|
|
|
* @property int $noc |
30
|
|
|
* @property string $classification |
31
|
|
|
* @property int $security_clearance_id |
32
|
|
|
* @property int $language_requirement_id |
33
|
|
|
* @property boolean $remote_work_allowed |
34
|
|
|
* @property int $manager_id |
35
|
|
|
* @property boolean $published |
36
|
|
|
* @property \Jenssegers\Date\Date $created_at |
37
|
|
|
* @property \Jenssegers\Date\Date $updated_at |
38
|
|
|
* |
39
|
|
|
* @property int $submitted_applications_count |
40
|
|
|
* |
41
|
|
|
* @property \App\Models\Lookup\Department $department |
42
|
|
|
* @property \App\Models\Lookup\JobTerm $job_term |
43
|
|
|
* @property \App\Models\Lookup\LanguageRequirement $language_requirement |
44
|
|
|
* @property \App\Models\Manager $manager |
45
|
|
|
* @property \App\Models\Lookup\Province $province |
46
|
|
|
* @property \App\Models\Lookup\SecurityClearance $security_clearance |
47
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $criteria |
48
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_applications |
49
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_poster_key_tasks |
50
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_poster_questions |
51
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_poster_translations |
52
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $submitted_applications |
53
|
|
|
* @property \Illuminate\Database\Eloquent\Collection[ScreeningPlan] $screening_plans |
54
|
|
|
* |
55
|
|
|
* Localized Properties: |
56
|
|
|
* @property string $city |
57
|
|
|
* @property string $title |
58
|
|
|
* @property string $impact |
59
|
|
|
* @property string $branch |
60
|
|
|
* @property string $division |
61
|
|
|
* @property string $education |
62
|
|
|
* |
63
|
|
|
* Methods |
64
|
|
|
* @method boolean isOpen() |
|
|
|
|
65
|
|
|
* @method string timeRemaining() |
|
|
|
|
66
|
|
|
*/ |
|
|
|
|
67
|
|
|
class JobPoster extends BaseModel { |
|
|
|
|
68
|
|
|
|
69
|
|
|
use \Dimsav\Translatable\Translatable; |
|
|
|
|
70
|
|
|
use Notifiable; |
|
|
|
|
71
|
|
|
|
72
|
|
|
public $translatedAttributes = ['city', 'title', 'impact', 'branch', 'division', 'education']; |
73
|
|
|
protected $casts = [ |
74
|
|
|
'job_term_id' => 'int', |
75
|
|
|
'department_id' => 'int', |
76
|
|
|
'province_id' => 'int', |
77
|
|
|
'salary_min' => 'int', |
78
|
|
|
'salary_max' => 'int', |
79
|
|
|
'noc' => 'int', |
80
|
|
|
'security_clearance_id' => 'int', |
81
|
|
|
'language_requirement_id' => 'int', |
82
|
|
|
'remote_work_allowed' => 'boolean', |
83
|
|
|
'manager_id' => 'int', |
84
|
|
|
'published' => 'boolean' |
85
|
|
|
]; |
86
|
|
|
protected $dates = [ |
87
|
|
|
'open_date_time', |
88
|
|
|
'close_date_time', |
89
|
|
|
'start_date_time' |
90
|
|
|
]; |
91
|
|
|
protected $fillable = [ |
92
|
|
|
'job_term_id', |
93
|
|
|
'term_qty', |
94
|
|
|
'open_date_time', |
95
|
|
|
'close_date_time', |
96
|
|
|
'start_date_time', |
97
|
|
|
'department_id', |
98
|
|
|
'province_id', |
99
|
|
|
'salary_min', |
100
|
|
|
'salary_max', |
101
|
|
|
'noc', |
102
|
|
|
'classification', |
103
|
|
|
'security_clearance_id', |
104
|
|
|
'language_requirement_id', |
105
|
|
|
'remote_work_allowed', |
106
|
|
|
'published' |
107
|
|
|
]; |
108
|
|
|
protected $withCount = ['submitted_applications']; |
109
|
|
|
|
110
|
|
|
protected $dispatchesEvents = [ |
111
|
|
|
'saved' => JobSaved::class, |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
public function department() { |
|
|
|
|
115
|
|
|
return $this->belongsTo(\App\Models\Lookup\Department::class); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function job_term() { |
|
|
|
|
119
|
|
|
return $this->belongsTo(\App\Models\Lookup\JobTerm::class); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function language_requirement() { |
|
|
|
|
123
|
|
|
return $this->belongsTo(\App\Models\Lookup\LanguageRequirement::class); |
124
|
|
|
} |
125
|
|
|
|
126
|
6 |
|
public function manager() { |
|
|
|
|
127
|
6 |
|
return $this->belongsTo(\App\Models\Manager::class); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function province() { |
|
|
|
|
131
|
|
|
return $this->belongsTo(\App\Models\Lookup\Province::class); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function security_clearance() { |
|
|
|
|
135
|
|
|
return $this->belongsTo(\App\Models\Lookup\SecurityClearance::class); |
136
|
|
|
} |
137
|
|
|
|
138
|
8 |
|
public function criteria() { |
|
|
|
|
139
|
8 |
|
return $this->hasMany(\App\Models\Criteria::class); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function job_applications() { |
|
|
|
|
143
|
|
|
return $this->hasMany(\App\Models\JobApplication::class); |
144
|
|
|
} |
145
|
|
|
|
146
|
8 |
|
public function job_poster_key_tasks() { |
|
|
|
|
147
|
8 |
|
return $this->hasMany(\App\Models\JobPosterKeyTask::class); |
148
|
|
|
} |
149
|
|
|
|
150
|
8 |
|
public function job_poster_questions() { |
|
|
|
|
151
|
8 |
|
return $this->hasMany(\App\Models\JobPosterQuestion::class); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function job_poster_translations() { |
|
|
|
|
155
|
|
|
return $this->hasMany(\App\Models\JobPosterTranslation::class); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function screening_plans() |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
return $this->hasMany(\App\Models\ScreeningPlan::class); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
// Artificial Relations |
164
|
|
|
|
165
|
10 |
|
public function submitted_applications() { |
|
|
|
|
166
|
|
|
return $this->hasMany(\App\Models\JobApplication::class)->whereHas('application_status', function ($query) { |
|
|
|
|
167
|
10 |
|
$query->where('name', '!=', 'draft'); |
168
|
10 |
|
}); |
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
// Accessors |
172
|
|
|
|
173
|
|
|
// Methods |
174
|
|
|
|
175
|
2 |
|
public function isOpen() { |
|
|
|
|
176
|
2 |
|
return $this->published |
177
|
2 |
|
&& $this->open_date_time->isPast() |
178
|
2 |
|
&& $this->close_date_time->isFuture(); |
179
|
|
|
} |
180
|
|
|
|
181
|
2 |
|
public function timeRemaining() { |
|
|
|
|
182
|
2 |
|
$interval = $this->close_date_time->diff(Date::now()); |
183
|
|
|
|
184
|
2 |
|
$d = $interval->d; |
185
|
2 |
|
$h = $interval->h; |
186
|
2 |
|
$m = $interval->i; |
187
|
2 |
|
$s = $interval->s; |
188
|
|
|
|
189
|
2 |
|
if ($d > 0) { |
190
|
2 |
|
$unit = 'day'; |
191
|
2 |
|
$count = $d; |
192
|
2 |
|
} else if ($h > 0) { |
193
|
2 |
|
$unit = 'hour'; |
194
|
2 |
|
$count = $h; |
195
|
|
|
} else if ($m > 0) { |
196
|
|
|
$unit = 'minute'; |
197
|
|
|
$count = $m; |
198
|
|
|
} else { |
199
|
|
|
$unit = 'second'; |
200
|
|
|
$count = $s; |
201
|
|
|
} |
202
|
|
|
|
203
|
2 |
|
$key = "common/time.$unit"; |
204
|
|
|
|
205
|
2 |
|
return Lang::choice($key, $count); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|