-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial integration of Search Provider
Signed-off-by: Christian Hartmann <[email protected]>
- Loading branch information
1 parent
7afb7e2
commit 27e2700
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Forms\Search; | ||
|
||
use OCA\Forms\Controller\PageController; | ||
use OCA\Forms\Db\Form; | ||
use OCP\IURLGenerator; | ||
use OCP\Search\SearchResultEntry; | ||
|
||
class FormsSearchResultEntry extends SearchResultEntry { | ||
public function __construct(Form $form) { | ||
$urlGenerator = new IURLGenerator(); | ||
Check failure on line 18 in lib/Search/FormsSearchResultEntry.php GitHub Actions / static-psalm-analysis dev-stable30InterfaceInstantiation
Check failure on line 18 in lib/Search/FormsSearchResultEntry.php GitHub Actions / static-psalm-analysis dev-masterInterfaceInstantiation
|
||
$formUrl = $urlGenerator->linkToRoute('forms.page.views', ['hash' => $form->getHash(), 'view' => 'submit']); | ||
parent::__construct('', $form->getTitle(), $form->getDescription(), $formUrl, 'forms-dark'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Forms\Search; | ||
|
||
use OCA\Forms\Db\Form; | ||
use OCA\Forms\Search\FormsSearchResultEntry; | ||
use OCA\Forms\Service\FormsService; | ||
use OCP\IL10N; | ||
use OCP\IUser; | ||
use OCP\Search\IProvider; | ||
use OCP\Search\ISearchQuery; | ||
use OCP\Search\SearchResult; | ||
|
||
class SearchProvider implements IProvider { | ||
/** | ||
* @psalm-suppress PossiblyUnusedMethod | ||
*/ | ||
public function __construct( | ||
private IL10N $l10n, | ||
private FormsService $formsService, | ||
) { | ||
} | ||
|
||
public function getId(): string { | ||
return 'forms'; | ||
} | ||
|
||
public function getName(): string { | ||
return $this->l10n->t('Forms'); | ||
} | ||
|
||
public function search(IUser $user, ISearchQuery $query): SearchResult { | ||
$forms = $this->formsService->search($user, $query); | ||
|
||
$results = array_map(function (Form $form) { | ||
return [ | ||
'object' => $form, | ||
'entry' => new FormsSearchResultEntry($form) | ||
]; | ||
}, $forms); | ||
|
||
$resultEntries = array_map(function (array $result) { | ||
return $result['entry']; | ||
}, $results); | ||
|
||
return SearchResult::complete( | ||
$this->l10n->t('Forms'), | ||
$resultEntries | ||
); | ||
} | ||
|
||
public function getOrder(string $route, array $routeParameters): int { | ||
if (str_contains($route, Application::APP_ID)) { | ||
Check failure on line 59 in lib/Search/Provider.php GitHub Actions / static-psalm-analysis dev-stable30UndefinedClass
Check failure on line 59 in lib/Search/Provider.php GitHub Actions / static-psalm-analysis dev-masterUndefinedClass
|
||
// Active app, prefer my results | ||
return -1; | ||
} | ||
return 77; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters