This controller handles all actions related to Locations for the Snipe-IT Asset Management application.
More...
|
| getIndex () |
| Returns a view that invokes the ajax tables which actually contains the content for the locations listing, which is generated in getDatatable. More...
|
|
| getCreate () |
| Returns a form view used to create a new location. More...
|
|
| postCreate () |
| Validates and stores a new location. More...
|
|
| store () |
| Validates and stores a new location created via the Create Asset form modal. More...
|
|
| getEdit ($locationId=null) |
| Makes a form view to edit location information. More...
|
|
| postEdit ($locationId=null) |
| Validates and stores updated location data from edit form. More...
|
|
| getDelete ($locationId) |
| Validates and deletes selected location. More...
|
|
| getView ($locationId=null) |
| Returns a view that invokes the ajax tables which actually contains the content for the locations detail page. More...
|
|
| getDatatable () |
| Returns the JSON response to populate the bootstrap tables on the locationa view. More...
|
|
| getDataViewUsers ($locationID) |
| Returns a JSON response that contains the users association with the selected location, to be used by the location detail view. More...
|
|
| getDataViewAssets ($locationID) |
| Returns a JSON response that contains the assets association with the selected location, to be used by the location detail view. More...
|
|
This controller handles all actions related to Locations for the Snipe-IT Asset Management application.
- Version
- v1.0
Definition at line 22 of file LocationsController.php.
App\Http\Controllers\LocationsController::getCreate |
( |
| ) |
|
Returns a form view used to create a new location.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- LocationsController::postCreate() method that validates and stores the data
- Since
- [v1.0]
- Returns
- View
Definition at line 52 of file LocationsController.php.
54 $locations = Location::orderBy(
'name',
'ASC')->get();
58 $location_options = array(
'' =>
'Top Level') + $location_options;
60 return View::make(
'locations/edit')
61 ->with(
'location_options', $location_options)
62 ->with(
'location',
new Location);
static getLocationHierarchy($locations, $parent_id=null)
static flattenLocationsArray($location_options_array=null)
App\Http\Controllers\LocationsController::getDatatable |
( |
| ) |
|
Returns the JSON response to populate the bootstrap tables on the locationa view.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- LocationsController::getIndex() method that returns JSON for location index
- Since
- [v1.0]
- Returns
- View
Definition at line 289 of file LocationsController.php.
291 $locations = Location::select(array(
'locations.id',
'locations.name',
'locations.address',
'locations.address2',
'locations.city',
'locations.state',
'locations.zip',
'locations.country',
'locations.parent_id',
'locations.currency'))->with(
'assets');
294 if (Input::has(
'search')) {
295 $locations = $locations->TextSearch(e(Input::get(
'search')));
298 if (Input::has(
'offset')) {
299 $offset = e(Input::get(
'offset'));
304 if (Input::has(
'limit')) {
305 $limit = e(Input::get(
'limit'));
310 $order = Input::get(
'order') ===
'asc' ?
'asc' :
'desc';
314 switch (Input::get(
'sort')) {
316 $locations = $locations->OrderParent($order);
319 $allowed_columns = [
'id',
'name',
'address',
'city',
'state',
'country',
'currency'];
321 $sort = in_array(Input::get(
'sort'), $allowed_columns) ? Input::get(
'sort') :
'created_at';
322 $locations = $locations->orderBy($sort, $order);
327 $locationsCount = $locations->count();
328 $locations = $locations->skip($offset)->take($limit)->get();
332 foreach ($locations as $location) {
333 $actions =
'<nobr><a href="'.route(
'update/location', $location->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/location', $location->id).
'" data-content="'.trans(
'admin/locations/message.delete.confirm').
'" data-title="'.trans(
'general.delete').
' '.htmlspecialchars($location->name).
'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>';
336 'id' => $location->id,
337 'name' => (
string)link_to(
'admin/settings/locations/'.$location->id.
'/view', e($location->name)),
338 'parent' => ($location->parent) ? e($location->parent->name) :
'',
340 'assets_default' => $location->assignedassets->count(),
341 'assets_checkedout' => $location->assets->count(),
342 'address' => ($location->address) ? e($location->address):
'',
343 'city' => e($location->city),
344 'state' => e($location->state),
345 'country' => e($location->country),
346 'currency' => e($location->currency),
347 'actions' => $actions
351 $data = array(
'total' => $locationsCount,
'rows' => $rows);
App\Http\Controllers\LocationsController::getDataViewAssets |
( |
|
$locationID | ) |
|
Returns a JSON response that contains the assets association with the selected location, to be used by the location detail view.
- Todo:
- This is broken for accessories and consumables.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- LocationsController::getView() method that creates the display view
- Parameters
-
- Since
- [v1.8]
- Returns
- View
Definition at line 396 of file LocationsController.php.
398 $location = Location::find($locationID)->load(
'assignedassets.model');
401 foreach ($location->assignedassets as $asset) {
403 'name' => (
string)link_to(
'/hardware/'.$asset->id.
'/view', e($asset->showAssetName())),
404 'asset_tag' => e($asset->asset_tag),
405 'serial' => e($asset->serial),
406 'model' => e($asset->model->name),
410 $data = array(
'total' => $location->assignedassets->count(),
'rows' => $rows);
App\Http\Controllers\LocationsController::getDataViewUsers |
( |
|
$locationID | ) |
|
Returns a JSON response that contains the users association with the selected location, to be used by the location detail view.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- LocationsController::getView() method that creates the display view
- Parameters
-
- Since
- [v1.8]
- Returns
- View
Definition at line 368 of file LocationsController.php.
370 $location = Location::find($locationID);
373 foreach ($location->users as $user) {
375 'name' => (
string)link_to(
'/admin/users/'.$user->id.
'/view', e($user->fullName()))
379 $data = array(
'total' => $location->users->count(),
'rows' => $rows);
App\Http\Controllers\LocationsController::getDelete |
( |
|
$locationId | ) |
|
Validates and deletes selected location.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- Parameters
-
- Since
- [v1.0]
- Returns
- Redirect
Definition at line 225 of file LocationsController.php.
228 if (is_null($location = Location::find($locationId))) {
230 return Redirect::to(
'admin/settings/locations')->with(
'error', trans(
'admin/locations/message.not_found'));
234 if ($location->users->count() > 0) {
235 return Redirect::to(
'admin/settings/locations')->with(
'error', trans(
'admin/locations/message.assoc_users'));
236 } elseif ($location->childLocations->count() > 0) {
237 return Redirect::to(
'admin/settings/locations')->with(
'error', trans(
'admin/locations/message.assoc_child_loc'));
238 } elseif ($location->assets->count() > 0) {
239 return Redirect::to(
'admin/settings/locations')->with(
'error', trans(
'admin/locations/message.assoc_assets'));
240 } elseif ($location->assignedassets->count() > 0) {
241 return Redirect::to(
'admin/settings/locations')->with(
'error', trans(
'admin/locations/message.assoc_assets'));
244 return Redirect::to(
'admin/settings/locations')->with(
'success', trans(
'admin/locations/message.delete.success'));
App\Http\Controllers\LocationsController::getEdit |
( |
|
$locationId = null | ) |
|
Makes a form view to edit location information.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- LocationsController::postCreate() method that validates and stores
- Parameters
-
- Since
- [v1.0]
- Returns
- View
Definition at line 157 of file LocationsController.php.
160 if (is_null($location = Location::find($locationId))) {
161 return Redirect::to(
'admin/settings/locations')->with(
'error', trans(
'admin/locations/message.does_not_exist'));
165 $locations = Location::orderBy(
'name',
'ASC')->get();
168 $location_options = array(
'' =>
'Top Level') + $location_options;
170 return View::make(
'locations/edit', compact(
'location'))->with(
'location_options', $location_options);
static getLocationHierarchy($locations, $parent_id=null)
static flattenLocationsArray($location_options_array=null)
App\Http\Controllers\LocationsController::getIndex |
( |
| ) |
|
Returns a view that invokes the ajax tables which actually contains the content for the locations listing, which is generated in getDatatable.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- LocationsController::getDatatable() method that generates the JSON response
- Since
- [v1.0]
- Returns
- View
Definition at line 34 of file LocationsController.php.
37 $locations = Location::orderBy(
'created_at',
'DESC')->with(
'parent',
'assets',
'assignedassets')->get();
40 return View::make(
'locations/index', compact(
'locations'));
App\Http\Controllers\LocationsController::getView |
( |
|
$locationId = null | ) |
|
Returns a view that invokes the ajax tables which actually contains the content for the locations detail page.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- LocationsController::getDataViewUsers() method that returns JSON for location users
-
LocationsController::getDataViewAssets() method that returns JSON for location assets
- Parameters
-
- Since
- [v1.0]
- Returns
- View
Definition at line 263 of file LocationsController.php.
265 $location = Location::find($locationId);
267 if (isset($location->id)) {
268 return View::make(
'locations/view', compact(
'location'));
271 $error = trans(
'admin/locations/message.does_not_exist', compact(
'id'));
274 return Redirect::route(
'locations')->with(
'error', $error);
App\Http\Controllers\LocationsController::postCreate |
( |
| ) |
|
Validates and stores a new location.
- Todo:
- Check if a Form Request would work better here.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- LocationsController::getCreate() method that makes the form
- Since
- [v1.0]
- Returns
- Redirect
Definition at line 75 of file LocationsController.php.
79 $location =
new Location();
83 $location->name = e(Input::get(
'name'));
84 if (Input::get(
'parent_id')==
'') {
85 $location->parent_id = null;
87 $location->parent_id = e(Input::get(
'parent_id'));
89 $location->currency = e(Input::get(
'currency',
'$'));
90 $location->address = e(Input::get(
'address'));
91 $location->address2 = e(Input::get(
'address2'));
92 $location->city = e(Input::get(
'city'));
93 $location->state = e(Input::get(
'state'));
94 $location->country = e(Input::get(
'country'));
95 $location->zip = e(Input::get(
'zip'));
96 $location->user_id = Auth::user()->id;
98 if ($location->save()) {
100 return Redirect::to(
"admin/settings/locations")->with(
'success', trans(
'admin/locations/message.create.success'));
103 return Redirect::back()->withInput()->withErrors($location->getErrors());
App\Http\Controllers\LocationsController::postEdit |
( |
|
$locationId = null | ) |
|
Validates and stores updated location data from edit form.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- LocationsController::getEdit() method that makes the form view
- Parameters
-
- Since
- [v1.0]
- Returns
- Redirect
Definition at line 183 of file LocationsController.php.
186 if (is_null($location = Location::find($locationId))) {
188 return Redirect::to(
'admin/settings/locations')->with(
'error', trans(
'admin/locations/message.does_not_exist'));
192 $location->name = e(Input::get(
'name'));
193 if (Input::get(
'parent_id')==
'') {
194 $location->parent_id = null;
196 $location->parent_id = e(Input::get(
'parent_id',
''));
198 $location->currency = e(Input::get(
'currency',
'$'));
199 $location->address = e(Input::get(
'address'));
200 $location->address2 = e(Input::get(
'address2'));
201 $location->city = e(Input::get(
'city'));
202 $location->state = e(Input::get(
'state'));
203 $location->country = e(Input::get(
'country'));
204 $location->zip = e(Input::get(
'zip'));
207 if ($location->save()) {
209 return Redirect::to(
"admin/settings/locations/")->with(
'success', trans(
'admin/locations/message.update.success'));
213 return Redirect::back()->withInput()->withInput()->withErrors($location->getErrors());
App\Http\Controllers\LocationsController::store |
( |
| ) |
|
Validates and stores a new location created via the Create Asset form modal.
- Todo:
- Check if a Form Request would work better here.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- See also
- AssetsController::getCreate() method that makes the form
- Since
- [v1.0]
- Returns
- String JSON
Definition at line 116 of file LocationsController.php.
119 $new[
'currency']=Setting::first()->default_currency;
122 $location =
new Location();
125 $location->name = e(Input::get(
'name'));
126 $location->currency = Setting::first()->default_currency;
127 $location->address =
'';
129 $location->city = e(Input::get(
'city'));
130 $location->state =
'';
131 $location->country = e(Input::get(
'country'));
133 $location->user_id = Auth::user()->id;
136 if ($location->save()) {
137 return JsonResponse::create($location);
142 $errors = $location->errors();
143 return JsonResponse::create([
"error" =>
"Failed validation: ".print_r($location->getErrors(),
true)], 500);
The documentation for this class was generated from the following file: