]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/BookController.php
Added further tests, Fixed speed_update issues, improved search result query count
[bookstack] / app / Http / Controllers / BookController.php
index 0092a78a9868caa5b5169abbdc4bf5e97536a6f6..6b2d6928dc9d01d2a732d035fa3f7326d066da24 100644 (file)
@@ -1,16 +1,17 @@
 <?php
 
-namespace Oxbow\Http\Controllers;
+namespace BookStack\Http\Controllers;
 
 use Activity;
 use Illuminate\Http\Request;
 
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Str;
-use Oxbow\Http\Requests;
-use Oxbow\Repos\BookRepo;
-use Oxbow\Repos\ChapterRepo;
-use Oxbow\Repos\PageRepo;
+use BookStack\Http\Requests;
+use BookStack\Repos\BookRepo;
+use BookStack\Repos\ChapterRepo;
+use BookStack\Repos\PageRepo;
+use Views;
 
 class BookController extends Controller
 {
@@ -40,8 +41,9 @@ class BookController extends Controller
      */
     public function index()
     {
-        $books = $this->bookRepo->getAll();
-        return view('books/index', ['books' => $books]);
+        $books = $this->bookRepo->getAllPaginated(10);
+        $recents = $this->signedIn ? $this->bookRepo->getRecentlyViewed(10, 0) : false;
+        return view('books/index', ['books' => $books, 'recents' => $recents]);
     }
 
     /**
@@ -86,7 +88,9 @@ class BookController extends Controller
     public function show($slug)
     {
         $book = $this->bookRepo->getBySlug($slug);
-        return view('books/show', ['book' => $book, 'current' => $book]);
+        Views::add($book);
+        $bookChildren = $this->bookRepo->getChildren($book);
+        return view('books/show', ['book' => $book, 'current' => $book, 'bookChildren' => $bookChildren]);
     }
 
     /**
@@ -146,14 +150,16 @@ class BookController extends Controller
     {
         $this->checkPermission('book-update');
         $book = $this->bookRepo->getBySlug($bookSlug);
+        $bookChildren = $this->bookRepo->getChildren($book);
         $books = $this->bookRepo->getAll();
-        return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books]);
+        return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]);
     }
 
     public function getSortItem($bookSlug)
     {
         $book = $this->bookRepo->getBySlug($bookSlug);
-        return view('books/sort-box', ['book' => $book]);
+        $bookChildren = $this->bookRepo->getChildren($book);
+        return view('books/sort-box', ['book' => $book, 'bookChildren' => $bookChildren]);
     }
 
     /**
@@ -182,7 +188,7 @@ class BookController extends Controller
             $isPage = $bookChild->type == 'page';
             $bookId = $this->bookRepo->exists($bookChild->book) ? $bookChild->book : $defaultBookId;
             $model = $isPage ? $this->pageRepo->getById($id) : $this->chapterRepo->getById($id);
-            $isPage ? $this->pageRepo->setBookId($bookId, $model) : $this->chapterRepo->setBookId($bookId, $model);
+            $isPage ? $this->pageRepo->changeBook($bookId, $model) : $this->chapterRepo->changeBook($bookId, $model);
             $model->priority = $index;
             if ($isPage) {
                 $model->chapter_id = ($bookChild->parentChapter === false) ? 0 : $bookChild->parentChapter;