| 1: | <?php |
| 2: | |
| 3: | namespace Baril\Bonsai\Concerns; |
| 4: | |
| 5: | use Baril\Orderly\Concerns\Orderable; |
| 6: | |
| 7: | trait BelongsToOrderedTree |
| 8: | { |
| 9: | use BelongsToTree { |
| 10: | children as _children; |
| 11: | setChildrenFromDescendants as _setChildrenFromDescendants; |
| 12: | getTree as _getTree; |
| 13: | } |
| 14: | use Orderable; |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | public function getGroupColumn() |
| 20: | { |
| 21: | return $this->getParentForeignKeyName(); |
| 22: | } |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | public function children() |
| 28: | { |
| 29: | return static::_children()->ordered(); |
| 30: | } |
| 31: | |
| 32: | protected function setChildrenFromDescendants($descendants) |
| 33: | { |
| 34: | $this->_setChildrenFromDescendants($descendants->sortBy($this->getOrderColumn())); |
| 35: | } |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | public static function getTree($depth = null) |
| 42: | { |
| 43: | return static::_getTree($depth)->sortBy((new static())->getOrderColumn())->values(); |
| 44: | } |
| 45: | } |
| 46: | |