]> BookStack Code Mirror - bookstack/blob - app/Chapter.php
c3001b69bd43778c2228f907901f5d3d8823b304
[bookstack] / app / Chapter.php
1 <?php namespace BookStack;
2
3
4 class Chapter extends Entity
5 {
6
7     protected $fillable = ['name', 'description', 'priority', 'book_id'];
8
9     public function book()
10     {
11         return $this->belongsTo('BookStack\Book');
12     }
13
14     public function pages()
15     {
16         return $this->hasMany('BookStack\Page')->orderBy('priority', 'ASC');
17     }
18
19     public function getUrl()
20     {
21         $bookSlug = isset($this->bookSlug) ? $this->bookSlug : $this->book->slug;
22         return '/books/' . $bookSlug. '/chapter/' . $this->slug;
23     }
24
25     public function getExcerpt($length = 100)
26     {
27         return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
28     }
29
30 }