1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-11-24 20:02:35 +01:00
BookStack/app/Chapter.php
2015-11-26 23:45:04 +00:00

31 lines
720 B
PHP

<?php namespace BookStack;
class Chapter extends Entity
{
protected $fillable = ['name', 'description', 'priority', 'book_id'];
public function book()
{
return $this->belongsTo('BookStack\Book');
}
public function pages()
{
return $this->hasMany('BookStack\Page')->orderBy('priority', 'ASC');
}
public function getUrl()
{
$bookSlug = isset($this->bookSlug) ? $this->bookSlug : $this->book->slug;
return '/books/' . $bookSlug. '/chapter/' . $this->slug;
}
public function getExcerpt($length = 100)
{
return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
}
}