1 <?php namespace BookStack;
4 class BookShelf extends Entity
6 protected $table = 'bookshelves';
8 public $searchFactor = 3;
10 protected $fillable = ['name', 'description', 'image_id'];
13 * Get the url for this bookshelf.
14 * @param string|bool $path
17 public function getUrl($path = false)
19 if ($path !== false) {
20 return baseUrl('/shelves/' . urlencode($this->slug) . '/' . trim($path, '/'));
22 return baseUrl('/shelves/' . urlencode($this->slug));
26 * Returns BookShelf cover image, if cover does not exists return default cover image.
27 * @param int $width - Width of the image
28 * @param int $height - Height of the image
31 public function getBookCover($width = 440, $height = 250)
33 $default = baseUrl('/book_default_cover.png');
34 if (!$this->image_id) {
39 $cover = $this->cover ? baseUrl($this->cover->getThumb($width, $height, false)) : $default;
40 } catch (\Exception $err) {
47 * Get the cover image of the book
48 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
50 public function cover()
52 return $this->belongsTo(Image::class, 'image_id');
56 * Get an excerpt of this book's description to the specified length or less.
60 public function getExcerpt($length = 100)
62 $description = $this->description;
63 return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
67 * Return a generalised, common raw query that can be 'unioned' across entities.
70 public function entityRawQuery()
72 return "'BookStack\\\\BookShelf' as entity_type, id, id as entity_id, slug, name, {$this->textField} as text,'' as html, '0' as book_id, '0' as priority, '0' as chapter_id, '0' as draft, created_by, updated_by, updated_at, created_at";