|
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\Admin\Job; |
|
11
|
|
|
|
|
12
|
|
|
use Exception; |
|
13
|
|
|
use HRis\Api\Controllers\BaseController; |
|
14
|
|
|
use HRis\Api\Eloquent\JobTitle; |
|
15
|
|
|
use HRis\Api\Requests\Admin\Job\JobTitleRequest; |
|
16
|
|
|
use HRis\Api\Requests\Profile\JobRequest; |
|
17
|
|
|
use HRis\Api\Transformers\JobTitleTransformer; |
|
18
|
|
|
use Illuminate\Http\Request; |
|
19
|
|
|
use Illuminate\Support\Facades\DB; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class JobTitlesController. |
|
23
|
|
|
*/ |
|
24
|
|
|
class JobTitlesController extends BaseController |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var JobTitle |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $job_title; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param JobTitle $job_title |
|
33
|
|
|
* |
|
34
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
35
|
|
|
*/ |
|
36
|
14 |
|
public function __construct(JobTitle $job_title) |
|
37
|
|
|
{ |
|
38
|
14 |
|
$this->job_title = $job_title; |
|
39
|
14 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Delete the PIM - Custom Field Section. |
|
43
|
|
|
* |
|
44
|
|
|
* @param JobTitleRequest $request |
|
45
|
|
|
* |
|
46
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
47
|
|
|
* |
|
48
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
49
|
|
|
*/ |
|
50
|
4 |
|
public function destroy(JobTitleRequest $request) |
|
51
|
|
|
{ |
|
52
|
4 |
|
$job_title_id = $request->get('id'); |
|
53
|
|
|
|
|
54
|
4 |
|
$response_code = $this->job_title->whereId($job_title_id)->delete(); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
4 |
|
if (!$response_code) { |
|
57
|
2 |
|
return $this->response()->array(['message' => UNABLE_DELETE_MESSAGE, 'status_code' => 422])->statusCode(422); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
2 |
|
return $this->response()->array(['message' => SUCCESS_DELETE_MESSAGE, 'status_code' => 200])->statusCode(200); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Show a PIM - Custom Field Section. |
|
65
|
|
|
* |
|
66
|
|
|
* @param JobRequest $request |
|
67
|
|
|
* |
|
68
|
|
|
* @return \Illuminate\View\View |
|
69
|
|
|
* |
|
70
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function index(JobRequest $request) |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
2 |
|
$job_titles = $this->job_title->paginate(ROWS_PER_PAGE); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
2 |
|
$response['data'] = $job_titles; |
|
|
|
|
|
|
77
|
2 |
|
$response['table'] = $this->setupDataTable($job_titles); |
|
78
|
2 |
|
$response['message'] = SUCCESS_RETRIEVE_MESSAGE; |
|
79
|
2 |
|
$response['status_code'] = 200; |
|
80
|
|
|
|
|
81
|
2 |
|
return $this->response()->array($response)->statusCode(200); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Save the PIM - Custom Field Section. |
|
86
|
|
|
* |
|
87
|
|
|
* @param JobTitleRequest $request |
|
88
|
|
|
* |
|
89
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
90
|
|
|
* |
|
91
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
92
|
|
|
*/ |
|
93
|
6 |
View Code Duplication |
public function store(JobTitleRequest $request) |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
try { |
|
96
|
6 |
|
$job_title = $this->job_title->create($request->all()); |
|
97
|
6 |
|
} catch (Exception $e) { |
|
98
|
|
|
return $this->response()->array(['message' => UNABLE_ADD_MESSAGE, 'status_code' => 422])->statusCode(422); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
6 |
|
return $this->response()->array(['job_title' => $job_title, 'message' => SUCCESS_ADD_MESSAGE, 'status_code' => 201])->statusCode(201); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Setup table for custom field section. |
|
106
|
|
|
* |
|
107
|
|
|
* @param $job_titles |
|
108
|
|
|
* |
|
109
|
|
|
* @return array |
|
110
|
|
|
* |
|
111
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
112
|
|
|
*/ |
|
113
|
2 |
View Code Duplication |
public function setupDataTable($job_titles) |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
2 |
|
$table = []; |
|
116
|
|
|
|
|
117
|
2 |
|
$table['title'] = 'Job Titles'; |
|
118
|
2 |
|
$table['permission'] = 'admin.job.titles'; |
|
119
|
2 |
|
$table['headers'] = ['Id', 'Name', 'Description']; |
|
120
|
2 |
|
$table['model'] = [ |
|
121
|
2 |
|
'singular' => 'job_title', |
|
122
|
2 |
|
'plural' => 'job_titles', |
|
123
|
2 |
|
'dashed' => 'job-titles', |
|
124
|
|
|
]; |
|
125
|
2 |
|
$table['items'] = $job_titles; |
|
126
|
|
|
|
|
127
|
2 |
|
return $table; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Update the PIM - Custom Field Section. |
|
132
|
|
|
* |
|
133
|
|
|
* @param JobTitleRequest $request |
|
134
|
|
|
* |
|
135
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
136
|
|
|
* |
|
137
|
|
|
* @author Bertrand Kintanar <[email protected]> |
|
138
|
|
|
*/ |
|
139
|
4 |
View Code Duplication |
public function update(JobTitleRequest $request) |
|
|
|
|
|
|
140
|
|
|
{ |
|
141
|
4 |
|
$job_title = $this->job_title->whereId($request->get('id'))->first(); |
|
|
|
|
|
|
142
|
|
|
|
|
143
|
4 |
|
if (!$job_title) { |
|
144
|
2 |
|
return $this->response()->array(['message' => UNABLE_RETRIEVE_MESSAGE, 'status_code' => 404])->statusCode(404); |
|
145
|
|
|
} |
|
146
|
|
|
try { |
|
147
|
|
|
|
|
148
|
2 |
|
$job_title->update($request->only(['name', 'description'])); |
|
149
|
2 |
|
} catch (Exception $e) { |
|
150
|
|
|
|
|
151
|
|
|
return $this->response()->array(['message' => UNABLE_UPDATE_MESSAGE, 'status_code' => 422])->statusCode(422); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
2 |
|
return $this->response()->array(['message' => SUCCESS_UPDATE_MESSAGE, 'status_code' => 200])->statusCode(200); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: