|
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\Controllers; |
|
11
|
|
|
|
|
12
|
|
|
use HRis\Api\Eloquent\CustomField; |
|
13
|
|
|
use HRis\Api\Eloquent\CustomFieldValue; |
|
14
|
|
|
use HRis\Api\Eloquent\Employee; |
|
15
|
|
|
use HRis\Api\Requests\EmployeeRequest; |
|
16
|
|
|
use HRis\Api\Transformers\EmployeeTransformer; |
|
17
|
|
|
|
|
18
|
|
|
class EmployeeController extends BaseController |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var CustomFieldValue |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $custom_field_value; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var Employee |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $employee; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var CustomField |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $custom_field; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param Employee $employee |
|
37
|
|
|
* @param CustomField $custom_field |
|
38
|
|
|
* @param CustomFieldValue $custom_field_value |
|
39
|
|
|
* |
|
40
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
41
|
|
|
*/ |
|
42
|
6 |
|
public function __construct(Employee $employee, CustomField $custom_field, CustomFieldValue $custom_field_value) |
|
43
|
|
|
{ |
|
44
|
6 |
|
$this->employee = $employee; |
|
45
|
6 |
|
$this->custom_field = $custom_field; |
|
46
|
6 |
|
$this->custom_field_value = $custom_field_value; |
|
47
|
6 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param Employee $employee |
|
51
|
|
|
* |
|
52
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
53
|
|
|
* |
|
54
|
|
|
* @return \Dingo\Api\Http\Response |
|
55
|
|
|
*/ |
|
56
|
6 |
|
public function show(Employee $employee) |
|
57
|
|
|
{ |
|
58
|
6 |
|
$this->initializeCustomFieldValues($employee->employee_id); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
6 |
|
$employee = $this->employee->getEmployeeById($employee->employee_id, null); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
6 |
|
return $this->item($employee, new EmployeeTransformer()); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param $employee_id |
|
67
|
|
|
* |
|
68
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
69
|
|
|
*/ |
|
70
|
6 |
|
private function initializeCustomFieldValues($employee_id) |
|
71
|
|
|
{ |
|
72
|
6 |
|
$employee_id = $this->employee->whereEmployeeId($employee_id)->value('id'); |
|
|
|
|
|
|
73
|
6 |
|
$custom_fields = $this->custom_field->get(); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
6 |
|
foreach ($custom_fields as $custom_field) { |
|
76
|
6 |
|
if (!$this->custom_field_value->whereCustomFieldId($custom_field->id)->whereEmployeeId($employee_id)->first()) { |
|
|
|
|
|
|
77
|
|
|
$data = [ |
|
78
|
6 |
|
'custom_field_id' => $custom_field->id, |
|
79
|
6 |
|
'employee_id' => $employee_id, |
|
80
|
6 |
|
'value' => null, |
|
81
|
6 |
|
]; |
|
82
|
|
|
|
|
83
|
6 |
|
$custom_field_value = $this->custom_field_value->firstOrCreate($data); |
|
84
|
6 |
|
$custom_field_value->save(); |
|
85
|
6 |
|
} |
|
86
|
6 |
|
} |
|
87
|
6 |
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
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.