Last active
August 29, 2015 14:21
-
-
Save stevebauman/00aaeaa0c7ca260a0aa5 to your computer and use it in GitHub Desktop.
Recursive BOM Array Method
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
/** | |
* Returns all of the assemblies items in an | |
* easy to work with array. | |
* | |
* @param bool $recursive | |
* | |
* @return array | |
*/ | |
public function getAssemblyItemsList($recursive = true, $depth = 0) | |
{ | |
$list = []; | |
$items = $this->getAssemblyItems(); | |
$level = 0; | |
$depth++; | |
foreach ($items as $key => $item) { | |
$list[$level] = [ | |
'id' => $item->id, | |
'name' => $item->name, | |
'metric_id' => $item->metric_id, | |
'category_id' => $item->category_id, | |
'quantity' => $item->pivot->quantity, | |
'depth' => $depth, | |
]; | |
if ($item->is_assembly && $recursive) { | |
$list[$level]['parts'] = $item->getAssemblyItemsList(true, $depth); | |
} | |
$level++; | |
} | |
return $list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment