]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Chapter.php
Show bookshelves that a book belongs to on a book view
[bookstack] / app / Entities / Chapter.php
index bdacb7c9d8340ee26a43c9652587594d33afadb6..d121432fa1a65035b03975b561dcfe70537b741e 100644 (file)
@@ -1,6 +1,8 @@
 <?php namespace BookStack\Entities;
 
-class Chapter extends Entity
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class Chapter extends BookChild
 {
     public $searchFactor = 1.3;
 
@@ -15,15 +17,6 @@ class Chapter extends Entity
         return 'BookStack\\Chapter';
     }
 
-    /**
-     * Get the book this chapter is within.
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
-     */
-    public function book()
-    {
-        return $this->belongsTo(Book::class);
-    }
-
     /**
      * Get the pages that this chapter contains.
      * @param string $dir
@@ -42,10 +35,13 @@ class Chapter extends Entity
     public function getUrl($path = false)
     {
         $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
+        $fullPath = '/books/' . urlencode($bookSlug) . '/chapter/' . urlencode($this->slug);
+
         if ($path !== false) {
-            return baseUrl('/books/' . urlencode($bookSlug) . '/chapter/' . urlencode($this->slug) . '/' . trim($path, '/'));
+            $fullPath .= '/' . trim($path, '/');
         }
-        return baseUrl('/books/' . urlencode($bookSlug) . '/chapter/' . urlencode($this->slug));
+
+        return url($fullPath);
     }
 
     /**
@@ -56,7 +52,7 @@ class Chapter extends Entity
     public function getExcerpt(int $length = 100)
     {
         $description = $this->text ?? $this->description;
-        return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
+        return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
     }
 
     /**