1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Itil\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Itil\Controllers\BaseServiceDeskController; |
6
|
|
|
use App\Itil\Models\Changes\SdChanges; |
7
|
|
|
use App\Itil\Models\Changes\SdChangestatus; |
8
|
|
|
use App\Itil\Models\Changes\SdChangepriorities; |
9
|
|
|
use App\Itil\Models\Changes\SdChangetypes; |
10
|
|
|
use App\Itil\Models\Changes\SdImpacttypes; |
11
|
|
|
use App\Itil\Models\Releases\SdLocations; |
12
|
|
|
use App\Itil\Requests\CreateChangesRequest; |
13
|
|
|
use App\User; |
14
|
|
|
use App\Itil\Models\Common\Cab; |
15
|
|
|
use Exception; |
16
|
|
|
use App\Itil\Requests\CreateReleaseRequest; |
17
|
|
|
use Illuminate\Http\Request; |
18
|
|
|
|
19
|
|
|
class ChangesController extends BaseServiceDeskController { |
20
|
|
|
|
21
|
|
|
public function __construct() { |
22
|
|
|
$this->middleware('auth'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function changesindex() { |
26
|
|
|
try { |
27
|
|
|
return view('itil::changes.index'); |
28
|
|
|
} catch (Exception $ex) { |
29
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
public function getChanges() { |
|
|
|
|
34
|
|
|
try { |
35
|
|
|
$change = new SdChanges(); |
36
|
|
|
$changes = $change->select('id', 'description', 'subject', 'status_id', 'priority_id', 'change_type_id', 'impact_id', 'location_id', 'approval_id')->get(); |
|
|
|
|
37
|
|
|
return \Datatable::Collection($changes) |
38
|
|
|
->showColumns('subject', 'reason') |
39
|
|
|
->addColumn('action', function($model) { |
40
|
|
|
$url = url('service-desk/changes/' . $model->id . '/delete'); |
41
|
|
|
$delete = \App\Itil\Controllers\UtilityController::deletePopUp($model->id, $url, "Delete $model->subject"); |
42
|
|
|
//dd($delete); |
43
|
|
|
return "<a href=" . url('service-desk/changes/' . $model->id . '/edit') . " class='btn btn-info btn-sm'>Edit</a> " |
44
|
|
|
. $delete |
45
|
|
|
. " <a href=" . url('service-desk/changes/' . $model->id . '/show') . " class='btn btn-primary btn-sm'>View</a>"; |
46
|
|
|
}) |
47
|
|
|
->searchColumns('description') |
48
|
|
|
->orderColumns('description', 'subject', 'reason', 'status_id', 'priority_id', 'change_type_id', 'impact_id', 'location_id', 'approval_id') |
49
|
|
|
->make(); |
50
|
|
|
} catch (Exception $ex) { |
51
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function changescreate() { |
56
|
|
|
try { |
57
|
|
|
$statuses = SdChangestatus::lists('name', 'id')->toArray(); |
58
|
|
|
$sd_changes_priorities = SdChangepriorities::lists('name', 'id')->toArray(); |
59
|
|
|
$sd_changes_types = SdChangetypes::lists('name', 'id')->toArray(); |
60
|
|
|
$sd_impact_types = SdImpacttypes::lists('name', 'id')->toArray(); |
61
|
|
|
$sd_locations = SdLocations::lists('title', 'id')->toArray(); |
62
|
|
|
$users = Cab::lists('name', 'id')->toArray(); |
63
|
|
|
// $assets = SdAssets::lists('name', 'id')->toArray(); |
|
|
|
|
64
|
|
|
$requester = User::where('role', 'agent')->orWhere('role', 'admin')->lists('email', 'id')->toArray(); |
65
|
|
|
|
66
|
|
|
return view('itil::changes.create', compact('statuses', 'sd_changes_priorities', 'sd_changes_types', 'sd_impact_types', 'sd_locations', 'users', 'requester')); |
67
|
|
|
} catch (Exception $ex) { |
68
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function changeshandleCreate(CreateChangesRequest $request, $attach = false) { |
73
|
|
|
// dd($request->all()); |
|
|
|
|
74
|
|
|
try { |
75
|
|
|
$sd_changes = new SdChanges; |
76
|
|
|
$sd_changes->fill($request->input())->save(); |
|
|
|
|
77
|
|
|
\App\Itil\Controllers\UtilityController::attachment($sd_changes->id, 'sd_changes', $request->file('attachments')); |
|
|
|
|
78
|
|
|
if (isAsset() == true) { |
|
|
|
|
79
|
|
|
\App\Itil\Controllers\UtilityController::storeAssetRelation('sd_changes', $sd_changes->id, $request->input('asset')); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
if ($attach == false) { |
|
|
|
|
82
|
|
|
return \Redirect::route('service-desk.changes.index')->with('message', 'Changes successfull !!!'); |
83
|
|
|
} |
84
|
|
|
return $sd_changes; |
85
|
|
|
} catch (Exception $ex) { |
86
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function changesedit($id) { |
91
|
|
|
try { |
92
|
|
|
|
93
|
|
|
$change = SdChanges::findOrFail($id); |
94
|
|
|
$statuses = SdChangestatus::lists('name', 'id')->toArray(); |
95
|
|
|
$sd_changes_status = ""; |
96
|
|
|
$sd_changes_priorities = SdChangepriorities::lists('name', 'id')->toArray(); |
97
|
|
|
$sd_changes_types = SdChangetypes::lists('name', 'id')->toArray(); |
98
|
|
|
$sd_impact_types = SdImpacttypes::lists('name', 'id')->toArray(); |
99
|
|
|
$sd_locations = SdLocations::lists('title', 'id')->toArray(); |
100
|
|
|
$users = Cab::lists('name', 'id')->toArray(); |
101
|
|
|
// $assets = SdAssets::lists('name', 'id')->toArray(); |
|
|
|
|
102
|
|
|
$requester = User::where('role', 'agent')->orWhere('role', 'admin')->lists('email', 'id')->toArray(); |
103
|
|
|
return view('itil::changes.edit', compact('sd_changes_status', 'change', 'statuses', 'sd_changes_priorities', 'sd_changes_types', 'sd_impact_types', 'sd_locations', 'users', 'requester')); |
104
|
|
|
} catch (Exception $ex) { |
105
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function changeshandleEdit($id, CreateChangesRequest $request) { |
110
|
|
|
try { |
111
|
|
|
|
112
|
|
|
$sd_changes = SdChanges::findOrFail($id); |
113
|
|
|
$sd_changes->fill($request->input())->save(); |
114
|
|
|
\App\Itil\Controllers\UtilityController::attachment($sd_changes->id, 'sd_changes', $request->file('attachments')); |
115
|
|
|
if (isAsset() == true) { |
|
|
|
|
116
|
|
|
\App\Itil\Controllers\UtilityController::storeAssetRelation('sd_changes', $sd_changes->id, $request->input('asset')); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
return \Redirect::route('service-desk.changes.index')->with('message', 'Changes successfully Edit !!!'); |
119
|
|
|
} catch (Exception $ex) { |
120
|
|
|
dd($ex); |
121
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function changesHandledelete($id) { |
126
|
|
|
try { |
127
|
|
|
$sd_changes = SdChanges::findOrFail($id); |
128
|
|
|
$sd_changes->delete(); |
129
|
|
|
return \Redirect::route('service-desk.changes.index')->with('message', 'Changes successfully Delete !!!'); |
130
|
|
|
} catch (Exception $ex) { |
131
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
View Code Duplication |
public function show($id) { |
|
|
|
|
136
|
|
|
try { |
137
|
|
|
$changes = new SdChanges(); |
138
|
|
|
$change = $changes->find($id); |
|
|
|
|
139
|
|
|
if ($change) { |
140
|
|
|
return view('itil::changes.show', compact('change')); |
141
|
|
|
} else { |
142
|
|
|
throw new \Exception('Sorry we can not find your request'); |
143
|
|
|
} |
144
|
|
|
} catch (Exception $ex) { |
145
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function close($id) { |
150
|
|
|
try { |
151
|
|
|
$changes = new SdChanges(); |
152
|
|
|
$change = $changes->find($id); |
|
|
|
|
153
|
|
|
if ($change) { |
154
|
|
|
$change->status_id = 6; |
155
|
|
|
$change->save(); |
156
|
|
|
return redirect()->back()->with('success', 'Updated'); |
157
|
|
|
} else { |
158
|
|
|
throw new \Exception('Sorry we can not find your request'); |
159
|
|
|
} |
160
|
|
|
} catch (\Exception $ex) { |
161
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
View Code Duplication |
public function getReleases() { |
|
|
|
|
166
|
|
|
$release = new \App\Itil\Models\Releases\SdReleases(); |
167
|
|
|
$releases = $release->select('id', 'subject')->get(); |
|
|
|
|
168
|
|
|
return \Datatable::Collection($releases) |
169
|
|
|
->addColumn('id', function($model) { |
170
|
|
|
return "<input type='radio' name='release' value='" . $model->id . "'>"; |
171
|
|
|
}) |
172
|
|
|
->addColumn('subject', function($model) { |
173
|
|
|
return str_limit($model->subject, 20); |
174
|
|
|
}) |
175
|
|
|
->orderColumns('subject') |
176
|
|
|
->searchColumns('subject') |
177
|
|
|
->make(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
View Code Duplication |
public function attachNewRelease($id, CreateReleaseRequest $request) { |
|
|
|
|
181
|
|
|
try { |
182
|
|
|
$release_controller = new RelesesController(); |
183
|
|
|
$release = $release_controller->releaseshandleCreate($request, true); |
184
|
|
|
$this->releaseAttach($id, $release->id); |
185
|
|
|
if ($release) { |
186
|
|
|
return redirect()->back()->with('success', 'Updated'); |
187
|
|
|
} |
188
|
|
|
} catch (\Exception $ex) { |
189
|
|
|
dd($ex); |
190
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function attachExistingRelease($id, Request $request) { |
195
|
|
|
try { |
196
|
|
|
$releaseid = $request->input('release'); |
197
|
|
|
$store = $this->releaseAttach($id, $releaseid); |
198
|
|
|
if ($store) { |
199
|
|
|
return redirect()->back()->with('success', 'Updated'); |
200
|
|
|
} |
201
|
|
|
} catch (\Exception $ex) { |
202
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
206
|
|
View Code Duplication |
public function releaseAttach($changeid, $releaseid) { |
|
|
|
|
207
|
|
|
$relation = new \App\Itil\Models\Changes\ChangeReleaseRelation(); |
208
|
|
|
$relations = $relation->where('change_id', $changeid)->first(); |
|
|
|
|
209
|
|
|
if ($relations) { |
210
|
|
|
$relations->delete(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
return $relation->create([ |
214
|
|
|
'release_id' => $releaseid, |
215
|
|
|
'change_id' => $changeid, |
216
|
|
|
]); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
View Code Duplication |
public function detachRelease($changeid) { |
|
|
|
|
220
|
|
|
try { |
221
|
|
|
$relations = new \App\Itil\Models\Changes\ChangeReleaseRelation(); |
222
|
|
|
$relation = $relations->where('change_id', $changeid)->first(); |
|
|
|
|
223
|
|
|
if ($relation) { |
224
|
|
|
$relation->delete(); |
225
|
|
|
} |
226
|
|
|
return redirect()->back()->with('success', 'Updated'); |
227
|
|
|
} catch (\Exception $ex) { |
228
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
} |
233
|
|
|
|
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.