|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jawaraegov\Workflows\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Jawaraegov\Workflows\Facades\Workflow; |
|
8
|
|
|
use Jawaraegov\Workflows\Models\WorkflowTransition; |
|
9
|
|
|
use Jawaraegov\Workflows\Models\WorkflowState; |
|
10
|
|
|
use That0n3guy\Transliteration; |
|
11
|
|
|
|
|
12
|
|
|
class WorkflowTransitionController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
public function index() |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
$transitions = WorkflowTransition::paginate(10); |
|
19
|
|
|
$state = array(); |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
return view('workflow.transition.index',compact('transitions')); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function create() |
|
25
|
|
|
{ |
|
26
|
|
|
$states = WorkflowState::all(); |
|
27
|
|
|
|
|
28
|
|
|
return view('workflow.transition.create',compact('states')); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function store(Request $request) |
|
32
|
|
|
{ |
|
33
|
|
|
$name = str_replace('_','-',\Transliteration::clean_filename(strtolower($request->label))); |
|
34
|
|
|
$label = $request->label; |
|
35
|
|
|
$from = $request->from; |
|
36
|
|
|
$to = $request->to; |
|
37
|
|
|
$message = $request->message; |
|
38
|
|
|
|
|
39
|
|
|
try |
|
40
|
|
|
{ |
|
41
|
|
|
WorkflowTransition::create([ |
|
42
|
|
|
'name' => $name, |
|
43
|
|
|
'label' => $label, |
|
44
|
|
|
'from' => $from, |
|
45
|
|
|
'to' => $to, |
|
46
|
|
|
'message' => $message |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
catch(\Illuminate\Database\QueryException $e){ |
|
|
|
|
|
|
50
|
|
|
// do what you want here with $e->getMessage(); |
|
51
|
|
|
return redirect()->route('transition')->with('message', 'Error'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return redirect()->route('transition')->with('message', 'Add data success'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function show($id) |
|
58
|
|
|
{ |
|
59
|
|
|
// |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
View Code Duplication |
public function edit($id) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
$transition = WorkflowTransition::where('id',$id)->first(); |
|
65
|
|
|
$states = WorkflowState::all(); |
|
66
|
|
|
|
|
67
|
|
|
return view('workflow.transitionedit',['transition' => $transition, 'states' => $states]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
View Code Duplication |
public function update(Request $request, $id) |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
$name = str_replace('_','-',\Transliteration::clean_filename(strtolower($request->label))); |
|
73
|
|
|
$label = $request->label; |
|
74
|
|
|
$from = $request->from; |
|
75
|
|
|
$to = $request->to; |
|
76
|
|
|
|
|
77
|
|
|
try |
|
78
|
|
|
{ |
|
79
|
|
|
WorkflowTransition::where('id',$id)->update([ |
|
80
|
|
|
'label' => $label, |
|
81
|
|
|
'name' => $name, |
|
82
|
|
|
'from' => $from, |
|
83
|
|
|
'to' => $to |
|
84
|
|
|
]); |
|
85
|
|
|
} |
|
86
|
|
|
catch(\Illuminate\Database\QueryException $e){ |
|
|
|
|
|
|
87
|
|
|
// do what you want here with $e->getMessage(); |
|
88
|
|
|
return redirect()->route('transition')->with('message', 'Error'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
return redirect()->route('transition')->with('message', 'Update data success'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function Active($id){ |
|
97
|
|
|
WorkflowTransition::where('id',$id)->update(['status' => 1]); |
|
98
|
|
|
|
|
99
|
|
|
return redirect()->back(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function DeActive($id){ |
|
103
|
|
|
WorkflowTransition::where('id',$id)->update(['status' => 0]); |
|
104
|
|
|
|
|
105
|
|
|
return redirect()->back(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function destroy($id) |
|
109
|
|
|
{ |
|
110
|
|
|
// |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.