App\Http\Controllers\ManufacturersController Class Reference

This controller handles all actions related to Manufacturers for the Snipe-IT Asset Management application. More...

Inheritance diagram for App\Http\Controllers\ManufacturersController:
App\Http\Controllers\Controller

Public Member Functions

 getIndex ()
 Returns a view that invokes the ajax tables which actually contains the content for the manufacturers listing, which is generated in getDatatable. More...
 
 getCreate ()
 Returns a view that displays a form to create a new manufacturer. More...
 
 postCreate ()
 Validates and stores the data for a new manufacturer. More...
 
 getEdit ($manufacturerId=null)
 Returns a view that displays a form to edit a manufacturer. More...
 
 postEdit ($manufacturerId=null)
 Validates and stores the updated manufacturer data. More...
 
 getDelete ($manufacturerId)
 Deletes a manufacturer. More...
 
 getView ($manufacturerId=null)
 Returns a view that invokes the ajax tables which actually contains the content for the manufacturers detail listing, which is generated in getDatatable. More...
 
 getDatatable ()
 Generates the JSON used to display the manufacturer listings. More...
 
 getDataView ($manufacturerId)
 Generates the JSON used to display the manufacturer detail. More...
 

Detailed Description

This controller handles all actions related to Manufacturers for the Snipe-IT Asset Management application.

Version
v1.0

Definition at line 20 of file ManufacturersController.php.

Member Function Documentation

App\Http\Controllers\ManufacturersController::getCreate ( )

Returns a view that displays a form to create a new manufacturer.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
ManufacturersController::postCreate()
Since
[v1.0]
Returns
View

Definition at line 46 of file ManufacturersController.php.

47  {
48  return View::make('manufacturers/edit')->with('manufacturer', new Manufacturer);
49  }
App\Http\Controllers\ManufacturersController::getDatatable ( )

Generates the JSON used to display the manufacturer listings.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
ManufacturersController::getIndex()
Since
[v1.0]
Returns
String JSON

Definition at line 196 of file ManufacturersController.php.

