Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/snipe/snipe-it
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Dec 6, 2019
2 parents 91bb76f + ff57f10 commit 943cf40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/Http/Controllers/Api/LocationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,28 @@ public function selectlist(Request $request)
}

if ($request->filled('search')) {
\Log::debug('Searching... ');
$locations = $locations->where('locations.name', 'LIKE', '%'.$request->input('search').'%');
}

$locations = $locations->orderBy('name', 'ASC')->get();

$locations_with_children = [];

foreach ($locations as $location) {
if(!array_key_exists($location->parent_id, $locations_with_children)) {
if (!array_key_exists($location->parent_id, $locations_with_children)) {
$locations_with_children[$location->parent_id] = [];
}
$locations_with_children[$location->parent_id][] = $location;
}

$location_options = Location::indenter($locations_with_children);
if ($request->filled('search')) {
$locations_formatted = $locations;
} else {
$location_options = Location::indenter($locations_with_children);
$locations_formatted = new Collection($location_options);

}

$locations_formatted = new Collection($location_options);
$paginated_results = new LengthAwarePaginator($locations_formatted->forPage($page, 500), $locations_formatted->count(), 500, $page, []);

//return [];
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ public function setLdapOuAttribute($ldap_ou)

public static function indenter($locations_with_children, $parent_id = null, $prefix = '') {
$results = Array();


if (!array_key_exists($parent_id, $locations_with_children)) {
return [];
}


foreach ($locations_with_children[$parent_id] as $location) {
$location->use_text = $prefix.' '.$location->name;
$location->use_image = ($location->image) ? url('/').'/uploads/locations/'.$location->image : null;
Expand Down

0 comments on commit 943cf40

Please sign in to comment.