5 use Illuminate\Database\Eloquent\Model;
7 class Page extends Entity
9 protected $fillable = ['name', 'html', 'priority', 'markdown'];
11 protected $simpleAttributes = ['name', 'id', 'slug'];
13 public function toSimpleArray()
15 $array = array_intersect_key($this->toArray(), array_flip($this->simpleAttributes));
16 $array['url'] = $this->getUrl();
20 public function book()
22 return $this->belongsTo('BookStack\Book');
25 public function chapter()
27 return $this->belongsTo('BookStack\Chapter');
30 public function hasChapter()
32 return $this->chapter()->count() > 0;
35 public function revisions()
37 return $this->hasMany('BookStack\PageRevision')->where('type', '=', 'version')->orderBy('created_at', 'desc');
40 public function getUrl()
42 $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
43 $midText = $this->draft ? '/draft/' : '/page/';
44 $idComponent = $this->draft ? $this->id : $this->slug;
45 return '/books/' . $bookSlug . $midText . $idComponent;
48 public function getExcerpt($length = 100)
50 $text = strlen($this->text) > $length ? substr($this->text, 0, $length-3) . '...' : $this->text;
51 return mb_convert_encoding($text, 'UTF-8');