]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/PageRepo.php
Merge branch 'custom_role_system'
[bookstack] / app / Repos / PageRepo.php
index f3933af69da8cd3cce6ddcdceedf69b0fe64c869..3d675183e3f1c807d78916893cf4488de3b5155c 100644 (file)
@@ -96,6 +96,16 @@ class PageRepo
         return $page;
     }
 
+    /**
+     * Count the pages with a particular slug within a book.
+     * @param $slug
+     * @param $bookId
+     * @return mixed
+     */
+    public function countBySlug($slug, $bookId)
+    {
+        return $this->page->where('slug', '=', $slug)->where('book_id', '=', $bookId)->count();
+    }
 
     /**
      * Save a new page into the system.
@@ -190,7 +200,16 @@ class PageRepo
      */
     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));
+        }
         $pages = $this->restrictionService->enforcePageRestrictions($this->page->fullTextSearchQuery(['name', 'text'], $terms, $whereTerms))
             ->paginate($count)->appends($paginationAppends);