getSelectParams($params); $selectParams['whereClause'][] = array( 'parentId' => $parentId ); $selectParams['orderBy'] = [ ['order', 'asc'], ['name', 'asc'] ]; $collection = $this->getRepository()->find($selectParams); foreach ($collection as $entity) { $childList = $this->getTree($entity->id, $params, $level + 1); $entity->set('childList', $childList); } return $collection; } public function getTreeItemPath($parentId = null) { $arr = []; while (1) { if (empty($parentId)) { break; } $parent = $this->getEntityManager()->getEntity($this->entityType, $parentId); if ($parent) { $parentId = $parent->get('parentId'); array_unshift($arr, $parent->id); } else { $parentId = null; } } return $arr; } }