BookStack/app/Chapter.php

30 lines
744 B
PHP
Raw Normal View History

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