use Activity;
+use BookStack\Exceptions\NotFoundException;
use BookStack\Services\RestrictionService;
use Illuminate\Support\Str;
use BookStack\Chapter;
* @param $slug
* @param $bookId
* @return mixed
+ * @throws NotFoundException
*/
public function getBySlug($slug, $bookId)
{
$chapter = $this->chapterQuery()->where('slug', '=', $slug)->where('book_id', '=', $bookId)->first();
- if ($chapter === null) abort(404);
+ if ($chapter === null) throw new NotFoundException('Chapter not found');
return $chapter;
}
+ /**
+ * Get the child items for a chapter
+ * @param Chapter $chapter
+ */
+ public function getChildren(Chapter $chapter)
+ {
+ return $this->restrictionService->enforcePageRestrictions($chapter->pages())->get();
+ }
+
/**
* Create a new chapter from request input.
* @param $input
}
Activity::removeEntity($chapter);
$chapter->views()->delete();
+ $chapter->restrictions()->delete();
$chapter->delete();
}
*/
public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = [])
{
- $terms = explode(' ', $term);
+ preg_match_all('/"(.*?)"/', $term, $matches);
+ if (count($matches[1]) > 0) {
+ $terms = $matches[1];
+ $term = trim(preg_replace('/"(.*?)"/', '', $term));
+ } else {
+ $terms = [];
+ }
+ if (!empty($term)) {
+ $terms = array_merge($terms, explode(' ', $term));
+ }
$chapters = $this->restrictionService->enforceChapterRestrictions($this->chapter->fullTextSearchQuery(['name', 'description'], $terms, $whereTerms))
->paginate($count)->appends($paginationAppends);
$words = join('|', explode(' ', preg_quote(trim($term), '/')));