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