]> BookStack Code Mirror - bookstack/blob - app/PageRevision.php
Fixes a corner case with exclamation in the ID.
[bookstack] / app / PageRevision.php
1 <?php namespace BookStack;
2
3 class PageRevision extends Model
4 {
5     protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
6
7     /**
8      * Get the user that created the page revision
9      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
10      */
11     public function createdBy()
12     {
13         return $this->belongsTo(User::class, 'created_by');
14     }
15
16     /**
17      * Get the page this revision originates from.
18      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
19      */
20     public function page()
21     {
22         return $this->belongsTo(Page::class);
23     }
24
25     /**
26      * Get the url for this revision.
27      * @param null|string $path
28      * @return string
29      */
30     public function getUrl($path = null)
31     {
32         $url = $this->page->getUrl() . '/revisions/' . $this->id;
33         if ($path) {
34             return $url . '/' . trim($path, '/');
35         }
36         return $url;
37     }
38
39     /**
40      * Get the previous revision for the same page if existing
41      * @return \BookStack\PageRevision|null
42      */
43     public function getPrevious()
44     {
45         if ($id = static::where('page_id', '=', $this->page_id)->where('id', '<', $this->id)->max('id')) {
46             return static::find($id);
47         }
48         return null;
49     }
50
51     /**
52      * Allows checking of the exact class, Used to check entity type.
53      * Included here to align with entities in similar use cases.
54      * (Yup, Bit of an awkward hack)
55      * @param $type
56      * @return bool
57      */
58     public static function isA($type)
59     {
60         return $type === 'revision';
61     }
62 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.