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