1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jawaraegov\Workflows\Traits; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use App\Http\Controllers\Controller; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Jawaraegov\Workflows\Facades\Workflow; |
9
|
|
|
use Jawaraegov\Workflows\Models\WorkflowTransition; |
10
|
|
|
use Jawaraegov\Workflows\Models\WorkflowState; |
11
|
|
|
use That0n3guy\Transliteration; |
12
|
|
|
|
13
|
|
|
trait WorkflowTransitionTrait |
14
|
|
|
{ |
15
|
|
|
public static function transitionIndex($page = 10) |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
$transitions = WorkflowTransition::paginate($page); |
19
|
|
|
$state = array(); |
|
|
|
|
20
|
|
|
|
21
|
|
|
return view('workflow::workflow.transition.index',compact('transitions')); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public static function transitionCreate() |
25
|
|
|
{ |
26
|
|
|
$states = WorkflowState::all(); |
27
|
|
|
|
28
|
|
|
return view('workflow::workflow.transition.create',compact('states')); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function transitionStore($request = array()) |
32
|
|
|
{ |
33
|
|
|
$name = str_replace('_','-',\Transliteration::clean_filename(strtolower($req->label))); |
|
|
|
|
34
|
|
|
$label = $request->label; |
35
|
|
|
$from = join(',',$request->from); |
36
|
|
|
$to = join(',',$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
|
|
View Code Duplication |
public static function transitionEdit($id) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$transition = WorkflowTransition::where('id',$id)->first(); |
60
|
|
|
$states = WorkflowState::all(); |
61
|
|
|
|
62
|
|
|
return view('workflow::workflow.transitionedit',['transition' => $transition, 'states' => $states]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public static function transitionUpdate($request = array(), $id) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$name = str_replace('_','-',\Transliteration::clean_filename(strtolower($request->label))); |
68
|
|
|
$label = $request->label; |
69
|
|
|
$from = join(',',$request->from); |
70
|
|
|
$to = $request->to; |
71
|
|
|
|
72
|
|
|
try |
73
|
|
|
{ |
74
|
|
|
WorkflowTransition::where('id',$id)->update([ |
75
|
|
|
'label' => $label, |
76
|
|
|
'name' => $name, |
77
|
|
|
'from' => $from, |
78
|
|
|
'to' => $to |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
catch(\Illuminate\Database\QueryException $e){ |
|
|
|
|
82
|
|
|
// do what you want here with $e->getMessage(); |
83
|
|
|
return redirect()->route('transition')->with('message', 'Error'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
|
88
|
|
|
return redirect()->route('transition')->with('message', 'Update data success'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public static function transitionActive($id){ |
92
|
|
|
WorkflowTransition::where('id',$id)->update(['status' => 1]); |
93
|
|
|
|
94
|
|
|
return redirect()->back(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public static function transitionDeActive($id){ |
98
|
|
|
WorkflowTransition::where('id',$id)->update(['status' => 0]); |
99
|
|
|
|
100
|
|
|
return redirect()->back(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.