<?php namespace BookStack\Http\Controllers;
-use BookStack\Repos\EntityRepo;
-use BookStack\Services\SearchService;
-use BookStack\Services\ViewService;
+use BookStack\Actions\ViewService;
+use BookStack\Entities\Repos\EntityRepo;
+use BookStack\Entities\SearchService;
use Illuminate\Http\Request;
class SearchController extends Controller
/**
* SearchController constructor.
- * @param EntityRepo $entityRepo
+ * @param \BookStack\Entities\Repos\EntityRepo $entityRepo
* @param ViewService $viewService
* @param SearchService $searchService
*/
$nextPageLink = baseUrl('/search?term=' . urlencode($searchTerm) . '&page=' . ($page+1));
$results = $this->searchService->searchEntities($searchTerm, 'all', $page, 20);
- $hasNextPage = $this->searchService->searchEntities($searchTerm, 'all', $page+1, 20)['count'] > 0;
return view('search/all', [
'entities' => $results['results'],
'totalResults' => $results['total'],
'searchTerm' => $searchTerm,
- 'hasNextPage' => $hasNextPage,
+ 'hasNextPage' => $results['has_more'],
'nextPageLink' => $nextPageLink
]);
}
{
$entityTypes = $request->filled('types') ? collect(explode(',', $request->get('types'))) : collect(['page', 'chapter', 'book']);
$searchTerm = $request->get('term', false);
+ $permission = $request->get('permission', 'view');
// Search for entities otherwise show most popular
if ($searchTerm !== false) {
$searchTerm .= ' {type:'. implode('|', $entityTypes->toArray()) .'}';
- $entities = $this->searchService->searchEntities($searchTerm)['results'];
+ $entities = $this->searchService->searchEntities($searchTerm, 'all', 1, 20, $permission)['results'];
} else {
$entityNames = $entityTypes->map(function ($type) {
- return 'BookStack\\' . ucfirst($type);
+ return 'BookStack\\' . ucfirst($type); // TODO - Extract this elsewhere, too specific and stringy
})->toArray();
- $entities = $this->viewService->getPopular(20, 0, $entityNames);
+ $entities = $this->viewService->getPopular(20, 0, $entityNames, $permission);
}
return view('search/entity-ajax-list', ['entities' => $entities]);
}
-
}
-
-