Skip to content

Commit

Permalink
Fixes #970
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Jul 29, 2015
1 parent 65bf156 commit 0c90182
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions app/controllers/admin/LocationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'));
Expand Down
2 changes: 2 additions & 0 deletions app/lang/en/admin/locations/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions app/models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0c90182

Please sign in to comment.