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