]> BookStack Code Mirror - bookstack/blob - app/Entities/Models/Chapter.php
fix image delete confirm text
[bookstack] / app / Entities / Models / Chapter.php
1 <?php namespace BookStack\Entities\Models;
2
3 use Illuminate\Support\Collection;
4
5 /**
6  * Class Chapter
7  * @property Collection<Page> $pages
8  */
9 class Chapter extends BookChild
10 {
11     public $searchFactor = 1.3;
12
13     protected $fillable = ['name', 'description', 'priority', 'book_id'];
14     protected $hidden = ['restricted', 'pivot', 'deleted_at'];
15
16     /**
17      * Get the pages that this chapter contains.
18      * @param string $dir
19      * @return mixed
20      */
21     public function pages($dir = 'ASC')
22     {
23         return $this->hasMany(Page::class)->orderBy('priority', $dir);
24     }
25
26     /**
27      * Get the url of this chapter.
28      */
29     public function getUrl($path = ''): string
30     {
31         $parts = [
32             'books',
33             urlencode($this->getAttribute('bookSlug') ?? $this->book->slug),
34             'chapter',
35             urlencode($this->slug),
36             trim($path, '/'),
37         ];
38
39         return url('/' . implode('/', $parts));
40     }
41
42     /**
43      * Get the visible pages in this chapter.
44      */
45     public function getVisiblePages(): Collection
46     {
47         return $this->pages()->visible()
48         ->orderBy('draft', 'desc')
49         ->orderBy('priority', 'asc')
50         ->get();
51     }
52 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.