fix paginated search

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Julien Veyssier 2020-09-19 17:45:05 +02:00
parent c04a027ff1
commit 39d19aa518
No known key found for this signature in database
GPG key ID: 4141FEE162030638

View file

@ -103,14 +103,13 @@ class MoodleSearchProvider implements IProvider {
$limit = $query->getLimit();
$term = $query->getTerm();
$offset = $query->getCursor();
$offset = $offset ? intval($offset) : 0;
$theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme', '');
$thumbnailUrl = ($theme === 'dark') ?
$this->urlGenerator->imagePath(Application::APP_ID, 'app.svg') :
$this->urlGenerator->imagePath(Application::APP_ID, 'app-dark.svg');
$resultBills = [];
$moodleUrl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'url', '');
$accessToken = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'token', '');
$searchEnabled = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'search_enabled', '0') === '1';
@ -119,6 +118,7 @@ class MoodleSearchProvider implements IProvider {
}
$searchResults = $this->service->search($moodleUrl, $accessToken, $term);
$searchResults = array_slice($searchResults, $offset, $limit);
$formattedResults = \array_map(function (array $entry) use ($thumbnailUrl, $moodleUrl): MoodleSearchResultEntry {
return new MoodleSearchResultEntry(
@ -134,7 +134,7 @@ class MoodleSearchProvider implements IProvider {
return SearchResult::paginated(
$this->getName(),
$formattedResults,
$query->getCursor() + count($formattedResults)
$offset + $limit
);
}