]> BookStack Code Mirror - bookstack/blob - app/Book.php
Making sure MyISAM is set for the tables that need it for new installtions that are...
[bookstack] / app / Book.php
1 <?php namespace BookStack;
2
3 class Book extends Entity
4 {
5
6     protected $fillable = ['name', 'description'];
7
8     /**
9      * Get the url for this book.
10      * @return string
11      */
12     public function getUrl()
13     {
14         return '/books/' . $this->slug;
15     }
16
17     /*
18      * Get the edit url for this book.
19      * @return string
20      */
21     public function getEditUrl()
22     {
23         return $this->getUrl() . '/edit';
24     }
25
26     /**
27      * Get all pages within this book.
28      * @return \Illuminate\Database\Eloquent\Relations\HasMany
29      */
30     public function pages()
31     {
32         return $this->hasMany(Page::class);
33     }
34
35     /**
36      * Get all chapters within this book.
37      * @return \Illuminate\Database\Eloquent\Relations\HasMany
38      */
39     public function chapters()
40     {
41         return $this->hasMany(Chapter::class);
42     }
43
44     /**
45      * Get an excerpt of this book's description to the specified length or less.
46      * @param int $length
47      * @return string
48      */
49     public function getExcerpt($length = 100)
50     {
51         $description = $this->description;
52         return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
53     }
54
55 }