Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
BelongsToOrderedTree | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
getGroupColumn | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
children | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setChildrenFromDescendants | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTree | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
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 | * @return string |
18 | */ |
19 | public function getGroupColumn() |
20 | { |
21 | return $this->getParentForeignKeyName(); |
22 | } |
23 | |
24 | /** |
25 | * @return \Illuminate\Database\Eloquent\Relation\HasMany |
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 | * @param int $depth |
39 | * @return \Illuminate\Database\Eloquent\Collection |
40 | */ |
41 | public static function getTree($depth = null) |
42 | { |
43 | return static::_getTree($depth)->sortBy((new static())->getOrderColumn())->values(); |
44 | } |
45 | } |