]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/SearchController.php
Apply fixes from StyleCI
[bookstack] / app / Http / Controllers / SearchController.php
index 21ebea378c06c11f897046575a3fe76a3d0185f9..d4431e1662ba423a485dc46077d7aefe3a85b846 100644 (file)
@@ -1,27 +1,23 @@
-<?php namespace BookStack\Http\Controllers;
+<?php
 
-use BookStack\Actions\ViewService;
-use BookStack\Entities\Models\Book;
-use BookStack\Entities\Models\Bookshelf;
-use BookStack\Entities\Models\Entity;
+namespace BookStack\Http\Controllers;
+
+use BookStack\Entities\Queries\Popular;
+use BookStack\Entities\Tools\SearchOptions;
 use BookStack\Entities\Tools\SearchRunner;
 use BookStack\Entities\Tools\ShelfContext;
-use BookStack\Entities\Tools\SearchOptions;
 use BookStack\Entities\Tools\SiblingFetcher;
 use Illuminate\Http\Request;
 
 class SearchController extends Controller
 {
-    protected $viewService;
     protected $searchRunner;
     protected $entityContextManager;
 
     public function __construct(
-        ViewService $viewService,
         SearchRunner $searchRunner,
         ShelfContext $entityContextManager
     ) {
-        $this->viewService = $viewService;
         $this->searchRunner = $searchRunner;
         $this->entityContextManager = $entityContextManager;
     }
@@ -36,17 +32,17 @@ class SearchController extends Controller
         $this->setPageTitle(trans('entities.search_for_term', ['term' => $fullSearchString]));
 
         $page = intval($request->get('page', '0')) ?: 1;
-        $nextPageLink = url('/search?term=' . urlencode($fullSearchString) . '&page=' . ($page+1));
+        $nextPageLink = url('/search?term=' . urlencode($fullSearchString) . '&page=' . ($page + 1));
 
         $results = $this->searchRunner->searchEntities($searchOpts, 'all', $page, 20);
 
         return view('search.all', [
-            'entities'   => $results['results'],
+            'entities'     => $results['results'],
             'totalResults' => $results['total'],
-            'searchTerm' => $fullSearchString,
-            'hasNextPage' => $results['has_more'],
+            'searchTerm'   => $fullSearchString,
+            'hasNextPage'  => $results['has_more'],
             'nextPageLink' => $nextPageLink,
-            'options' => $searchOpts,
+            'options'      => $searchOpts,
         ]);
     }
 
@@ -57,6 +53,7 @@ class SearchController extends Controller
     {
         $term = $request->get('term', '');
         $results = $this->searchRunner->searchBook($bookId, $term);
+
         return view('partials.entity-list', ['entities' => $results]);
     }
 
@@ -67,6 +64,7 @@ class SearchController extends Controller
     {
         $term = $request->get('term', '');
         $results = $this->searchRunner->searchChapter($chapterId, $term);
+
         return view('partials.entity-list', ['entities' => $results]);
     }
 
@@ -77,15 +75,15 @@ class SearchController extends Controller
     public function searchEntitiesAjax(Request $request)
     {
         $entityTypes = $request->filled('types') ? explode(',', $request->get('types')) : ['page', 'chapter', 'book'];
-        $searchTerm =  $request->get('term', false);
+        $searchTerm = $request->get('term', false);
         $permission = $request->get('permission', 'view');
 
         // Search for entities otherwise show most popular
         if ($searchTerm !== false) {
-            $searchTerm .= ' {type:'. implode('|', $entityTypes) .'}';
+            $searchTerm .= ' {type:' . implode('|', $entityTypes) . '}';
             $entities = $this->searchRunner->searchEntities(SearchOptions::fromString($searchTerm), 'all', 1, 20, $permission)['results'];
         } else {
-            $entities = $this->viewService->getPopular(20, 0, $entityTypes, $permission);
+            $entities = (new Popular())->run(20, 0, $entityTypes, $permission);
         }
 
         return view('search.entity-ajax-list', ['entities' => $entities]);
@@ -99,7 +97,8 @@ class SearchController extends Controller
         $type = $request->get('entity_type', null);
         $id = $request->get('entity_id', null);
 
-        $entities = (new SiblingFetcher)->fetch($type, $id);
+        $entities = (new SiblingFetcher())->fetch($type, $id);
+
         return view('partials.entity-list-basic', ['entities' => $entities, 'style' => 'compact']);
     }
 }