Passed
Push — task/user-api-endpoint ( 6e4649...f0b85b )
by Chris
04:32
created

Manager::toApiArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Traits\TalentCloudCrudTrait as CrudTrait;
11
use Spatie\Translatable\HasTranslations;
12
13
/**
14
 * Class Manager
15
 *
16
 * @property int $id
17
 * @property int $department_id
18
 * @property int $work_review_frequency_id
19
 * @property int $stay_late_frequency_id
20
 * @property int $engage_team_frequency_id
21
 * @property int $development_opportunity_frequency_id
22
 * @property int $refuse_low_value_work_frequency_id
23
 * @property int $years_experience
24
 * @property string $twitter_username
25
 * @property string $linkedin_url
26
 * @property int $user_id
27
 * @property \Jenssegers\Date\Date $created_at
28
 * @property \Jenssegers\Date\Date $updated_at
29
 *
30
 * @property \App\Models\User $user
31
 * @property \App\Models\Lookup\Department $department
32
 * @property \Illuminate\Database\Eloquent\Collection $job_posters
33
 * @property \App\Models\WorkEnvironment $work_environment
34
 * @property \App\Models\TeamCulture $team_culture
35
 * @property \App\Models\Lookup\Frequency $work_review_frequency
36
 * @property \App\Models\Lookup\Frequency $stay_late_frequency
37
 * @property \App\Models\Lookup\Frequency $engage_team_frequency
38
 * @property \App\Models\Lookup\Frequency $development_opportunity_frequency
39
 * @property \App\Models\Lookup\Frequency $refuse_low_value_work_frequency
40
 *
41
 * Localized Properties:
42
 * @property string $about_me
43
 * @property string $greatest_accomplishment
44
 * @property string $division
45
 * @property string $position
46
 * @property string $leadership_style
47
 * @property string $employee_learning
48
 * @property string $expectations
49
 * @property string $education
50
 * @property string $career_journey
51
 * @property string $learning_path
52
 *
53
 * Computed Properties
54
 * @property string $full_name
55
 * @property string $first_name
56
 * @property string $last_name
57
 * @property boolean $is_demo_manager
58
 */
59
class Manager extends BaseModel
60
{
61
    use HasTranslations;
62
    use CrudTrait;
63
64
    public $translatable = [
65
        'about_me',
66
        'greatest_accomplishment',
67
        'division',
68
        'position',
69
        'leadership_style',
70
        'employee_learning',
71
        'expectations',
72
        'education',
73
        'career_journey',
74
        'learning_path'
75
    ];
76
    protected $casts = [
77
        'department_id' => 'int',
78
        'user_id' => 'int'
79
    ];
80
    protected $fillable = [
81
        'department_id',
82
        'twitter_username',
83
        'linkedin_url',
84
        'work_review_frequency_id',
85
        'stay_late_frequency_id',
86
        'engage_team_frequency_id',
87
        'development_opportunity_frequency_id',
88
        'refuse_low_value_work_frequency_id',
89
        'years_experience',
90
        'about_me',
91
        'greatest_accomplishment',
92
        'division',
93
        'position',
94
        'leadership_style',
95
        'employee_learning',
96
        'expectations',
97
        'education',
98
        'career_journey',
99
        'learning_path'
100
    ];
101
102
    /**
103
     * The accessors to append to the model's array form.
104
     *
105
     * @var array
106
     */
107
    protected $appends = ['first_name', 'last_name', 'full_name', 'is_demo_manager'];
108
109
    /**
110
     * The attributes that should be visible in arrays.
111
     *
112
     * @var array
113
     */
114
    protected $visible = [
115
        'id',
116
        'user_id',
117
        'first_name',
118
        'last_name',
119
        'full_name',
120
        'department_id',
121
        'twitter_username',
122
        'linkedin_url',
123
        'is_demo_manager',
124
        'about_me',
125
        'greatest_accomplishment',
126
        'division',
127
        'position',
128
        'leadership_style',
129
        'employee_learning',
130
        'expectations',
131
        'education',
132
        'career_journey',
133
        'learning_path'
134
    ];
135
136
    public function user()
137
    {
138
        return $this->belongsTo(\App\Models\User::class);
139
    }
140
141
    public function department()
142
    {
143
        return $this->belongsTo(\App\Models\Lookup\Department::class);
144
    }
145
146
    public function job_posters() //phpcs:ignore
147
    {
148
        return $this->hasMany(\App\Models\JobPoster::class);
149
    }
150
151
    public function work_environment() //phpcs:ignore
152
    {
153
        return $this->hasOne(\App\Models\WorkEnvironment::class)->withDefault();
154
    }
155
156
    public function team_culture() //phpcs:ignore
157
    {
158
        return $this->hasOne(\App\Models\TeamCulture::class)->withDefault();
159
    }
160
161
    public function work_review_frequency() //phpcs:ignore
162
    {
163
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
164
    }
165
166
    public function stay_late_frequency() //phpcs:ignore
167
    {
168
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
169
    }
170
171
    public function engage_team_frequency() //phpcs:ignore
172
    {
173
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
174
    }
175
176
    public function development_opportunity_frequency() //phpcs:ignore
177
    {
178
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
179
    }
180
181
    public function refuse_low_value_work_frequency() //phpcs:ignore
182
    {
183
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
184
    }
185
186
    /**
187
     * Return the full name of the User associated with this Manager.
188
     *
189
     * @return string
190
     */
191
    public function getFullNameAttribute(): string
192
    {
193
        if ($this->user !== null) {
194
            return $this->user->first_name . ' ' . $this->user->last_name;
195
        }
196
        return '';
197
    }
198
199
    /**
200
     * Return the first name of the User associated with this Manager.
201
     *
202
     * @return string
203
     */
204
    public function getFirstNameAttribute(): string
205
    {
206
        if ($this->user !== null) {
207
            return $this->user->first_name;
208
        }
209
        return '';
210
    }
211
212
    /**
213
     * Return the last name of the User associated with this Manager.
214
     *
215
     * @return string
216
     */
217
    public function getLastNameAttribute(): string
218
    {
219
        if ($this->user !== null) {
220
            return $this->user->last_name;
221
        }
222
        return '';
223
    }
224
225
    /**
226
     * Return whether this is a Demo Manager.
227
     *
228
     * @return boolean
229
     */
230
    public function getIsDemoManagerAttribute(): bool
231
    {
232
        if ($this->user !== null) {
233
            return $this->user->isDemoManager();
234
        }
235
        return true;
236
    }
237
}
238