use BookStack\Uploads\Image;
+/**
+ * Class Book
+ * @property string $description
+ * @property int $image_id
+ * @property Image|null $cover
+ * @package BookStack\Entities
+ */
class Book extends Entity
{
public $searchFactor = 2;
public function getUrl($path = false)
{
if ($path !== false) {
- return baseUrl('/books/' . urlencode($this->slug) . '/' . trim($path, '/'));
+ return url('/books/' . urlencode($this->slug) . '/' . trim($path, '/'));
}
- return baseUrl('/books/' . urlencode($this->slug));
+ return url('/books/' . urlencode($this->slug));
}
/**
*/
public function getBookCover($width = 440, $height = 250)
{
- $default = baseUrl('/book_default_cover.png');
+ $default = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
if (!$this->image_id) {
return $default;
}
try {
- $cover = $this->cover ? baseUrl($this->cover->getThumb($width, $height, false)) : $default;
+ $cover = $this->cover ? url($this->cover->getThumb($width, $height, false)) : $default;
} catch (\Exception $err) {
$cover = $default;
}
return $this->hasMany(Page::class);
}
+ /**
+ * Get the direct child pages of this book.
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function directPages()
+ {
+ return $this->pages()->where('chapter_id', '=', '0');
+ }
+
/**
* Get all chapters within this book.
* @return \Illuminate\Database\Eloquent\Relations\HasMany
* @param int $length
* @return string
*/
- public function getExcerpt($length = 100)
+ public function getExcerpt(int $length = 100)
{
$description = $this->description;
- return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
+ return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
}
/**