1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Add prev and next button to navigate through different pages

This commit is contained in:
Shubham Tiwari
2021-01-27 10:05:55 +05:30
parent 7ba6962707
commit 99c42033b1
6 changed files with 89 additions and 1 deletions

View File

@ -142,6 +142,38 @@ class PageController extends Controller
$page->load(['comments.createdBy']);
}
$chapterId = $page->getParentChapter();
$allPageSlugs = $this->pageRepo->getPageByChapterID($chapterId[0]->id);
$pos = 0;
foreach ($allPageSlugs as $slug){
if($pageSlug === $slug->slug){
$currPagePos = $pos;
}
$pos++;
$pageUrl = $this->pageRepo->getBySlug($bookSlug, $slug->slug);
$urlLink[] = $pageUrl->getUrl();
}
for($i=0; $i <= $currPagePos; $i++){
$nextCount = $i+1;
$prevCount = $i-1;
$prevPage = '#';
$nextPage = '#';
if($nextCount < count($urlLink)){
$nextPage = $urlLink[$nextCount];
}
if($currPagePos == $i && $currPagePos != 0){
$prevPage = $urlLink[$prevCount];
}
}
$disablePrev = "";
$disableNxt = "";
if($prevPage == "#"){
$disablePrev = "disabled";
}
if($nextPage == "#"){
$disableNxt = "disabled";
}
Views::add($page);
$this->setPageTitle($page->getShortName());
return view('pages.show', [
@ -150,7 +182,11 @@ class PageController extends Controller
'current' => $page,
'sidebarTree' => $sidebarTree,
'commentsEnabled' => $commentsEnabled,
'pageNav' => $pageNav
'pageNav' => $pageNav,
'prevPage' => $prevPage,
'nextPage' => $nextPage,
'disablePrev' => $disablePrev,
'disableNxt' => $disableNxt
]);
}