1
|
|
|
<?php namespace Jawaraegov\Workflows\Http\Controllers; |
2
|
|
|
|
3
|
|
|
use App\Http\Controllers\Controller; |
4
|
|
|
use Illuminate\Http\Request; |
5
|
|
|
use Jawaraegov\Workflows\Facades\Workflow; |
6
|
|
|
use Jawaraegov\Workflows\Models\WorkflowModel; |
7
|
|
|
use Jawaraegov\Workflows\Models\WorkflowTransition; |
8
|
|
|
use Jawaraegov\Workflows\Models\WorkflowState; |
9
|
|
|
use That0n3guy\Transliteration; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* The WorkflowController class. |
13
|
|
|
* |
14
|
|
|
* @package Jawaraegov\Workflows |
15
|
|
|
* @author Jawaraegov <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class WorkflowController extends Controller |
18
|
|
|
{ |
19
|
|
|
public function demo() |
20
|
|
|
{ |
21
|
|
|
return Workflow::welcome(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function index() |
25
|
|
|
{ |
26
|
|
|
$workflows = WorkflowModel::paginate(10); |
27
|
|
|
return view('workflow.workflow.index',compact('workflows')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function create() |
31
|
|
|
{ |
32
|
|
|
$dir = base_path('/app'); |
33
|
|
|
$files = scandir($dir); |
34
|
|
|
|
35
|
|
|
$models = array(); |
36
|
|
|
$namespace = 'App\\'; |
37
|
|
View Code Duplication |
foreach($files as $file) { |
|
|
|
|
38
|
|
|
// skip current and parent folder entries and non-php files |
39
|
|
|
if (preg_match("/.php/",$file)){ |
40
|
|
|
$models[] = $namespace . preg_replace("/.php/", "", $file); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
return view('workflow.workflow.create',compact('models')); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function store(Request $request) |
47
|
|
|
{ |
48
|
|
|
$name = \Transliteration::clean_filename(strtolower($request->label)); |
49
|
|
|
$label = $request->label; |
50
|
|
|
$content_type = $request->content_type; |
|
|
|
|
51
|
|
|
|
52
|
|
|
try |
53
|
|
|
{ |
54
|
|
|
WorkflowModel::create([ |
55
|
|
|
'name' => $name, |
56
|
|
|
'label' => $label, |
57
|
|
|
'content_type' => $content_type |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
catch(\Illuminate\Database\QueryException $e){ |
|
|
|
|
61
|
|
|
// do what you want here with $e->getMessage(); |
62
|
|
|
return redirect()->route('workflow')->with('message', 'Error'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return redirect()->route('workflow')->with('message', 'Add data success'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function show($id) |
69
|
|
|
{ |
70
|
|
|
// |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function edit($id) |
74
|
|
|
{ |
75
|
|
|
$dir = base_path('/app'); |
76
|
|
|
$files = scandir($dir); |
77
|
|
|
|
78
|
|
|
$models = array(); |
79
|
|
|
$namespace = 'App\\'; |
80
|
|
View Code Duplication |
foreach($files as $file) { |
|
|
|
|
81
|
|
|
// skip current and parent folder entries and non-php files |
82
|
|
|
if (preg_match("/.php/",$file)){ |
83
|
|
|
$models[] = $namespace . preg_replace("/.php/", "", $file); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
$workflow = WorkflowModel::where('id',$id)->first(); |
87
|
|
|
|
88
|
|
|
return view('workflow.workflow.edit',compact('workflow','models')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function update(Request $request, $id) |
92
|
|
|
{ |
93
|
|
|
$name = \Transliteration::clean_filename(strtolower($request->label)); |
94
|
|
|
$label = $request->label; |
95
|
|
|
$content_type = $request->content_type; |
|
|
|
|
96
|
|
|
|
97
|
|
|
try |
98
|
|
|
{ |
99
|
|
|
WorkflowModel::where('id',$id)->update(['label' => $label, 'name' => $name, 'content_type' => $content_type]); |
100
|
|
|
} |
101
|
|
|
catch(\Illuminate\Database\QueryException $e){ |
|
|
|
|
102
|
|
|
// do what you want here with $e->getMessage(); |
103
|
|
|
return redirect()->route('workflow')->with('message', 'Error'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return redirect()->route('workflow')->with('message', 'Update data success'); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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.