-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make Forms available in unified search
Signed-off-by: Christian Hartmann <[email protected]>
- Loading branch information
1 parent
7afb7e2
commit 470810c
Showing
5 changed files
with
130 additions
and
2 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
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,18 @@ | ||
<?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 OCP\Search\SearchResultEntry; | ||
|
||
class FormsSearchResultEntry extends SearchResultEntry { | ||
public function __construct(Form $form, string $formUrl) { | ||
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,68 @@ | ||
<?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\AppInfo\Application; | ||
use OCA\Forms\Db\Form; | ||
use OCA\Forms\Service\FormsService; | ||
use OCP\IL10N; | ||
use OCP\IURLGenerator; | ||
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 IURLGenerator $urlGenerator, | ||
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($query); | ||
|
||
$results = array_map(function (Form $form) { | ||
$formUrl = $this->urlGenerator->linkToRoute('forms.page.views', ['hash' => $form->getHash(), 'view' => 'submit']); | ||
return [ | ||
'object' => $form, | ||
'entry' => new FormsSearchResultEntry($form, $formUrl) | ||
]; | ||
}, $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)) { | ||
// 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