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 WorkflowStateTrait |
14
|
|
|
{ |
15
|
|
|
public static function stateIndex($page = 10) |
16
|
|
|
{ |
17
|
|
|
$states = WorkflowState::paginate($page); |
18
|
|
|
|
19
|
|
|
return view('workflow::workflow.state.index',compact('states')); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public static function stateCreate() |
23
|
|
|
{ |
24
|
|
|
return view('workflow::workflow.state.create'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public static function stateStore($request = array()) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$name = \Transliteration::clean_filename(strtolower($request->label)); |
30
|
|
|
$label = $request->label; |
31
|
|
|
|
32
|
|
|
try |
33
|
|
|
{ |
34
|
|
|
WorkflowState::create([ |
35
|
|
|
'name' => $name, |
36
|
|
|
'label' => $label, |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
catch(\Illuminate\Database\QueryException $e){ |
|
|
|
|
40
|
|
|
// do what you want here with $e->getMessage(); |
41
|
|
|
return redirect()->route('state')->with('message', 'Error'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return redirect()->route('state')->with('message', 'Add data success'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public static function stateEdit($id) |
48
|
|
|
{ |
49
|
|
|
$state = WorkflowState::where('id',$id)->first(); |
50
|
|
|
|
51
|
|
|
return view('workflow::workflow.state.edit',['state' => $state]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public static function stateUpdate($request = array(), $id) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$name = \Transliteration::clean_filename(strtolower($request->label)); |
57
|
|
|
$label = $request->label; |
58
|
|
|
|
59
|
|
|
try |
60
|
|
|
{ |
61
|
|
|
WorkflowState::where('id',$id)->update(['label' => $label, 'name' => $name]); |
62
|
|
|
} |
63
|
|
|
catch(\Illuminate\Database\QueryException $e){ |
|
|
|
|
64
|
|
|
// do what you want here with $e->getMessage(); |
65
|
|
|
return redirect()->route('state')->with('message', 'Error'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return redirect()->route('state')->with('message', 'Update data success'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public static function stateActive($id){ |
72
|
|
|
WorkflowState::where('id',$id)->update(['status' => 1]); |
73
|
|
|
|
74
|
|
|
return redirect()->back(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public static function stateDeActive($id){ |
78
|
|
|
WorkflowState::where('id',$id)->update(['status' => 0]); |
79
|
|
|
|
80
|
|
|
return redirect()->back(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.