]> BookStack Code Mirror - bookstack/blob - app/Page.php
Got standard form-based registration working
[bookstack] / app / Page.php
1 <?php
2
3 namespace Oxbow;
4
5 use Illuminate\Database\Eloquent\Model;
6
7 class Page extends Entity
8 {
9     protected $fillable = ['name', 'html', 'priority'];
10
11     protected $simpleAttributes = ['name', 'id', 'slug'];
12
13     public function toSimpleArray()
14     {
15         $array = array_intersect_key($this->toArray(), array_flip($this->simpleAttributes));
16         $array['url'] = $this->getUrl();
17         return $array;
18     }
19
20     public function book()
21     {
22         return $this->belongsTo('Oxbow\Book');
23     }
24
25     public function chapter()
26     {
27         return $this->belongsTo('Oxbow\Chapter');
28     }
29
30     public function hasChapter()
31     {
32         return $this->chapter()->count() > 0;
33     }
34
35
36     public function revisions()
37     {
38         return $this->hasMany('Oxbow\PageRevision')->orderBy('created_at', 'desc');
39     }
40
41     public function getUrl()
42     {
43         return '/books/' . $this->book->slug . '/page/' . $this->slug;
44     }
45
46     public function getExcerpt($length = 100)
47     {
48         return strlen($this->text) > $length ? substr($this->text, 0, $length-3) . '...' : $this->text;
49     }
50
51 }