2015-09-11 02:31:09 +08:00
|
|
|
<?php namespace BookStack;
|
2015-07-28 03:17:08 +08:00
|
|
|
|
|
|
|
|
2015-08-16 21:51:45 +08:00
|
|
|
class Chapter extends Entity
|
2015-07-28 03:17:08 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
protected $fillable = ['name', 'description', 'priority', 'book_id'];
|
|
|
|
|
|
|
|
public function book()
|
|
|
|
{
|
2015-09-11 02:31:09 +08:00
|
|
|
return $this->belongsTo('BookStack\Book');
|
2015-07-28 03:17:08 +08:00
|
|
|
}
|
|
|
|
|
2015-07-31 05:27:35 +08:00
|
|
|
public function pages()
|
2015-07-28 03:17:08 +08:00
|
|
|
{
|
2015-09-11 02:31:09 +08:00
|
|
|
return $this->hasMany('BookStack\Page')->orderBy('priority', 'ASC');
|
2015-07-28 03:17:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getUrl()
|
|
|
|
{
|
|
|
|
return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
|
|
|
|
}
|
|
|
|
|
2015-07-31 05:27:35 +08:00
|
|
|
public function getExcerpt($length = 100)
|
|
|
|
{
|
|
|
|
return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
|
|
|
|
}
|
|
|
|
|
2015-07-28 03:17:08 +08:00
|
|
|
}
|