• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 22006424715

13 Feb 2026 11:30PM UTC coverage: 51.545%. First build
22006424715

Pull #6878

github

web-flow
Merge dc5b56837 into ae70bcc7a
Pull Request #6878: fix: search provider navigation

0 of 11 new or added lines in 1 file covered. (0.0%)

9058 of 17573 relevant lines covered (51.54%)

6.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/Search/FileSearchProvider.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
7
 * SPDX-License-Identifier: AGPL-3.0-or-later
8
 */
9

10
namespace OCA\Libresign\Search;
11

12
use OCA\Libresign\AppInfo\Application;
13
use OCA\Libresign\Db\File;
14
use OCA\Libresign\Db\SignRequestMapper;
15
use OCP\App\IAppManager;
16
use OCP\Files\IMimeTypeDetector;
17
use OCP\Files\IRootFolder;
18
use OCP\IL10N;
19
use OCP\IURLGenerator;
20
use OCP\IUser;
21
use OCP\Search\IProvider;
22
use OCP\Search\ISearchQuery;
23
use OCP\Search\SearchResult;
24
use OCP\Search\SearchResultEntry;
25

26
class FileSearchProvider implements IProvider {
27
        public function __construct(
28
                private IL10N $l10n,
29
                private IURLGenerator $urlGenerator,
30
                private IRootFolder $rootFolder,
31
                private IAppManager $appManager,
32
                private IMimeTypeDetector $mimeTypeDetector,
33
                private SignRequestMapper $fileMapper,
34
        ) {
35
        }
×
36

37
        #[\Override]
38
        public function getId(): string {
39
                return 'libresign_files';
×
40
        }
41

42
        #[\Override]
43
        public function getName(): string {
44
                return $this->l10n->t('LibreSign documents');
×
45
        }
46

47
        #[\Override]
48
        public function getOrder(string $route, array $routeParameters): int {
49
                if (strpos($route, Application::APP_ID . '.') === 0) {
×
50
                        return 0;
×
51
                }
52
                return 10;
×
53
        }
54

55
        #[\Override]
56
        public function search(IUser $user, ISearchQuery $query): SearchResult {
57
                if (!$this->appManager->isEnabledForUser(Application::APP_ID, $user)) {
×
58
                        return SearchResult::complete($this->l10n->t('LibreSign documents'), []);
×
59
                }
60

61
                $term = $query->getTerm();
×
62
                $limit = $query->getLimit();
×
63
                $offset = $query->getCursor();
×
64

65
                try {
66
                        $files = $this->fileMapper->getFilesToSearchProvider($user, $term, $limit, (int)$offset);
×
67
                } catch (\Exception $e) {
×
68
                        return SearchResult::complete($this->l10n->t('LibreSign documents'), []);
×
69
                }
70

71
                $results = array_map(function (File $file) use ($user) {
×
72
                        return $this->formatResult($file, $user);
×
73
                }, $files);
×
74

75
                return SearchResult::paginated(
×
76
                        $this->l10n->t('LibreSign documents'),
×
77
                        $results,
×
78
                        $offset + $limit
×
79
                );
×
80
        }
81

82
        private function formatResult(File $file, IUser $user): SearchResultEntry {
83
                $userFolder = $this->rootFolder->getUserFolder($file->getUserId());
×
84
                $thumbnailUrl = '';
×
85
                $subline = '';
×
86
                $icon = '';
×
87
                $path = '';
×
88

89
                try {
90
                        $nodes = $userFolder->getById($file->getNodeId());
×
91
                        if (!empty($nodes)) {
×
92
                                $node = array_shift($nodes);
×
93

94
                                $icon = $this->mimeTypeDetector->mimeTypeIcon($node->getMimetype());
×
95

96
                                $thumbnailUrl = $this->urlGenerator->linkToRouteAbsolute(
×
97
                                        'core.Preview.getPreviewByFileId',
×
98
                                        [
×
99
                                                'x' => 32,
×
100
                                                'y' => 32,
×
101
                                                'fileId' => $node->getId()
×
102
                                        ]
×
103
                                );
×
104

105
                                $path = $userFolder->getRelativePath($node->getPath());
×
106
                                $subline = $this->formatSubline($path);
×
107
                        }
108
                } catch (\Exception $e) {
×
109
                }
110

NEW
111
                if ($file->getUserId() === $user->getUID()) {
×
NEW
112
                        $link = $this->urlGenerator->linkToRouteAbsolute(
×
NEW
113
                                'libresign.page.indexFPath',
×
NEW
114
                                ['path' => 'filelist/sign']
×
NEW
115
                        );
×
NEW
116
                        $link .= '?uuid=' . urlencode($file->getUuid());
×
117
                } else {
NEW
118
                        $link = $this->urlGenerator->linkToRouteAbsolute(
×
NEW
119
                                'libresign.page.indexFPath',
×
NEW
120
                                ['path' => 'validation/' . $file->getUuid()]
×
NEW
121
                        );
×
122
                }
123

124
                $searchResultEntry = new SearchResultEntry(
×
125
                        $thumbnailUrl,
×
126
                        $file->getName(),
×
127
                        $subline,
×
NEW
128
                        $link,
×
129
                        $icon,
×
130
                );
×
131

132
                $searchResultEntry->addAttribute('fileId', (string)$file->getNodeId());
×
133
                $searchResultEntry->addAttribute('path', $path);
×
134

135
                return $searchResultEntry;
×
136
        }
137

138
        private function formatSubline(string $path): string {
139
                if (strrpos($path, '/') > 0) {
×
140
                        $path = ltrim(dirname($path), '/');
×
141
                        // TRANSLATORS This string indicates the location of a file in a given path.
142
                        return $this->l10n->t('in %s', [$path]);
×
143
                } else {
144
                        return '';
×
145
                }
146
        }
147

148
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc