]> BookStack Code Mirror - bookstack/blob - app/Book.php
Added view count tracking with personalised lists
[bookstack] / app / Book.php
1 <?php
2
3 namespace BookStack;
4
5 class Book extends Entity
6 {
7
8     protected $fillable = ['name', 'description'];
9
10     public function getUrl()
11     {
12         return '/books/' . $this->slug;
13     }
14
15     public function getEditUrl()
16     {
17         return $this->getUrl() . '/edit';
18     }
19
20     public function pages()
21     {
22         return $this->hasMany('BookStack\Page');
23     }
24
25     public function chapters()
26     {
27         return $this->hasMany('BookStack\Chapter');
28     }
29
30     public function children()
31     {
32         $pages = $this->pages()->where('chapter_id', '=', 0)->get();
33         $chapters = $this->chapters()->get();
34         foreach($chapters as $chapter) {
35             $pages->push($chapter);
36         }
37         return $pages->sortBy('priority');
38     }
39
40     public function getExcerpt($length = 100)
41     {
42         return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
43     }
44
45 }