Created
October 2, 2019 09:39
-
-
Save uberbrady/98eca5dcf013c51858b90fe1478c53ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$locations_with_children=[]; | |
foreach($locations as $location) { | |
$locations_with_children[$location->parent_id] = true; | |
} | |
public static function indenter($locations, $locations_with_children, $parent_id = null, $prefix = '') { | |
$results = Array(); | |
foreach($locations as $location) { | |
$locations_with_children[$location->parent_id] = true; | |
if($location->parent_id == $parent_id) { | |
//append this parent node first, | |
$location->use_text = $prefix.' '.$location->name; | |
$location->use_image = ($location->image) ? url('/').'/uploads/locations/'.$location->image : null; | |
$results[] = $location; | |
//now append the children. (if we have any) | |
if($locations_with_children[$location->id]) { | |
$results = array_merge($results,Location::indenter($locations,$location->id,$prefix.'--')); | |
} | |
} | |
} | |
return $results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment