1
|
|
|
<?php namespace Bantenprov\VueWorkflow\Http\Controllers; |
2
|
|
|
|
3
|
|
|
use App\Http\Controllers\Controller; |
4
|
|
|
use Illuminate\Http\Request; |
5
|
|
|
use Bantenprov\VueWorkflow\Facades\VueWorkflow; |
6
|
|
|
use Bantenprov\VueWorkflow\Models\Workflow; |
7
|
|
|
use Bantenprov\VueWorkflow\Models\WorkflowType; |
8
|
|
|
use Bantenprov\VueWorkflow\Models\Transition; |
9
|
|
|
|
10
|
|
|
use Validator; |
11
|
|
|
|
12
|
|
|
use Bantenprov\VueWorkflow\Http\Traits\WorkflowTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The VueWorkflowController class. |
16
|
|
|
* |
17
|
|
|
* @package Bantenprov\VueWorkflow |
18
|
|
|
* @author bantenprov <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class WorkflowController extends Controller |
21
|
|
|
{ |
22
|
|
|
use WorkflowTrait; |
23
|
|
|
|
24
|
|
|
protected $workflowModel; |
25
|
|
|
protected $workflowTypeModel; |
26
|
|
|
|
27
|
|
|
public function __construct(Request $request, Workflow $workflow, WorkflowType $workflowType){ |
28
|
|
|
$this->workflowModel = $workflow; |
29
|
|
|
$this->workflowTypeModel = $workflowType; |
30
|
|
|
|
31
|
|
|
//dd($request->path()); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* [Function] index |
36
|
|
|
* @param Request $req |
37
|
|
|
* |
38
|
|
|
* @return json |
39
|
|
|
*/ |
40
|
|
|
public function index(Request $req) |
41
|
|
|
{ |
42
|
|
|
// $transition = Transition::where('name','propose-to-propose')->where('workflow_id','19')->first(); |
|
|
|
|
43
|
|
|
// dd($transition->id); |
|
|
|
|
44
|
|
|
//dd($this->getRequest($req->input('sort'))); |
|
|
|
|
45
|
|
|
|
46
|
|
|
//dd(class_basename($this->workflowTypeModel)); |
|
|
|
|
47
|
|
|
//dd(class_basename(get_class($this))); |
|
|
|
|
48
|
|
|
//dd(get_declared_classes()); |
|
|
|
|
49
|
|
|
// foreach (get_declared_classes() as $value) { |
|
|
|
|
50
|
|
|
// //Illuminate\Database\Eloquent\Model |
51
|
|
|
// if(get_parent_class($value) == "Illuminate\Database\Eloquent\Model"){ |
|
|
|
|
52
|
|
|
// echo $value."<br>"; |
|
|
|
|
53
|
|
|
// } |
54
|
|
|
// //echo $value."<br>"; |
55
|
|
|
|
56
|
|
|
// } |
57
|
|
|
// dd(); |
58
|
|
|
$response; |
|
|
|
|
59
|
|
|
|
60
|
|
|
$param = explode('|',$req->get('sort')); |
61
|
|
|
|
62
|
|
|
if($req->get('filter') != ''){ |
63
|
|
|
$search = "%{$req->get('filter')}%"; |
64
|
|
|
$response = $this->workflowModel->where('name','like',$search)->orderBy($param[0], $param[1])->paginate(10); |
65
|
|
|
}else{ |
66
|
|
|
if($req->get('sort') == ''){ |
67
|
|
|
$response = $this->workflowModel->paginate(10); |
68
|
|
|
}else{ |
69
|
|
|
$response = $this->workflowModel->orderBy($param[0], $param[1])->paginate(10); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return response()->json($response); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* [Function] create |
78
|
|
|
* @param Request $req |
|
|
|
|
79
|
|
|
* |
80
|
|
|
* @return json |
81
|
|
|
*/ |
82
|
|
|
public function create() |
83
|
|
|
{ |
84
|
|
|
$content_type = [ |
85
|
|
|
['id' => 1,'label' => 'Posting'], |
86
|
|
|
['id' => 2,'label' => 'Posting1'], |
87
|
|
|
['id' => 3,'label' => 'SopOnline'], |
88
|
|
|
['id' => 4,'label' => 'Workflow'], |
89
|
|
|
['id' => 5,'label' => 'Pendaftaran'], |
90
|
|
|
]; |
91
|
|
|
|
92
|
|
|
return response()->json($content_type); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* [Function] store |
97
|
|
|
* @param Request $req |
98
|
|
|
* |
99
|
|
|
* @return json |
100
|
|
|
*/ |
101
|
|
|
public function store(Request $req) |
102
|
|
|
{ |
103
|
|
|
|
104
|
|
|
// $request['content_id'] = 1; |
|
|
|
|
105
|
|
|
// $request['content_type'] = $req->content_type; |
|
|
|
|
106
|
|
|
$request['label'] = $req->label; |
|
|
|
|
107
|
|
|
$request['name'] = $req->name; |
108
|
|
|
|
109
|
|
|
$validator = Validator::make($req->all(),[ |
110
|
|
|
'label' => 'required', |
111
|
|
|
'name' => 'required' |
112
|
|
|
]); |
113
|
|
|
|
114
|
|
View Code Duplication |
if($validator->fails()){ |
|
|
|
|
115
|
|
|
$response['message'] = 'failed transition allready exist !'; |
|
|
|
|
116
|
|
|
$response['status'] = false; |
117
|
|
|
}else{ |
118
|
|
|
$response['message'] = 'success add new transition'; |
|
|
|
|
119
|
|
|
$response['status'] = true; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
//$this->insertWithWorkflow($this->workflowModel, $request); |
|
|
|
|
123
|
|
|
$this->workflowModel->create($request); |
124
|
|
|
return response()->json($response); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* [Function] show |
129
|
|
|
* @param $id |
130
|
|
|
* |
131
|
|
|
* @return json |
132
|
|
|
*/ |
133
|
|
|
public function show($id) |
134
|
|
|
{ |
135
|
|
|
$check = $this->workflowTypeModel->where('workflow_id',$id)->count(); |
136
|
|
|
|
137
|
|
|
if($check > 0){ |
138
|
|
|
$response = $this->workflowModel->findOrFail($id); |
139
|
|
|
$response['workflow_type'] = ['label' =>$this->workflowModel->findOrFail($id)->getWorkflowType->workflow_type]; |
140
|
|
|
$response['content_type'] = ['label' => $this->workflowModel->findOrFail($id)->getWorkflowType->content_type]; |
141
|
|
|
$response['status'] = true; |
142
|
|
|
}else{ |
143
|
|
|
$response = $this->workflowModel->findOrFail($id); |
144
|
|
|
$response['workflow_type'] = '-'; |
145
|
|
|
$response['content_type'] = '-'; |
146
|
|
|
$response['status'] = true; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return response()->json($response); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* [Function] edit |
154
|
|
|
* @param $id |
155
|
|
|
* |
156
|
|
|
* @return json |
157
|
|
|
*/ |
158
|
|
|
public function edit($id) |
159
|
|
|
{ |
160
|
|
|
|
161
|
|
|
$response['status'] = true; |
|
|
|
|
162
|
|
|
$response['workflow'] = $this->workflowModel->findOrFail($id); |
163
|
|
|
|
164
|
|
|
return response()->json($response); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* [Function] update |
169
|
|
|
* @param $id |
170
|
|
|
* |
171
|
|
|
* @return json |
172
|
|
|
*/ |
173
|
|
|
public function update($id, Request $request) |
174
|
|
|
{ |
175
|
|
|
|
176
|
|
|
$validator = Validator::make($request->all(), [ |
177
|
|
|
'label' => 'required', |
178
|
|
|
'name' => 'required' |
179
|
|
|
]); |
180
|
|
|
|
181
|
|
|
if($validator->fails()){ |
182
|
|
|
|
183
|
|
|
$response['status'] = false; |
|
|
|
|
184
|
|
|
$response['message'] = 'failed update '; |
185
|
|
|
|
186
|
|
|
}else{ |
187
|
|
|
|
188
|
|
|
$response['status'] = true; |
|
|
|
|
189
|
|
|
$response['message'] = 'update success'; |
190
|
|
|
$this->workflowModel->findOrFail($id)->update($request->all()); |
191
|
|
|
|
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
|
196
|
|
|
return response()->json($response); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* [Function] storeWorkflow |
202
|
|
|
* @param Request $req |
203
|
|
|
* |
204
|
|
|
* @return json |
205
|
|
|
*/ |
206
|
|
|
public function storeWorkflow(Request $req, $id) |
207
|
|
|
{ |
208
|
|
|
$workflow['workflow_id'] = $id; |
|
|
|
|
209
|
|
|
$workflow['workflow_type'] = $req->workflow_type; |
210
|
|
|
$workflow['content_type'] = $req->content_type; |
211
|
|
|
|
212
|
|
|
$this->workflowTypeModel->create($workflow); |
213
|
|
|
|
214
|
|
|
return response()->json(['status' => true, 'message' => 'Success register workflow']); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* [Function] destroy |
219
|
|
|
* @param Request $req |
|
|
|
|
220
|
|
|
* |
221
|
|
|
* @return json |
222
|
|
|
*/ |
223
|
|
|
public function destroy($id) |
224
|
|
|
{ |
225
|
|
|
$state = $this->workflowModel->findOrFail($id)->delete(); |
|
|
|
|
226
|
|
|
|
227
|
|
|
return response()->json(['status' => true]); |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.