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