| Total Complexity | 32 |
| Total Lines | 178 |
| Duplicated Lines | 0 % |
| Coverage | 26.76% |
| Changes | 0 | ||
| 1 | <?php |
||
| 49 | class JobApplication extends BaseModel { |
||
| 50 | |||
| 51 | use Notifiable; |
||
|
|
|||
| 52 | |||
| 53 | protected $dispatchesEvents = [ |
||
|
1 ignored issue
–
show
|
|||
| 54 | 'retrieved' => ApplicationRetrieved::class, |
||
| 55 | 'saved' => ApplicationSaved::class, |
||
| 56 | ]; |
||
| 57 | |||
| 58 | protected $casts = [ |
||
|
1 ignored issue
–
show
|
|||
| 59 | 'job_poster_id' => 'int', |
||
| 60 | 'application_status_id' => 'int', |
||
| 61 | 'citizenship_declaration_id' => 'int', |
||
| 62 | 'veteran_status_id' => 'int', |
||
| 63 | 'preferred_language_id' => 'int', |
||
| 64 | 'applicant_id' => 'int', |
||
| 65 | 'applicant_snapshot_id' => 'int', |
||
| 66 | 'submission_signature' => 'string', |
||
| 67 | 'submission_date' => 'string', |
||
| 68 | 'experience_saved' => 'boolean', |
||
| 69 | 'language_requirement_confirmed' => 'boolean' |
||
| 70 | ]; |
||
| 71 | protected $fillable = [ |
||
|
1 ignored issue
–
show
|
|||
| 72 | 'citizenship_declaration_id', |
||
| 73 | 'language_requirement_confirmed', |
||
| 74 | 'veteran_status_id', |
||
| 75 | 'preferred_language_id', |
||
| 76 | 'submission_signature', |
||
| 77 | 'submission_date', |
||
| 78 | 'experience_saved', |
||
| 79 | ]; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * The accessors to append to the model's array/json form. |
||
| 83 | * |
||
| 84 | * @var array |
||
| 85 | */ |
||
| 86 | protected $appends = ['meets_essential_criteria']; |
||
| 87 | |||
| 88 | protected function createApplicantSnapshot($applicant_id) { |
||
|
1 ignored issue
–
show
|
|||
| 89 | $applicant = Applicant::where('id', $applicant_id)->firstOrFail(); |
||
| 90 | |||
| 91 | $snapshot = $applicant->replicate(); |
||
| 92 | |||
| 93 | } |
||
| 94 | |||
| 95 | 1 | public function applicant() { |
|
|
1 ignored issue
–
show
|
|||
| 96 | 1 | return $this->belongsTo(\App\Models\Applicant::class); |
|
| 97 | } |
||
| 98 | |||
| 99 | public function applicant_snapshot() { |
||
|
1 ignored issue
–
show
|
|||
| 100 | return $this->belongsTo(\App\Models\Applicant::class, 'applicant_snapshot_id'); |
||
| 101 | } |
||
| 102 | |||
| 103 | 12 | public function application_status() { |
|
|
1 ignored issue
–
show
|
|||
| 104 | 12 | return $this->belongsTo(\App\Models\Lookup\ApplicationStatus::class); |
|
| 105 | } |
||
| 106 | |||
| 107 | public function citizenship_declaration() { |
||
|
1 ignored issue
–
show
|
|||
| 108 | return $this->belongsTo(\App\Models\Lookup\CitizenshipDeclaration::class); |
||
| 109 | } |
||
| 110 | |||
| 111 | public function veteran_status() { |
||
|
1 ignored issue
–
show
|
|||
| 112 | return $this->belongsTo(\App\Models\Lookup\VeteranStatus::class); |
||
| 113 | } |
||
| 114 | |||
| 115 | public function preferred_language() { |
||
| 117 | } |
||
| 118 | |||
| 119 | 1 | public function job_poster() { |
|
|
1 ignored issue
–
show
|
|||
| 120 | 1 | return $this->belongsTo(\App\Models\JobPoster::class); |
|
| 121 | } |
||
| 122 | |||
| 123 | public function job_application_answers() { |
||
|
1 ignored issue
–
show
|
|||
| 124 | return $this->hasMany(\App\Models\JobApplicationAnswer::class); |
||
| 125 | } |
||
| 126 | |||
| 127 | 1 | public function skill_declarations() { |
|
|
1 ignored issue
–
show
|
|||
| 128 | 1 | return $this->applicant->skill_declarations() |
|
| 129 | 1 | ->whereIn('skill_id', $this->job_poster->criteria->pluck('skill_id')); |
|
| 130 | } |
||
| 131 | |||
| 132 | public function application_review() { |
||
|
1 ignored issue
–
show
|
|||
| 133 | return $this->hasOne(ApplicationReview::class); |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Return either 'complete', 'incomplete' or 'error', depending on the |
||
| 138 | * status of the requested section. |
||
| 139 | * |
||
| 140 | * @param string $section Should be one of: |
||
|
1 ignored issue
–
show
|
|||
| 141 | * 'basics' |
||
| 142 | * 'experience' |
||
| 143 | * 'essential_skills' |
||
| 144 | * 'asset_skills' |
||
| 145 | * 'preview' |
||
| 146 | * |
||
| 147 | * @return string $status 'complete', 'incomplete' or 'error' |
||
| 148 | */ |
||
| 149 | public function getSectionStatus(string $section) { |
||
| 150 | //TODO: determine whether sections are complete or invalid |
||
| 151 | $validator = new ApplicationValidator(); |
||
| 152 | $status = 'incomplete'; |
||
| 153 | switch($section) { |
||
| 154 | case 'basics': |
||
| 155 | if ($validator->basicsComplete($this)) { |
||
| 156 | $status = 'complete'; |
||
| 157 | } |
||
| 158 | break; |
||
| 159 | case 'experience': |
||
| 160 | if ($validator->experienceComplete($this)) { |
||
| 161 | $status = 'complete'; |
||
| 162 | } |
||
| 163 | break; |
||
| 164 | case 'essential_skills': |
||
| 165 | if ($validator->essentialSkillsComplete($this)) { |
||
| 166 | $status = 'complete'; |
||
| 167 | } |
||
| 168 | break; |
||
| 169 | case 'asset_skills': |
||
| 170 | if ($validator->assetSkillsComplete($this)) { |
||
| 171 | $status = 'complete'; |
||
| 172 | } |
||
| 173 | break; |
||
| 174 | case 'preview': |
||
| 175 | if ($validator->basicsComplete($this) && |
||
| 176 | $validator->experienceComplete($this) && |
||
| 177 | $validator->essentialSkillsComplete($this) && |
||
| 178 | $validator->assetSkillsComplete($this)) { |
||
| 179 | $status = 'complete'; |
||
| 180 | } |
||
| 181 | break; |
||
| 182 | case 'confirm': |
||
| 183 | if ($validator->affirmationComplete($this)) { |
||
| 184 | $status = 'complete'; |
||
| 185 | } |
||
| 186 | break; |
||
| 187 | default: |
||
| 188 | $status = 'error'; |
||
| 189 | break; |
||
| 190 | } |
||
| 191 | return $status; |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Returns true if this application meets all the essential criteria. |
||
| 196 | * That means it has attached an SkillDeclaration for each essential criterion, |
||
| 197 | * with a level at least as high as the required level. |
||
| 198 | * |
||
| 199 | * @return boolean |
||
| 200 | */ |
||
| 201 | 1 | public function meetsEssentialCriteria(): bool |
|
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Accessor for meetsEssentialCriteria function, which |
||
| 220 | * allows this value to be automtacially appended to array/json representation. |
||
| 221 | * |
||
| 222 | * @return boolean |
||
| 223 | */ |
||
| 224 | public function getMeetsEssentialCriteriaAttribute():bool |
||
| 227 | } |
||
| 228 | } |
||
| 229 |