]> BookStack Code Mirror - bookstack/blob - app/Book.php
Updated views for permissions and added notifications. Fixes #2 and #7
[bookstack] / app / Book.php
1 <?php
2
3 namespace Oxbow;
4
5 class Book extends Entity
6 {
7
8     protected $fillable = ['name', 'description'];
9
10     public function getUrl()
11     {
12         return '/books/' . $this->slug;
13     }
14
15     public function getEditUrl()
16     {
17         return $this->getUrl() . '/edit';
18     }
19
20     public function pages()
21     {
22         return $this->hasMany('Oxbow\Page');
23     }
24
25     public function chapters()
26     {
27         return $this->hasMany('Oxbow\Chapter');
28     }
29
30     public function children()
31     {
32         $pages = $this->pages()->where('chapter_id', '=', 0)->get();
33         $chapters = $this->chapters()->get();
34         foreach($chapters as $chapter) {
35             $pages->push($chapter);
36         }
37         return $pages->sortBy('priority');
38     }
39
40     /**
41      * Gets only the most recent activity for this book
42      * @param int $limit
43      * @param int $page
44      * @return mixed
45      */
46     public function recentActivity($limit = 20, $page=0)
47     {
48         return $this->hasMany('Oxbow\Activity')->orderBy('created_at', 'desc')->skip($limit*$page)->take($limit)->get();
49     }
50
51 }