mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 14:27:33 -08:00
Fix for searching on child location names (#7646)
* Fix for child locations * Reverts temp changes to indenter
This commit is contained in:
parent
893454dca7
commit
ff57f10e9f
|
@ -232,23 +232,28 @@ class LocationsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
\Log::debug('Searching... ');
|
|
||||||
$locations = $locations->where('locations.name', 'LIKE', '%'.$request->input('search').'%');
|
$locations = $locations->where('locations.name', 'LIKE', '%'.$request->input('search').'%');
|
||||||
}
|
}
|
||||||
|
|
||||||
$locations = $locations->orderBy('name', 'ASC')->get();
|
$locations = $locations->orderBy('name', 'ASC')->get();
|
||||||
|
|
||||||
$locations_with_children = [];
|
$locations_with_children = [];
|
||||||
|
|
||||||
foreach ($locations as $location) {
|
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] = [];
|
||||||
}
|
}
|
||||||
$locations_with_children[$location->parent_id][] = $location;
|
$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, []);
|
$paginated_results = new LengthAwarePaginator($locations_formatted->forPage($page, 500), $locations_formatted->count(), 500, $page, []);
|
||||||
|
|
||||||
//return [];
|
//return [];
|
||||||
|
|
|
@ -150,11 +150,13 @@ class Location extends SnipeModel
|
||||||
|
|
||||||
public static function indenter($locations_with_children, $parent_id = null, $prefix = '') {
|
public static function indenter($locations_with_children, $parent_id = null, $prefix = '') {
|
||||||
$results = Array();
|
$results = Array();
|
||||||
|
|
||||||
|
|
||||||
if (!array_key_exists($parent_id, $locations_with_children)) {
|
if (!array_key_exists($parent_id, $locations_with_children)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach ($locations_with_children[$parent_id] as $location) {
|
foreach ($locations_with_children[$parent_id] as $location) {
|
||||||
$location->use_text = $prefix.' '.$location->name;
|
$location->use_text = $prefix.' '.$location->name;
|
||||||
$location->use_image = ($location->image) ? url('/').'/uploads/locations/'.$location->image : null;
|
$location->use_image = ($location->image) ? url('/').'/uploads/locations/'.$location->image : null;
|
||||||
|
|
Loading…
Reference in a new issue