]> BookStack Code Mirror - bookstack/blob - app/PageRevision.php
Merge branch 'diff' of git://github.com/younes0/BookStack into younes0-diff
[bookstack] / app / PageRevision.php
1 <?php namespace BookStack;
2
3
4 class PageRevision extends Model
5 {
6     protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
7
8     /**
9      * Get the user that created the page revision
10      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
11      */
12     public function createdBy()
13     {
14         return $this->belongsTo(User::class, 'created_by');
15     }
16
17     /**
18      * Get the page this revision originates from.
19      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
20      */
21     public function page()
22     {
23         return $this->belongsTo(Page::class);
24     }
25
26     /**
27      * Get the url for this revision.
28      * @return string
29      */
30     public function getUrl()
31     {
32         return $this->page->getUrl() . '/revisions/' . $this->id;
33     }
34
35     /**
36      * Get previous revision
37      * @return \BookStack\PageRevision
38      */
39     public function getPrevious()
40     {
41         if ($id = PageRevision::where('id', '<', $this->id)->max('id')) {
42             return PageRevision::find($id);
43         }
44     }
45
46     /**
47      * Get next revision
48      * @return \BookStack\PageRevision
49      */
50     public function getNext()
51     {
52         if ($id = PageRevision::where('id', '>', $this->id)->min('id')) {
53             return PageRevision::find($id);
54         }
55     }
56 }