BookStack/app/Chapter.php

31 lines
720 B
PHP
Raw Normal View History

<?php namespace BookStack;
2015-07-27 15:17:08 -04:00
class Chapter extends Entity
2015-07-27 15:17:08 -04:00
{
protected $fillable = ['name', 'description', 'priority', 'book_id'];
public function book()
{
return $this->belongsTo('BookStack\Book');
2015-07-27 15:17:08 -04:00
}
public function pages()
2015-07-27 15:17:08 -04:00
{
return $this->hasMany('BookStack\Page')->orderBy('priority', 'ASC');
2015-07-27 15:17:08 -04:00
}
public function getUrl()
{
$bookSlug = isset($this->bookSlug) ? $this->bookSlug : $this->book->slug;
return '/books/' . $bookSlug. '/chapter/' . $this->slug;
2015-07-27 15:17:08 -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
}