2015-09-10 14:31:09 -04:00
|
|
|
<?php namespace BookStack;
|
2015-07-27 15:17:08 -04:00
|
|
|
|
|
|
|
|
2015-08-16 09:51:45 -04:00
|
|
|
class Chapter extends Entity
|
2015-07-27 15:17:08 -04:00
|
|
|
{
|
|
|
|
protected $fillable = ['name', 'description', 'priority', 'book_id'];
|
|
|
|
|
|
|
|
public function book()
|
|
|
|
{
|
2015-09-10 14:31:09 -04:00
|
|
|
return $this->belongsTo('BookStack\Book');
|
2015-07-27 15:17:08 -04:00
|
|
|
}
|
|
|
|
|
2015-07-30 17:27:35 -04:00
|
|
|
public function pages()
|
2015-07-27 15:17:08 -04:00
|
|
|
{
|
2015-09-10 14:31:09 -04:00
|
|
|
return $this->hasMany('BookStack\Page')->orderBy('priority', 'ASC');
|
2015-07-27 15:17:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getUrl()
|
|
|
|
{
|
2015-11-29 12:33:25 -05:00
|
|
|
$bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
|
2015-11-26 18:45:04 -05:00
|
|
|
return '/books/' . $bookSlug. '/chapter/' . $this->slug;
|
2015-07-27 15:17:08 -04:00
|
|
|
}
|
|
|
|
|
2015-07-30 17:27:35 -04:00
|
|
|
public function getExcerpt($length = 100)
|
|
|
|
{
|
|
|
|
return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
|
|
|
|
}
|
|
|
|
|
2015-07-27 15:17:08 -04:00
|
|
|
}
|