|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Itil\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Itil\Controllers\BaseServiceDeskController; |
|
6
|
|
|
use App\Itil\Models\Common\Location; |
|
7
|
|
|
use App\Itil\Models\Changes\SdLocationcategories; |
|
8
|
|
|
use App\Model\helpdesk\Agent\Department; |
|
9
|
|
|
use App\Itil\Requests\CreateLocationRequest; |
|
10
|
|
|
use Exception; |
|
11
|
|
|
use Illuminate\Http\Request; |
|
12
|
|
|
class LocationController extends BaseServiceDeskController { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* |
|
16
|
|
|
* @return type |
|
17
|
|
|
*/ |
|
18
|
|
|
public function index() { |
|
19
|
|
|
try { |
|
20
|
|
|
return view('itil::location.index'); |
|
21
|
|
|
} catch (Exception $ex) { |
|
22
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* |
|
28
|
|
|
* @return type |
|
29
|
|
|
*/ |
|
30
|
|
View Code Duplication |
public function getLocation() { |
|
|
|
|
|
|
31
|
|
|
try { |
|
32
|
|
|
$locationcategorys = new Location(); |
|
33
|
|
|
$locationcategory = $locationcategorys->select('id', 'location_category_id', 'title', 'email', 'phone', 'address', 'all_department_access', 'departments', 'status', 'created_at', 'updated_at')->get(); |
|
|
|
|
|
|
34
|
|
|
return \Datatable::Collection($locationcategory) |
|
35
|
|
|
->addColumn('location_category_id', function($model) { |
|
36
|
|
|
$name = "--"; |
|
37
|
|
|
$location_categories = new SdLocationcategories; |
|
38
|
|
|
$location_category = $location_categories->where('id', $model->location_category_id)->first(); |
|
|
|
|
|
|
39
|
|
|
if($location_category){ |
|
40
|
|
|
$name = $location_category->name; |
|
41
|
|
|
} |
|
42
|
|
|
return $name; |
|
43
|
|
|
}) |
|
44
|
|
|
->showColumns('title', 'email', 'phone', 'address') |
|
45
|
|
|
->addColumn('action', function($model) { |
|
46
|
|
|
return "<a href=" . url('service-desk/location-types/' . $model->id . '/edit') . " class='btn btn-info btn-sm'>Edit</a> <a href=" . url('service-desk/location-types/' . $model->id . '/show') . " class='btn btn-primary btn-sm'>View</a>"; |
|
47
|
|
|
}) |
|
48
|
|
|
->searchColumns('title', 'email', 'phone', 'address') |
|
49
|
|
|
->orderColumns('location_category_id', 'title', 'email', 'phone', 'address') |
|
50
|
|
|
->make(); |
|
51
|
|
|
} catch (Exception $ex) { |
|
52
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* |
|
58
|
|
|
* @return type |
|
59
|
|
|
*/ |
|
60
|
|
View Code Duplication |
public function create() { |
|
|
|
|
|
|
61
|
|
|
try { |
|
62
|
|
|
$departments = Department::all(array('id', 'name')); |
|
63
|
|
|
$location_category = SdLocationcategories::all(array('id', 'name')); |
|
64
|
|
|
$organizations = \App\Model\helpdesk\Agent_panel\Organization::lists('name', 'id')->toArray(); |
|
65
|
|
|
return view('itil::location.create', compact('departments', 'location_category', 'organizations')); |
|
66
|
|
|
} catch (Exception $ex) { |
|
67
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* |
|
73
|
|
|
* @param CreateLocationRequest $request |
|
74
|
|
|
* @return type |
|
75
|
|
|
*/ |
|
76
|
|
View Code Duplication |
public function handleCreate(CreateLocationRequest $request) { |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
try { |
|
79
|
|
|
$sd_location = new Location(); |
|
80
|
|
|
$sd_location->title = $request->title; |
|
|
|
|
|
|
81
|
|
|
$sd_location->email = $request->email; |
|
|
|
|
|
|
82
|
|
|
$sd_location->phone = $request->phone; |
|
|
|
|
|
|
83
|
|
|
$sd_location->address = $request->address; |
|
|
|
|
|
|
84
|
|
|
$sd_location->location_category_id = $request->location_category; |
|
|
|
|
|
|
85
|
|
|
$sd_location->departments = $request->department; |
|
|
|
|
|
|
86
|
|
|
$sd_location->organization = $request->organization; |
|
|
|
|
|
|
87
|
|
|
$sd_location->save(); |
|
88
|
|
|
return \Redirect::route('service-desk.location.index')->with('message', 'Location successfully created'); |
|
89
|
|
|
} catch (Exception $ex) { |
|
90
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* |
|
96
|
|
|
* @param type $id |
|
97
|
|
|
* @return type |
|
98
|
|
|
*/ |
|
99
|
|
|
public function edit($id) { |
|
100
|
|
|
try { |
|
101
|
|
|
// dd($id); |
|
|
|
|
|
|
102
|
|
|
$location_category_name = ""; |
|
103
|
|
|
$departments_name = ""; |
|
104
|
|
|
$sd_location = Location::findOrFail($id); |
|
105
|
|
|
$departments = Department::whereid($sd_location->departments)->first(); |
|
106
|
|
|
if($departments){ |
|
107
|
|
|
$departments_name = $departments->name; |
|
108
|
|
|
} |
|
109
|
|
|
$location_category = SdLocationcategories::whereid($sd_location->location_category_id)->first(); |
|
110
|
|
|
if($location_category){ |
|
111
|
|
|
$location_category_name = $location_category->name; |
|
112
|
|
|
} |
|
113
|
|
|
$departments = Department::all(array('id', 'name')); |
|
114
|
|
|
$location_category = SdLocationcategories::all(array('id', 'name')); |
|
115
|
|
|
$organizations = \App\Model\helpdesk\Agent_panel\Organization::lists('name', 'id')->toArray(); |
|
116
|
|
|
return view('itil::location.edit', compact('departments', 'location_category', 'location_category_name', 'departments_name', 'sd_location', 'organizations')); |
|
117
|
|
|
} catch (Exception $ex) { |
|
118
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* |
|
124
|
|
|
* @param CreateLocationRequest $request |
|
125
|
|
|
* @return type |
|
126
|
|
|
*/ |
|
127
|
|
View Code Duplication |
public function handleEdit(CreateLocationRequest $request) { |
|
|
|
|
|
|
128
|
|
|
try { |
|
129
|
|
|
$id = $request->location_id; |
|
|
|
|
|
|
130
|
|
|
$sd_location = Location::findOrFail($id); |
|
131
|
|
|
$sd_location->email = $request->email; |
|
|
|
|
|
|
132
|
|
|
$sd_location->title = $request->title; |
|
|
|
|
|
|
133
|
|
|
$sd_location->phone = $request->phone; |
|
|
|
|
|
|
134
|
|
|
$sd_location->address = $request->address; |
|
|
|
|
|
|
135
|
|
|
$sd_location->location_category_id = $request->location_category; |
|
|
|
|
|
|
136
|
|
|
$sd_location->departments = $request->department; |
|
|
|
|
|
|
137
|
|
|
$sd_location->organization = $request->organization; |
|
|
|
|
|
|
138
|
|
|
$sd_location->save(); |
|
139
|
|
|
return \Redirect::route('service-desk.location.index')->with('message', 'Location successfully Updated'); |
|
140
|
|
|
} catch (Exception $ex) { |
|
141
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* |
|
147
|
|
|
* @param type $id |
|
148
|
|
|
* @return type |
|
149
|
|
|
*/ |
|
150
|
|
|
public function handledelete($id) { |
|
151
|
|
|
try { |
|
152
|
|
|
$sd_location = Location::findOrFail($id); |
|
153
|
|
|
$sd_location->delete(); |
|
154
|
|
|
return \Redirect::route('service-desk.location-category.index')->with('message', 'Location successfully delete !!!'); |
|
155
|
|
|
} catch (Exception $ex) { |
|
156
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
View Code Duplication |
public function show($id) { |
|
|
|
|
|
|
161
|
|
|
try { |
|
162
|
|
|
$locations = new Location(); |
|
163
|
|
|
$location = $locations->find($id); |
|
|
|
|
|
|
164
|
|
|
if ($location) { |
|
165
|
|
|
return view('itil::location.show', compact('location')); |
|
166
|
|
|
} else { |
|
167
|
|
|
throw new \Exception('Sorry we can not find your request'); |
|
168
|
|
|
} |
|
169
|
|
|
} catch (Exception $ex) { |
|
170
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function getLocationsForForm(Request $request) { |
|
175
|
|
|
$id = $request->input('id'); |
|
176
|
|
|
$assets = new \App\Itil\Model\Assets\SdAssets(); |
|
177
|
|
|
$asset = $assets->find($id); |
|
178
|
|
|
$location_id = ''; |
|
179
|
|
|
$select = ""; |
|
180
|
|
|
if($asset){ |
|
181
|
|
|
$location_id = $asset->location_id; |
|
182
|
|
|
} |
|
183
|
|
|
$html = "<option value=''>Select</option>"; |
|
184
|
|
|
$orgid = $request->input('org'); |
|
185
|
|
|
$location = $this->getLocationsByOrg($orgid); |
|
186
|
|
|
$locations = $location->lists('title', 'id')->toArray(); |
|
187
|
|
|
if (count($locations) > 0) { |
|
188
|
|
|
foreach ($locations as $key => $value) { |
|
189
|
|
|
if($key==$location_id){ |
|
190
|
|
|
$select = 'selected'; |
|
191
|
|
|
} |
|
192
|
|
|
$html .= "<option value='" . $key . "' $select>" . $value . "</option>"; |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
return $html; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function getLocationsByOrg($orgid) { |
|
199
|
|
|
$location = new Location(); |
|
200
|
|
|
$locations = $location->where('organization', $orgid); |
|
|
|
|
|
|
201
|
|
|
return $locations; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
} |
|
205
|
|
|
|
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.