1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-10-30 23:52:40 +01:00
BookStack/app/Book.php

46 lines
929 B
PHP
Raw Normal View History

2015-07-12 21:01:42 +02:00
<?php
namespace Oxbow;
class Book extends Entity
2015-07-12 21:01:42 +02:00
{
protected $fillable = ['name', 'description'];
public function getUrl()
{
return '/books/' . $this->slug;
}
public function getEditUrl()
{
return $this->getUrl() . '/edit';
}
2015-07-12 22:31:15 +02:00
public function pages()
{
return $this->hasMany('Oxbow\Page');
}
2015-07-27 21:17:08 +02:00
public function chapters()
{
return $this->hasMany('Oxbow\Chapter');
}
public function children()
{
$pages = $this->pages()->where('chapter_id', '=', 0)->get();
2015-07-27 21:17:08 +02:00
$chapters = $this->chapters()->get();
2015-07-31 00:18:48 +02:00
foreach($chapters as $chapter) {
$pages->push($chapter);
}
return $pages->sortBy('priority');
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-12 21:01:42 +02:00
}