BookStack/app/Book.php

52 lines
1.1 KiB
PHP
Raw Normal View History

2015-07-13 03:01:42 +08:00
<?php
namespace Oxbow;
class Book extends Entity
2015-07-13 03:01:42 +08:00
{
protected $fillable = ['name', 'description'];
public function getUrl()
{
return '/books/' . $this->slug;
}
public function getEditUrl()
{
return $this->getUrl() . '/edit';
}
2015-07-13 04:31:15 +08:00
public function pages()
{
return $this->hasMany('Oxbow\Page');
}
2015-07-28 03:17:08 +08:00
public function chapters()
{
return $this->hasMany('Oxbow\Chapter');
}
public function children()
{
$pages = $this->pages()->where('chapter_id', '=', 0)->get();
2015-07-28 03:17:08 +08:00
$chapters = $this->chapters()->get();
2015-07-31 06:18:48 +08:00
foreach($chapters as $chapter) {
$pages->push($chapter);
}
return $pages->sortBy('priority');
2015-07-28 03:17:08 +08:00
}
/**
* Gets only the most recent activity for this book
* @param int $limit
* @param int $page
* @return mixed
*/
public function recentActivity($limit = 20, $page=0)
{
return $this->hasMany('Oxbow\Activity')->orderBy('created_at', 'desc')->skip($limit*$page)->take($limit)->get();
}
2015-07-13 03:01:42 +08:00
}