|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the HRis Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* HRis - Human Resource and Payroll System |
|
7
|
|
|
* |
|
8
|
|
|
* @link http://github.com/HB-Co/HRis |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace HRis\Api\Transformers; |
|
11
|
|
|
|
|
12
|
|
|
use HRis\Api\Eloquent\Employee; |
|
13
|
|
|
use League\Fractal\ParamBag; |
|
14
|
|
|
|
|
15
|
|
|
class EmployeeTransformer extends BaseTransformer |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* List of resources to automatically include. |
|
19
|
|
|
* |
|
20
|
|
|
* @var array |
|
21
|
|
|
* |
|
22
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $defaultIncludes = [ |
|
25
|
|
|
'user', |
|
26
|
|
|
'job_history', |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Resources that can be included if requested. |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
* |
|
34
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $availableIncludes = [ |
|
37
|
|
|
'city', |
|
38
|
|
|
'country', |
|
39
|
|
|
'dependents', |
|
40
|
|
|
'emergency_contacts', |
|
41
|
|
|
'job_histories', |
|
42
|
|
|
'work_experiences', |
|
43
|
|
|
'employee_skills', |
|
44
|
|
|
'educations', |
|
45
|
|
|
'custom_field_values', |
|
46
|
|
|
'supervisors', |
|
47
|
|
|
'subordinates', |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Transform object into a generic array. |
|
52
|
|
|
* |
|
53
|
|
|
* @param Employee $employee |
|
54
|
|
|
* |
|
55
|
|
|
* @return array |
|
56
|
|
|
* |
|
57
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
58
|
|
|
*/ |
|
59
|
6 |
|
public function transform(Employee $employee) |
|
60
|
|
|
{ |
|
61
|
|
|
return [ |
|
62
|
6 |
|
'id' => $employee->id, |
|
|
|
|
|
|
63
|
6 |
|
'employee_id' => $employee->employee_id, |
|
|
|
|
|
|
64
|
6 |
|
'face_id' => $employee->face_id, |
|
|
|
|
|
|
65
|
6 |
|
'marital_status_id' => $employee->marital_status_id, |
|
|
|
|
|
|
66
|
6 |
|
'nationality_id' => $employee->nationality_id, |
|
|
|
|
|
|
67
|
6 |
|
'first_name' => $employee->first_name, |
|
|
|
|
|
|
68
|
6 |
|
'middle_name' => $employee->middle_name, |
|
|
|
|
|
|
69
|
6 |
|
'last_name' => $employee->last_name, |
|
|
|
|
|
|
70
|
6 |
|
'sufffix_name' => $employee->sufffix_name, |
|
|
|
|
|
|
71
|
6 |
|
'avatar' => $employee->avatar, |
|
|
|
|
|
|
72
|
6 |
|
'gender' => $employee->gender, |
|
|
|
|
|
|
73
|
6 |
|
'address_1' => $employee->address_1, |
|
|
|
|
|
|
74
|
6 |
|
'address_2' => $employee->address_2, |
|
|
|
|
|
|
75
|
6 |
|
'address_city_id' => (int) $employee->address_city_id, |
|
|
|
|
|
|
76
|
6 |
|
'address_province_id' => (int) $employee->address_province_id, |
|
|
|
|
|
|
77
|
6 |
|
'address_country_id' => (int) $employee->address_country_id, |
|
|
|
|
|
|
78
|
6 |
|
'address_postal_code' => $employee->address_postal_code, |
|
|
|
|
|
|
79
|
6 |
|
'home_phone' => $employee->home_phone, |
|
|
|
|
|
|
80
|
6 |
|
'mobile_phone' => $employee->mobile_phone, |
|
|
|
|
|
|
81
|
6 |
|
'work_email' => $employee->work_email, |
|
|
|
|
|
|
82
|
6 |
|
'other_email' => $employee->other_email, |
|
|
|
|
|
|
83
|
6 |
|
'social_security' => $employee->social_security, |
|
|
|
|
|
|
84
|
6 |
|
'tax_identification' => $employee->tax_identification, |
|
|
|
|
|
|
85
|
6 |
|
'philhealth' => $employee->philhealth, |
|
|
|
|
|
|
86
|
6 |
|
'hdmf_pagibig' => $employee->hdmf_pagibig, |
|
|
|
|
|
|
87
|
6 |
|
'mid_rtn' => $employee->mid_rtn, |
|
|
|
|
|
|
88
|
6 |
|
'birth_date' => $employee->birth_date, |
|
|
|
|
|
|
89
|
6 |
|
'remarks' => $employee->remarks, |
|
|
|
|
|
|
90
|
6 |
|
'joined_date' => $employee->joined_date, |
|
|
|
|
|
|
91
|
6 |
|
'probation_end_date' => $employee->probation_end_date, |
|
|
|
|
|
|
92
|
6 |
|
'permanency_date' => $employee->permanency_date, |
|
|
|
|
|
|
93
|
6 |
|
'resign_date' => $employee->resign_date, |
|
|
|
|
|
|
94
|
6 |
|
'custom_field_values' => $employee->customFieldValues->lists('value', 'custom_field_id'), |
|
|
|
|
|
|
95
|
6 |
|
]; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Include City. |
|
100
|
|
|
* |
|
101
|
|
|
* @param Employee $employee |
|
102
|
|
|
* |
|
103
|
|
|
* @return \League\Fractal\Resource\Item |
|
104
|
|
|
* |
|
105
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
106
|
|
|
*/ |
|
107
|
|
|
public function includeCity(Employee $employee) |
|
108
|
|
|
{ |
|
109
|
|
|
$city = $employee->city; |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
return $this->item($city, new CityTransformer()); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Include User. |
|
116
|
|
|
* |
|
117
|
|
|
* @param Employee $employee |
|
118
|
|
|
* |
|
119
|
|
|
* @return \League\Fractal\Resource\Item |
|
120
|
|
|
* |
|
121
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
122
|
|
|
*/ |
|
123
|
6 |
|
public function includeUser(Employee $employee) |
|
124
|
|
|
{ |
|
125
|
6 |
|
$user = $employee->user; |
|
|
|
|
|
|
126
|
|
|
|
|
127
|
6 |
|
return $this->item($user, new UserTransformer()); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Include Country. |
|
132
|
|
|
* |
|
133
|
|
|
* @param Employee $employee |
|
134
|
|
|
* |
|
135
|
|
|
* @return \League\Fractal\Resource\Item |
|
136
|
|
|
* |
|
137
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
138
|
|
|
*/ |
|
139
|
|
|
public function includeCountry(Employee $employee) |
|
140
|
|
|
{ |
|
141
|
|
|
$country = $employee->country; |
|
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
return $this->item($country, new CountryTransformer()); |
|
|
|
|
|
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Include Dependent. |
|
148
|
|
|
* |
|
149
|
|
|
* @param Employee $employee |
|
150
|
|
|
* @param ParamBag $params |
|
151
|
|
|
* |
|
152
|
|
|
* @throws \Exception |
|
153
|
|
|
* |
|
154
|
|
|
* @return \League\Fractal\Resource\Collection |
|
155
|
|
|
* |
|
156
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
157
|
|
|
*/ |
|
158
|
|
|
public function includeDependents(Employee $employee, ParamBag $params = null) |
|
159
|
|
|
{ |
|
160
|
|
|
$dependents = $employee->dependents(); |
|
161
|
|
|
|
|
162
|
|
|
return $this->transformCollection($dependents, new DependentTransformer(), $params); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Include EmergencyContact. |
|
167
|
|
|
* |
|
168
|
|
|
* @param Employee $employee |
|
169
|
|
|
* @param ParamBag $params |
|
170
|
|
|
* |
|
171
|
|
|
* @throws \Exception |
|
172
|
|
|
* |
|
173
|
|
|
* @return \League\Fractal\Resource\Collection |
|
174
|
|
|
* |
|
175
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
176
|
|
|
*/ |
|
177
|
|
|
public function includeEmergencyContacts(Employee $employee, ParamBag $params = null) |
|
178
|
|
|
{ |
|
179
|
|
|
$emergency_contacts = $employee->emergencyContacts(); |
|
180
|
|
|
|
|
181
|
|
|
return $this->transformCollection($emergency_contacts, new EmergencyContactTransformer(), $params); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Include CustomFieldValue. |
|
186
|
|
|
* |
|
187
|
|
|
* @param Employee $employee |
|
188
|
|
|
* |
|
189
|
|
|
* @return \League\Fractal\Resource\Collection |
|
190
|
|
|
* |
|
191
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
192
|
|
|
*/ |
|
193
|
|
|
public function includeCustomFieldValues(Employee $employee) |
|
194
|
|
|
{ |
|
195
|
|
|
$custom_field_values = $employee->customFieldValues->lists('value', 'custom_field_id'); |
|
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
return $custom_field_values; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Include JobHistory. |
|
202
|
|
|
* |
|
203
|
|
|
* @param Employee $employee |
|
204
|
|
|
* |
|
205
|
|
|
* @return \League\Fractal\Resource\Item |
|
206
|
|
|
* |
|
207
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
208
|
|
|
*/ |
|
209
|
6 |
|
public function includeJobHistory(Employee $employee) |
|
210
|
|
|
{ |
|
211
|
6 |
|
$job_history = $employee->jobHistory(); |
|
212
|
|
|
|
|
213
|
6 |
|
return $this->item($job_history, new JobHistoryTransformer()); |
|
|
|
|
|
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Include JobHistories. |
|
218
|
|
|
* |
|
219
|
|
|
* @param Employee $employee |
|
220
|
|
|
* @param ParamBag $params |
|
221
|
|
|
* |
|
222
|
|
|
* @throws \Exception |
|
223
|
|
|
* |
|
224
|
|
|
* @return \League\Fractal\Resource\Collection |
|
225
|
|
|
* |
|
226
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
227
|
|
|
*/ |
|
228
|
|
|
public function includeJobHistories(Employee $employee, ParamBag $params = null) |
|
229
|
|
|
{ |
|
230
|
|
|
$job_histories = $employee->jobHistories(); |
|
231
|
|
|
|
|
232
|
|
|
return $this->transformCollection($job_histories, new JobHistoryTransformer(), $params); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Include WorkExperiences. |
|
237
|
|
|
* |
|
238
|
|
|
* @param Employee $employee |
|
239
|
|
|
* @param ParamBag $params |
|
240
|
|
|
* |
|
241
|
|
|
* @throws \Exception |
|
242
|
|
|
* |
|
243
|
|
|
* @return \League\Fractal\Resource\Collection |
|
244
|
|
|
* |
|
245
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
246
|
|
|
*/ |
|
247
|
|
|
public function includeWorkExperiences(Employee $employee, ParamBag $params = null) |
|
248
|
|
|
{ |
|
249
|
|
|
$work_experiences = $employee->workExperiences(); |
|
250
|
|
|
|
|
251
|
|
|
return $this->transformCollection($work_experiences, new WorkExperienceTransformer(), $params); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* Include EmployeeSkills. |
|
256
|
|
|
* |
|
257
|
|
|
* @param Employee $employee |
|
258
|
|
|
* @param ParamBag $params |
|
259
|
|
|
* |
|
260
|
|
|
* @throws \Exception |
|
261
|
|
|
* |
|
262
|
|
|
* @return \League\Fractal\Resource\Collection |
|
263
|
|
|
* |
|
264
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
265
|
|
|
*/ |
|
266
|
|
|
public function includeEmployeeSkills(Employee $employee, ParamBag $params = null) |
|
267
|
|
|
{ |
|
268
|
|
|
$employee_skills = $employee->employeeSkills(); |
|
269
|
|
|
|
|
270
|
|
|
return $this->transformCollection($employee_skills, new EmployeeSkillTransformer(), $params); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* Include Educations. |
|
275
|
|
|
* |
|
276
|
|
|
* @param Employee $employee |
|
277
|
|
|
* @param ParamBag $params |
|
278
|
|
|
* |
|
279
|
|
|
* @throws \Exception |
|
280
|
|
|
* |
|
281
|
|
|
* @return \League\Fractal\Resource\Collection |
|
282
|
|
|
* |
|
283
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
284
|
|
|
*/ |
|
285
|
|
|
public function includeEducations(Employee $employee, ParamBag $params = null) |
|
286
|
|
|
{ |
|
287
|
|
|
$educations = $employee->educations(); |
|
288
|
|
|
|
|
289
|
|
|
return $this->transformCollection($educations, new EducationTransformer(), $params); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* Include Supervisors. |
|
294
|
|
|
* |
|
295
|
|
|
* @param Employee $employee |
|
296
|
|
|
* @param ParamBag $params |
|
297
|
|
|
* |
|
298
|
|
|
* @throws \Exception |
|
299
|
|
|
* |
|
300
|
|
|
* @return \League\Fractal\Resource\Collection |
|
301
|
|
|
* |
|
302
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
303
|
|
|
*/ |
|
304
|
|
View Code Duplication |
public function includeSupervisors(Employee $employee, ParamBag $params = null) |
|
|
|
|
|
|
305
|
|
|
{ |
|
306
|
|
|
$supervisors = $employee->supervisors()->pluck('supervisor_id')->toArray(); |
|
307
|
|
|
|
|
308
|
|
|
$supervisors = $employee->whereIn('id', $supervisors); |
|
|
|
|
|
|
309
|
|
|
|
|
310
|
|
|
return $this->transformCollection($supervisors, new EmployeeTransformer(), $params); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* Include Subordinates. |
|
315
|
|
|
* |
|
316
|
|
|
* @param Employee $employee |
|
317
|
|
|
* @param ParamBag $params |
|
318
|
|
|
* |
|
319
|
|
|
* @throws \Exception |
|
320
|
|
|
* |
|
321
|
|
|
* @return \League\Fractal\Resource\Collection |
|
322
|
|
|
* |
|
323
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
324
|
|
|
*/ |
|
325
|
|
View Code Duplication |
public function includeSubordinates(Employee $employee, ParamBag $params = null) |
|
|
|
|
|
|
326
|
|
|
{ |
|
327
|
|
|
$subordinates = $employee->subordinates()->pluck('employee_id')->toArray(); |
|
328
|
|
|
|
|
329
|
|
|
$subordinates = $employee->whereIn('id', $subordinates); |
|
|
|
|
|
|
330
|
|
|
|
|
331
|
|
|
return $this->transformCollection($subordinates, new EmployeeTransformer(), $params); |
|
332
|
|
|
} |
|
333
|
|
|
} |
|
334
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.