From 45e26c0936c15bc53dd903cc646b7182afd99441 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 5 Dec 2014 08:51:48 -0700 Subject: [PATCH] refactored page prev/next/adjacent so they work! --- system/src/Grav/Common/Page/Page.php | 36 +++++----------------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 7f9b4bb26..862b1f6e6 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1186,15 +1186,8 @@ class Page */ public function isFirst() { - /** @var Pages $pages */ - $pages = self::$grav['pages']; - $parent = $pages->get($this->parent); - - if ($this->path() == array_values($parent->items)[0]) { - return true; - } else { - return false; - } + $collection = $this->parent()->collection(); + return $collection->isFirst($this->path()); } /** @@ -1204,15 +1197,8 @@ class Page */ public function isLast() { - /** @var Pages $pages */ - $pages = self::$grav['pages']; - $parent = $pages->get($this->parent); - - if ($this->path() == array_values($parent->items)[count($parent->items)-1]) { - return true; - } else { - return false; - } + $collection = $this->parent()->collection(); + return $collection->isLast($this->path()); } /** @@ -1243,18 +1229,8 @@ class Page */ public function adjacentSibling($direction = 1) { - /** @var Pages $pages */ - $pages = self::$grav['pages']; - $parent = $this->parent(); - $children = $parent->children(); - - $adjacent = $children->adjacentSibling($this->path(), $direction); - - if (!$adjacent) { - return null; - } - - return $adjacent; + $collection = $this->parent()->collection(); + return $collection->adjacentSibling($this->path(), $direction); } /**