]> BookStack Code Mirror - bookstack/blob - app/Book.php
Add socialite authentication for okta
[bookstack] / app / Book.php
1 <?php namespace BookStack;
2
3 class Book extends Entity
4 {
5
6     protected $fillable = ['name', 'description'];
7
8     /**
9      * Get the url for this book.
10      * @param string|bool $path
11      * @return string
12      */
13     public function getUrl($path = false)
14     {
15         if ($path !== false) {
16             return baseUrl('/books/' . urlencode($this->slug) . '/' . trim($path, '/'));
17         }
18         return baseUrl('/books/' . urlencode($this->slug));
19     }
20
21     /*
22      * Get the edit url for this book.
23      * @return string
24      */
25     public function getEditUrl()
26     {
27         return $this->getUrl() . '/edit';
28     }
29
30     /**
31      * Get all pages within this book.
32      * @return \Illuminate\Database\Eloquent\Relations\HasMany
33      */
34     public function pages()
35     {
36         return $this->hasMany(Page::class);
37     }
38
39     /**
40      * Get all chapters within this book.
41      * @return \Illuminate\Database\Eloquent\Relations\HasMany
42      */
43     public function chapters()
44     {
45         return $this->hasMany(Chapter::class);
46     }
47
48     /**
49      * Get an excerpt of this book's description to the specified length or less.
50      * @param int $length
51      * @return string
52      */
53     public function getExcerpt($length = 100)
54     {
55         $description = $this->description;
56         return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
57     }
58
59     /**
60      * Return a generalised, common raw query that can be 'unioned' across entities.
61      * @return string
62      */
63     public function entityRawQuery()
64     {
65         return "'BookStack\\\\Book' as entity_type, id, id as entity_id, slug, name, {$this->textField} as text,'' as html, '0' as book_id, '0' as priority, '0' as chapter_id, '0' as draft, created_by, updated_by, updated_at, created_at";
66     }
67
68 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.