1 <?php namespace BookStack;
4 class Page extends Entity
6 protected $fillable = ['name', 'html', 'priority', 'markdown'];
8 protected $simpleAttributes = ['name', 'id', 'slug'];
10 public function toSimpleArray()
12 $array = array_intersect_key($this->toArray(), array_flip($this->simpleAttributes));
13 $array['url'] = $this->getUrl();
17 public function book()
19 return $this->belongsTo('BookStack\Book');
22 public function chapter()
24 return $this->belongsTo('BookStack\Chapter');
27 public function hasChapter()
29 return $this->chapter()->count() > 0;
32 public function revisions()
34 return $this->hasMany('BookStack\PageRevision')->where('type', '=', 'version')->orderBy('created_at', 'desc');
37 public function getUrl()
39 $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
40 $midText = $this->draft ? '/draft/' : '/page/';
41 $idComponent = $this->draft ? $this->id : $this->slug;
42 return '/books/' . $bookSlug . $midText . $idComponent;
45 public function getExcerpt($length = 100)
47 $text = strlen($this->text) > $length ? substr($this->text, 0, $length-3) . '...' : $this->text;
48 return mb_convert_encoding($text, 'UTF-8');