Passed
Push — task/applicant-skill-relations... ( 78f92f )
by
unknown
06:50
created

Applicant::degrees()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Models;
4
5
use App\Traits\TalentCloudCrudTrait as CrudTrait;
6
7
/**
8
 * Class Applicant
9
 *
10
 * @property int $id
11
 * @property string $personal_website
12
 * @property string $tagline
13
 * @property string $twitter_username
14
 * @property string $linkedin_url
15
 * @property int $user_id
16
 * @property boolean $is_snapshot
17
 *
18
 * @property \Jenssegers\Date\Date $created_at
19
 * @property \Jenssegers\Date\Date $updated_at
20
 *
21
 * @property \App\Models\User $user
22
 * @property \Illuminate\Database\Eloquent\Collection $applicant_profile_answers
23
 * @property \Illuminate\Database\Eloquent\Collection $job_applications
24
 * @property \Illuminate\Database\Eloquent\Collection $submitted_applications
25
 * @property \Illuminate\Database\Eloquent\Collection $degrees
26
 * @property \Illuminate\Database\Eloquent\Collection $courses
27
 * @property \Illuminate\Database\Eloquent\Collection $work_experiences
28
 * @property \Illuminate\Database\Eloquent\Collection $skill_declarations
29
 * @property \Illuminate\Database\Eloquent\Collection $references
30
 * @property \Illuminate\Database\Eloquent\Collection $work_samples
31
 * @property \Illuminate\Database\Eloquent\Collection $projects
32
 *
33
 * Version 2 application models.
34
 * @property \Illuminate\Database\Eloquent\Collection $experiences_work
35
 * @property \Illuminate\Database\Eloquent\Collection $experiences_personal
36
 * @property \Illuminate\Database\Eloquent\Collection $experiences_education
37
 * @property \Illuminate\Database\Eloquent\Collection $experiences_award
38
 * @property \Illuminate\Database\Eloquent\Collection $experiences_community
39
 */
40
class Applicant extends BaseModel
41
{
42
    // Trait for Backpack.
43
    use CrudTrait;
44
45
    protected $casts = [
46
        'user_id' => 'int',
47
        'personal_website' => 'string',
48
        'tagline' => 'string',
49
        'twitter_username' => 'string',
50
        'linkedin_url' => 'string',
51
        'is_snapshot' => 'boolean'
52
    ];
53
    protected $fillable = [
54
        'personal_website',
55
        'tagline',
56
        'twitter_username',
57
        'linkedin_url'
58
    ];
59
60
    public function user()
61
    {
62
        return $this->belongsTo(\App\Models\User::class);
63
    }
64
65
    public function applicant_profile_answers() //phpcs:ignore
66
    {
67
        return $this->hasMany(\App\Models\ApplicantProfileAnswer::class);
68
    }
69
70
    public function job_applications() //phpcs:ignore
71
    {
72
        if ($this->is_snapshot) {
73
            return $this->hasMany(\App\Models\JobApplication::class, 'applicant_snapshot_id');
74
        }
75
        return $this->hasMany(\App\Models\JobApplication::class);
76
    }
77
78
    /**
79
     * Get all of the Job Applications submitted by this applicant
80
     *
81
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
82
     */
83
    public function submitted_applications() // phpcs:ignore
84
    {
85
        return $this->hasMany(\App\Models\JobApplication::class)->whereDoesntHave('application_status', function ($query): void {
86
            $query->where('name', 'draft');
87
        });
88
    }
89
90
    public function degrees()
91
    {
92
        return $this->morphMany(\App\Models\Degree::class, 'degreeable')->orderBy('end_date', 'desc');
93
    }
94
95
    public function courses()
96
    {
97
        return $this->morphMany(\App\Models\Course::class, 'courseable')->orderBy('end_date', 'desc');
98
    }
99
100
    public function work_experiences() //phpcs:ignore
101
    {
102
        return $this->morphMany(\App\Models\WorkExperience::class, 'experienceable')->orderBy('end_date', 'desc');
103
    }
104
105
    public function skill_declarations() //phpcs:ignore
106
    {
107
        return $this->morphMany(\App\Models\SkillDeclaration::class, 'skillable');
108
    }
109
110
    public function references()
111
    {
112
        return $this->morphMany(\App\Models\Reference::class, 'referenceable');
113
    }
114
115
    public function work_samples() //phpcs:ignore
116
    {
117
        return $this->morphMany(\App\Models\WorkSample::class, 'work_sampleable');
118
    }
119
120
    public function projects()
121
    {
122
        return $this->morphMany(\App\Models\Project::class, 'projectable');
123
    }
124
125
    public function skills() // phpcs:ignore
126
    {
127
        return $this->belongsToMany(\App\Models\Skill::class, 'applicants_skills');
128
    }
129
130
    // Version 2 application models.
131
132
    public function experiences_work() //phpcs:ignore
133
    {
134
        return $this->morphMany(\App\Models\ExperienceWork::class, 'experienceable')
135
            ->orderBy('end_date', 'desc');
136
    }
137
138
    public function experiences_personal() //phpcs:ignore
139
    {
140
        return $this->morphMany(\App\Models\ExperiencePersonal::class, 'experienceable')
141
            ->orderBy('end_date', 'desc');
142
    }
143
144
    public function experiences_education() //phpcs:ignore
145
    {
146
        return $this->morphMany(\App\Models\ExperienceEducation::class, 'experienceable')
147
            ->orderBy('end_date', 'desc');
148
    }
149
150
    public function experiences_award() //phpcs:ignore
151
    {
152
        return $this->morphMany(\App\Models\ExperienceAward::class, 'experienceable');
153
    }
154
155
    public function experiences_community() //phpcs:ignore
156
    {
157
        return $this->morphMany(\App\Models\ExperienceCommunity::class, 'experienceable')
158
            ->orderBy('end_date', 'desc');
159
    }
160
}
161