From 0c9018289b3fed49154e2d7138d4b760ce7d2752 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 Jul 2015 20:24:58 -0700 Subject: [PATCH] Fixes #970 --- app/controllers/admin/LocationsController.php | 12 ++++++++---- app/lang/en/admin/locations/message.php | 2 ++ app/models/Location.php | 6 +++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/LocationsController.php b/app/controllers/admin/LocationsController.php index 22ce45cd6276..b8c90e767c45 100755 --- a/app/controllers/admin/LocationsController.php +++ b/app/controllers/admin/LocationsController.php @@ -99,11 +99,11 @@ public function postCreate() return Redirect::to('admin/settings/locations/create')->with('error', Lang::get('admin/locations/message.create.error')); } - + public function store() { $new = Input::all(); - + $new['currency']=Setting::first()->default_currency; // create a new location instance @@ -237,10 +237,14 @@ public function getDelete($locationId) } - if ($location->has_users->count() > 0) { + if ($location->users->count() > 0) { return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.assoc_users')); } elseif ($location->childLocations->count() > 0) { - return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.assoc_users')); + return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.assoc_child_loc')); + } elseif ($location->assets->count() > 0) { + return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.assoc_assets')); + } elseif ($location->assignedassets->count() > 0) { + return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.assoc_assets')); } else { $location->delete(); return Redirect::to('admin/settings/locations')->with('success', Lang::get('admin/locations/message.delete.success')); diff --git a/app/lang/en/admin/locations/message.php b/app/lang/en/admin/locations/message.php index b2277f9a9dc9..982d2b36035d 100755 --- a/app/lang/en/admin/locations/message.php +++ b/app/lang/en/admin/locations/message.php @@ -4,6 +4,8 @@ 'does_not_exist' => 'Location does not exist.', 'assoc_users' => 'This location is currently associated with at least one user and cannot be deleted. Please update your users to no longer reference this location and try again. ', + 'assoc_assets' => 'This location is currently associated with at least one asset and cannot be deleted. Please update your assets to no longer reference this location and try again. ', + 'assoc_child_loc' => 'This location is currently the parent of at least one asset and cannot be deleted. Please update your locations to no longer reference this location and try again. ', 'create' => array( diff --git a/app/models/Location.php b/app/models/Location.php index 3b076f21c78a..5f6fd95b38fc 100755 --- a/app/models/Location.php +++ b/app/models/Location.php @@ -16,7 +16,7 @@ class Location extends Elegant 'zip' => 'alpha_space|min:3|max:10', ); - public function has_users() { + public function users() { return $this->hasMany('User', 'location_id'); } @@ -33,7 +33,7 @@ public function parent() { } public function childLocations() { - return $this->hasMany('Location')->where('parent_id','=',$this->id); + return $this->hasMany('Location','id')->where('parent_id','=',$this->id); } public static function getLocationHierarchy($locations, $parent_id = null) { @@ -64,7 +64,7 @@ public static function getLocationHierarchy($locations, $parent_id = null) { public static function flattenLocationsArray ($location_options_array = null) { - + $location_options = array(); foreach ($location_options_array as $id => $value) { // get the top level key value