-<?php namespace BookStack\Entities\Repos;
+<?php
+
+namespace BookStack\Entities\Repos;
use BookStack\Actions\ActivityType;
use BookStack\Actions\TagRepo;
-use BookStack\Entities\Book;
+use BookStack\Entities\Models\Book;
use BookStack\Entities\Tools\TrashCan;
use BookStack\Exceptions\ImageUploadException;
use BookStack\Exceptions\NotFoundException;
class BookRepo
{
-
protected $baseRepo;
protected $tagRepo;
protected $imageRepo;
*/
public function getAllPaginated(int $count = 20, string $sort = 'name', string $order = 'asc'): LengthAwarePaginator
{
- return Book::visible()->orderBy($sort, $order)->paginate($count);
+ return Book::visible()->with('cover')->orderBy($sort, $order)->paginate($count);
}
/**
}
/**
- * Create a new book in the system
+ * Create a new book in the system.
*/
public function create(array $input): Book
{
$book = new Book();
$this->baseRepo->create($book, $input);
- Activity::addForEntity($book, ActivityType::BOOK_CREATE);
+ Activity::add(ActivityType::BOOK_CREATE, $book);
+
return $book;
}
public function update(Book $book, array $input): Book
{
$this->baseRepo->update($book, $input);
- Activity::addForEntity($book, ActivityType::BOOK_UPDATE);
+ Activity::add(ActivityType::BOOK_UPDATE, $book);
+
return $book;
}
/**
* Update the given book's cover image, or clear it.
+ *
* @throws ImageUploadException
* @throws Exception
*/
$this->baseRepo->updateCoverImage($book, $coverImage, $removeImage);
}
- /**
- * Update the permissions of a book.
- */
- public function updatePermissions(Book $book, bool $restricted, Collection $permissions = null)
- {
- $this->baseRepo->updatePermissions($book, $restricted, $permissions);
- }
-
/**
* Remove a book from the system.
+ *
* @throws Exception
*/
public function destroy(Book $book)
{
$trashCan = new TrashCan();
$trashCan->softDestroyBook($book);
- Activity::addForEntity($book, ActivityType::BOOK_DELETE);
+ Activity::add(ActivityType::BOOK_DELETE, $book);
$trashCan->autoClearOld();
}