| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Models; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use App\Traits\TalentCloudCrudTrait as CrudTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Database\Eloquent\Builder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Class Applicant | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @property int $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @property string $personal_website | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @property string $tagline | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @property string $twitter_username | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @property string $linkedin_url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @property int $user_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @property boolean $is_snapshot | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @property int $citizenship_declaration_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @property int $veteran_status_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @property \Jenssegers\Date\Date $created_at | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @property \Jenssegers\Date\Date $updated_at | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @property \App\Models\User $user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $applicant_profile_answers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $job_applications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $submitted_applications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $degrees | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $courses | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $work_experiences | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $skill_declarations | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $references | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $work_samples | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $projects | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $applicant_classifications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $skills | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  * Version 2 application models. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $experiences_work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $experiences_personal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $experiences_education | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $experiences_award | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  * @property \Illuminate\Database\Eloquent\Collection $experiences_community | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  * @method \Illuminate\Database\Query\Builder experienceSkillsQuery | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | class Applicant extends BaseModel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     // Trait for Backpack. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     use CrudTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     protected $casts = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         'user_id' => 'int', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         'personal_website' => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         'tagline' => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         'twitter_username' => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         'linkedin_url' => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         'is_snapshot' => 'boolean', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         'citizenship_declaration_id' => 'int', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         'veteran_status_id' => 'int', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     protected $fillable = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         'personal_website', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         'tagline', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         'twitter_username', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         'linkedin_url', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         'citizenship_declaration_id' => 'int', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         'veteran_status_id' => 'int', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function user() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         return $this->belongsTo(\App\Models\User::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     public function applicant_profile_answers() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         return $this->hasMany(\App\Models\ApplicantProfileAnswer::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     public function job_applications() //phpcs:ignore | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |         if ($this->is_snapshot) { | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |             return $this->hasMany(\App\Models\JobApplication::class, 'applicant_snapshot_id'); | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |         return $this->hasMany(\App\Models\JobApplication::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * Get all of the Job Applications submitted by this applicant | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @return \Illuminate\Database\Eloquent\Relations\HasMany | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     public function submitted_applications() // phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         return $this->hasMany(\App\Models\JobApplication::class)->whereDoesntHave('application_status', function ($query): void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             $query->where('name', 'draft'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     public function degrees() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         return $this->morphMany(\App\Models\Degree::class, 'degreeable')->orderBy('end_date', 'desc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     public function courses() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         return $this->morphMany(\App\Models\Course::class, 'courseable')->orderBy('end_date', 'desc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public function work_experiences() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         return $this->morphMany(\App\Models\WorkExperience::class, 'experienceable')->orderBy('end_date', 'desc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     public function skill_declarations() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         return $this->morphMany(\App\Models\SkillDeclaration::class, 'skillable'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     public function references() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         return $this->morphMany(\App\Models\Reference::class, 'referenceable'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     public function work_samples() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         return $this->morphMany(\App\Models\WorkSample::class, 'work_sampleable'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     public function projects() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         return $this->morphMany(\App\Models\Project::class, 'projectable'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     public function applicant_classifications() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         return $this->hasMany(\App\Models\ApplicantClassification::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     public function skills() // phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         return $this->belongsToMany(\App\Models\Skill::class, 'applicant_skill'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     // Version 2 application models. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     public function experiences_work() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         return $this->morphMany(\App\Models\ExperienceWork::class, 'experienceable') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             ->orderBy('end_date', 'desc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     public function experiences_personal() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         return $this->morphMany(\App\Models\ExperiencePersonal::class, 'experienceable') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             ->orderBy('end_date', 'desc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     public function experiences_education() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         return $this->morphMany(\App\Models\ExperienceEducation::class, 'experienceable') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             ->orderBy('end_date', 'desc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     public function experiences_award() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         return $this->morphMany(\App\Models\ExperienceAward::class, 'experienceable'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     public function experiences_community() //phpcs:ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         return $this->morphMany(\App\Models\ExperienceCommunity::class, 'experienceable') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             ->orderBy('end_date', 'desc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * Returns a Laravel QueryBuilder object which will retrieve all ExperienceSkills | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * which are linked to this Applicant, through this Applicant's Experiences. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * It returns the query builder object instead of the results of the query, so that additional | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      * clauses can be added by other code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      * @return \Illuminate\Database\Query\Builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     public function experienceSkillsQuery() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         $applicantId = $this->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         return ExperienceSkill::whereHasMorph( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |             'experience', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |             '*', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             function (Builder $query) use ($applicantId): void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |                 $query->where([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |                     ['experienceable_type', 'applicant'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |                     ['experienceable_id', $applicantId] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |                 ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 200 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 201 |  |  |  |