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

Added view count tracking with personalised lists

This commit is contained in:
Dan Brown
2015-11-21 17:22:14 +00:00
parent 76eb8fc5d7
commit ea55b7f141
18 changed files with 311 additions and 30 deletions

View File

@ -1,7 +1,9 @@
<?php namespace BookStack\Repos;
use BookStack\Activity;
use Illuminate\Support\Str;
use BookStack\Book;
use Views;
class BookRepo
{
@ -20,18 +22,28 @@ class BookRepo
$this->pageRepo = $pageRepo;
}
/**
* Get the book that has the given id.
* @param $id
* @return mixed
*/
public function getById($id)
{
return $this->book->findOrFail($id);
}
/**
* Get all books, Limited by count.
* @param int $count
* @return mixed
*/
public function getAll($count = 10)
{
return $this->book->orderBy('name', 'asc')->take($count)->get();
}
/**
* Getas
* Get all books paginated.
* @param int $count
* @return mixed
*/
@ -40,6 +52,16 @@ class BookRepo
return $this->book->orderBy('name', 'asc')->paginate($count);
}
public function getRecentlyViewed($count = 10, $page = 0)
{
return Views::getUserRecentlyViewed($count, $page, $this->book);
}
/**
* Get a book by slug
* @param $slug
* @return mixed
*/
public function getBySlug($slug)
{
return $this->book->where('slug', '=', $slug)->first();
@ -65,11 +87,20 @@ class BookRepo
return $this->book->fill($input);
}
/**
* Count the amount of books that have a specific slug.
* @param $slug
* @return mixed
*/
public function countBySlug($slug)
{
return $this->book->where('slug', '=', $slug)->count();
}
/**
* Destroy a book identified by the given slug.
* @param $bookSlug
*/
public function destroyBySlug($bookSlug)
{
$book = $this->getBySlug($bookSlug);
@ -84,12 +115,22 @@ class BookRepo
$book->delete();
}
/**
* Get the next child element priority.
* @param Book $book
* @return int
*/
public function getNewPriority($book)
{
$lastElem = $book->children()->pop();
return $lastElem ? $lastElem->priority + 1 : 0;
}
/**
* @param string $slug
* @param bool|false $currentId
* @return bool
*/
public function doesSlugExist($slug, $currentId = false)
{
$query = $this->book->where('slug', '=', $slug);
@ -99,6 +140,13 @@ class BookRepo
return $query->count() > 0;
}
/**
* Provides a suitable slug for the given book name.
* Ensures the returned slug is unique in the system.
* @param string $name
* @param bool|false $currentId
* @return string
*/
public function findSuitableSlug($name, $currentId = false)
{
$originalSlug = Str::slug($name);
@ -111,6 +159,11 @@ class BookRepo
return $slug;
}
/**
* Get books by search term.
* @param $term
* @return mixed
*/
public function getBySearch($term)
{
$terms = explode(' ', preg_quote(trim($term)));