mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-31 15:24:31 +03:00
Merge branch 'prev-next-button' of https://github.com/shubhamosmosys/BookStack into shubhamosmosys-prev-next-button
This commit is contained in:
@ -138,4 +138,13 @@ class Page extends BookChild
|
||||
$refreshed->html = (new PageContent($refreshed))->render();
|
||||
return $refreshed;
|
||||
}
|
||||
/**
|
||||
* Get the parent chapter ID.
|
||||
*/
|
||||
public function getParentChapter()
|
||||
{
|
||||
$chapterId = $this->chapter()->visible()
|
||||
->get('id');
|
||||
return $chapterId;
|
||||
}
|
||||
}
|
||||
|
@ -468,4 +468,10 @@ class PageRepo
|
||||
->where('page_id', '=', $page->id)
|
||||
->orderBy('created_at', 'desc');
|
||||
}
|
||||
/**
|
||||
* Get page details by chapter ID.
|
||||
*/
|
||||
public function getPageByChapterID(int $id){
|
||||
return Page::visible()->where('chapter_id', '=', $id)->get(['id','slug']);
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +142,39 @@ 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";
|
||||
}
|
||||
|
||||
View::incrementFor($page);
|
||||
$this->setPageTitle($page->getShortName());
|
||||
return view('pages.show', [
|
||||
@ -150,7 +183,11 @@ class PageController extends Controller
|
||||
'current' => $page,
|
||||
'sidebarTree' => $sidebarTree,
|
||||
'commentsEnabled' => $commentsEnabled,
|
||||
'pageNav' => $pageNav
|
||||
'pageNav' => $pageNav,
|
||||
'prevPage' => $prevPage,
|
||||
'nextPage' => $nextPage,
|
||||
'disablePrev' => $disablePrev,
|
||||
'disableNxt' => $disableNxt
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user