| @@ 97-128 (lines=32) @@ | ||
| 94 | * |
|
| 95 | * @return array |
|
| 96 | */ |
|
| 97 | public function getParentsList() |
|
| 98 | { |
|
| 99 | /** @var static $root */ |
|
| 100 | $root = static::root(); |
|
| 101 | $items = [ |
|
| 102 | ['id' => '1', 'title' => 'Item Root'], |
|
| 103 | ]; |
|
| 104 | ||
| 105 | if ($this->exists) { |
|
| 106 | $parents = $this->ancestors() |
|
| 107 | ->withoutRoot() |
|
| 108 | ->orWhere(function ($query) { |
|
| 109 | $query->where('depth', $this->depth)->where('id', '<>', $this->id); |
|
| 110 | }) |
|
| 111 | ->get(); |
|
| 112 | foreach ($parents as $parent) { |
|
| 113 | $items[] = [ |
|
| 114 | 'title' => $parent->present()->indentedTitle(), |
|
| 115 | 'id' => $parent->id, |
|
| 116 | ]; |
|
| 117 | } |
|
| 118 | } else { |
|
| 119 | foreach ($root->getDescendants() as $parent) { |
|
| 120 | $items[] = [ |
|
| 121 | 'title' => $parent->present()->indentedTitle(), |
|
| 122 | 'id' => $parent->id, |
|
| 123 | ]; |
|
| 124 | } |
|
| 125 | } |
|
| 126 | ||
| 127 | return array_pluck($items, 'title', 'id'); |
|
| 128 | } |
|
| 129 | ||
| 130 | /** |
|
| 131 | * Count published articles. |
|
| @@ 118-149 (lines=32) @@ | ||
| 115 | * |
|
| 116 | * @return array |
|
| 117 | */ |
|
| 118 | public function getParentsList() |
|
| 119 | { |
|
| 120 | /** @var static $root */ |
|
| 121 | $root = static::root(); |
|
| 122 | $items = [ |
|
| 123 | ['id' => '1', 'title' => 'Item Root'], |
|
| 124 | ]; |
|
| 125 | ||
| 126 | if ($this->exists) { |
|
| 127 | $parents = $this->ancestors() |
|
| 128 | ->withoutRoot() |
|
| 129 | ->orWhere(function ($query) { |
|
| 130 | $query->where('depth', $this->depth)->where('id', '<>', $this->id); |
|
| 131 | }) |
|
| 132 | ->get(); |
|
| 133 | foreach ($parents as $parent) { |
|
| 134 | $items[] = [ |
|
| 135 | 'title' => $parent->present()->indentedTitle(0), |
|
| 136 | 'id' => $parent->id, |
|
| 137 | ]; |
|
| 138 | } |
|
| 139 | } else { |
|
| 140 | foreach ($root->getDescendants() as $parent) { |
|
| 141 | $items[] = [ |
|
| 142 | 'title' => $parent->present()->indentedTitle(0), |
|
| 143 | 'id' => $parent->id, |
|
| 144 | ]; |
|
| 145 | } |
|
| 146 | } |
|
| 147 | ||
| 148 | return array_pluck($items, 'title', 'id'); |
|
| 149 | } |
|
| 150 | ||
| 151 | /** |
|
| 152 | * Check if the menu has the given widget. |
|