197  {
198  $manufacturers = Manufacturer::select(array('id','name'))->with('assets')
199  ->whereNull('deleted_at');
200 
201  if (Input::has('search')) {
202  $manufacturers = $manufacturers->TextSearch(e(Input::get('search')));
203  }
204 
205  if (Input::has('offset')) {
206  $offset = e(Input::get('offset'));
207  } else {
208  $offset = 0;
209  }
210 
211  if (Input::has('limit')) {
212  $limit = e(Input::get('limit'));
213  } else {
214  $limit = 50;
215  }
216 
217  $allowed_columns = ['id','name'];
218  $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
219  $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
220 
221  $manufacturers->orderBy($sort, $order);
222 
223  $manufacturersCount = $manufacturers->count();
224  $manufacturers = $manufacturers->skip($offset)->take($limit)->get();
225 
226  $rows = array();
227 
228  foreach ($manufacturers as $manufacturer) {
229  $actions = '<a href="'.route('update/manufacturer', $manufacturer->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/manufacturer', $manufacturer->id).'" data-content="'.trans('admin/manufacturers/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($manufacturer->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
230 
231  $rows[] = array(
232  'id' => $manufacturer->id,
233  'name' => (string)link_to('admin/settings/manufacturers/'.$manufacturer->id.'/view', e($manufacturer->name)),
234  'assets' => $manufacturer->assets->count(),
235  'actions' => $actions
236  );
237  }
238 
239  $data = array('total' => $manufacturersCount, 'rows' => $rows);
240 
241  return $data;
242 
243  }
App\Http\Controllers\ManufacturersController::getDataView (   $manufacturerId)

Generates the JSON used to display the manufacturer detail.

This JSON returns data on all of the assets with the specified manufacturer ID number.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
ManufacturersController::getView()
Parameters
int$manufacturerId
Since
[v1.0]
Returns
String JSON

Definition at line 257 of file ManufacturersController.php.

258  {
259 
260  $manufacturer = Manufacturer::with('assets.company')->find($manufacturerId);
261  $manufacturer_assets = $manufacturer->assets;
262 
263  if (Input::has('search')) {
264  $manufacturer_assets = $manufacturer_assets->TextSearch(e(Input::get('search')));
265  }
266 
267  if (Input::has('offset')) {
268  $offset = e(Input::get('offset'));
269  } else {
270  $offset = 0;
271  }
272 
273  if (Input::has('limit')) {
274  $limit = e(Input::get('limit'));
275  } else {
276  $limit = 50;
277  }
278 
279  $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
280 
281  $allowed_columns = ['id','name','serial','asset_tag'];
282  $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
283  $count = $manufacturer_assets->count();
284 
285  $rows = array();
286 
287  foreach ($manufacturer_assets as $asset) {
288 
289  $actions = '';
290  if ($asset->deleted_at=='') {
291  $actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="'.route('update/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/hardware', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
292  } elseif ($asset->deleted_at!='') {
293  $actions = '<a href="'.route('restore/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
294  }
295 
296  if ($asset->assetstatus) {
297  if ($asset->assetstatus->deployable != 0) {
298  if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) {
299  $inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';
300  } else {
301  $inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';
302  }
303  }
304  }
305 
306  $row = array(
307  'id' => $asset->id,
308  'name' => (string)link_to('/hardware/'.$asset->id.'/view', e($asset->showAssetName())),
309  'model' => e($asset->model->name),
310  'asset_tag' => e($asset->asset_tag),
311  'serial' => e($asset->serial),
312  'assigned_to' => ($asset->assigneduser) ? (string)link_to('/admin/users/'.$asset->assigneduser->id.'/view', e($asset->assigneduser->fullName())): '',
313  'actions' => $actions,
314  'companyName' => e(Company::getName($asset)),
315  );
316 
317  if (isset($inout)) {
318  $row['change'] = $inout;
319  }
320 
321  $rows[] = $row;
322  }
323 
324  $data = array('total' => $count, 'rows' => $rows);
325  return $data;
326  }
App\Http\Controllers\ManufacturersController::getDelete (   $manufacturerId)

Deletes a manufacturer.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$manufacturerId
Since
[v1.0]
Returns
View

Definition at line 135 of file ManufacturersController.php.

136  {
137  // Check if the manufacturer exists
138  if (is_null($manufacturer = Manufacturer::find($manufacturerId))) {
139  // Redirect to the manufacturers page
140  return Redirect::to('admin/settings/manufacturers')->with('error', trans('admin/manufacturers/message.not_found'));
141  }
142 
143  if ($manufacturer->has_models() > 0) {
144 
145  // Redirect to the asset management page
146  return Redirect::to('admin/settings/manufacturers')->with('error', trans('admin/manufacturers/message.assoc_users'));
147  } else {
148 
149  // Delete the manufacturer
150  $manufacturer->delete();
151 
152  // Redirect to the manufacturers management page
153  return Redirect::to('admin/settings/manufacturers')->with('success', trans('admin/manufacturers/message.delete.success'));
154  }
155 
156  }
App\Http\Controllers\ManufacturersController::getEdit (   $manufacturerId = null)

Returns a view that displays a form to edit a manufacturer.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
ManufacturersController::postEdit()
Parameters
int$manufacturerId
Since
[v1.0]
Returns
View

Definition at line 83 of file ManufacturersController.php.

84  {
85  // Check if the manufacturer exists
86  if (is_null($manufacturer = Manufacturer::find($manufacturerId))) {
87  // Redirect to the manufacturer page
88  return Redirect::to('admin/settings/manufacturers')->with('error', trans('admin/manufacturers/message.does_not_exist'));
89  }
90 
91  // Show the page
92  return View::make('manufacturers/edit', compact('manufacturer'));
93  }
App\Http\Controllers\ManufacturersController::getIndex ( )

Returns a view that invokes the ajax tables which actually contains the content for the manufacturers listing, which is generated in getDatatable.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
ManufacturersController::getDatatable() method that generates the JSON response
Since
[v1.0]
Returns
View

Definition at line 31 of file ManufacturersController.php.

32  {
33  // Show the page
34  return View::make('manufacturers/index', compact('manufacturers'));
35  }
App\Http\Controllers\ManufacturersController::getView (   $manufacturerId = null)

Returns a view that invokes the ajax tables which actually contains the content for the manufacturers detail listing, which is generated in getDatatable.

This data contains a listing of all assets that belong to that manufacturer.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
ManufacturersController::getDataView()
Parameters
int$manufacturerId
Since
[v1.0]
Returns
View

Definition at line 171 of file ManufacturersController.php.

172  {
173  $manufacturer = Manufacturer::find($manufacturerId);
174 
175  if (isset($manufacturer->id)) {
176  return View::make('manufacturers/view', compact('manufacturer'));
177  } else {
178  // Prepare the error message
179  $error = trans('admin/manufacturers/message.does_not_exist', compact('id'));
180 
181  // Redirect to the user management page
182  return Redirect::route('manufacturers')->with('error', $error);
183  }
184 
185 
186  }
App\Http\Controllers\ManufacturersController::postCreate ( )

Validates and stores the data for a new manufacturer.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
ManufacturersController::postCreate()
Since
[v1.0]
Returns
Redirect

Definition at line 60 of file ManufacturersController.php.

61  {
62  $manufacturer = new Manufacturer;
63  $manufacturer->name = e(Input::get('name'));
64  $manufacturer->user_id = Auth::user()->id;
65 
66  if ($manufacturer->save()) {
67  return Redirect::to("admin/settings/manufacturers")->with('success', trans('admin/manufacturers/message.create.success'));
68  }
69 
70  return Redirect::back()->withInput()->withErrors($manufacturer->getErrors());
71 
72  }
App\Http\Controllers\ManufacturersController::postEdit (   $manufacturerId = null)

Validates and stores the updated manufacturer data.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
ManufacturersController::getEdit()
Parameters
int$manufacturerId
Since
[v1.0]
Returns
View

Definition at line 105 of file ManufacturersController.php.

106  {
107  // Check if the manufacturer exists
108  if (is_null($manufacturer = Manufacturer::find($manufacturerId))) {
109  // Redirect to the manufacturer page
110  return Redirect::to('admin/settings/manufacturers')->with('error', trans('admin/manufacturers/message.does_not_exist'));
111  }
112 
113  // Save the data
114  $manufacturer->name = e(Input::get('name'));
115 
116  // Was it created?
117  if ($manufacturer->save()) {
118  // Redirect to the new manufacturer page
119  return Redirect::to("admin/settings/manufacturers")->with('success', trans('admin/manufacturers/message.update.success'));
120  }
121 
122  return Redirect::back()->withInput()->withErrors($manufacturer->getErrors());
123 
124 
125  }

The documentation for this class was generated from the following file: