<?php namespace BookStack\Entities;
-class Chapter extends Entity
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class Chapter extends BookChild
{
public $searchFactor = 1.3;
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
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);
}
/**
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;
}
/**