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

LibreSign / libresign / 20443160568

22 Dec 2025 08:26PM UTC coverage: 43.449%. First build
20443160568

Pull #6243

github

web-flow
Merge 85ed9f61c into 6d6fcf9aa
Pull Request #6243: feat: unified search

0 of 87 new or added lines in 2 files covered. (0.0%)

5936 of 13662 relevant lines covered (43.45%)

5.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\IDBConnection;
19
use OCP\IL10N;
20
use OCP\IURLGenerator;
21
use OCP\IUser;
22
use OCP\Search\IProvider;
23
use OCP\Search\ISearchQuery;
24
use OCP\Search\SearchResult;
25
use OCP\Search\SearchResultEntry;
26

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

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

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

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

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

NEW
63
                $term = $query->getTerm();
×
NEW
64
                $limit = $query->getLimit();
×
NEW
65
                $offset = $query->getCursor();
×
66

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

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

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

84
        /**
85
         * Format a File entity as a SearchResultEntry
86
         *
87
         * @param File $file The file entity to format
88
         * @param IUser $user Current user
89
         * @return SearchResultEntry Formatted search result entry
90
         */
91
        private function formatResult(File $file, IUser $user): SearchResultEntry {
NEW
92
                $userFolder = $this->rootFolder->getUserFolder($user->getUID());
×
NEW
93
                $thumbnailUrl = '';
×
NEW
94
                $subline = '';
×
NEW
95
                $icon = '';
×
NEW
96
                $path = '';
×
97

98
                try {
NEW
99
                        $nodes = $userFolder->getById($file->getNodeId());
×
NEW
100
                        if (!empty($nodes)) {
×
NEW
101
                                $node = array_shift($nodes);
×
102

NEW
103
                                $icon = $this->mimeTypeDetector->mimeTypeIcon($node->getMimetype());
×
104

NEW
105
                                $thumbnailUrl = $this->urlGenerator->linkToRouteAbsolute(
×
NEW
106
                                        'core.Preview.getPreviewByFileId',
×
NEW
107
                                        [
×
NEW
108
                                                'x' => 32,
×
NEW
109
                                                'y' => 32,
×
NEW
110
                                                'fileId' => $node->getId()
×
NEW
111
                                        ]
×
NEW
112
                                );
×
113

NEW
114
                                $path = $userFolder->getRelativePath($node->getPath());
×
NEW
115
                                $subline = $this->formatSubline($path);
×
116
                        }
NEW
117
                } catch (\Exception $e) {
×
118
                }
119

NEW
120
                $link = $this->urlGenerator->linkToRoute(
×
NEW
121
                        'files.View.showFile',
×
NEW
122
                        ['fileid' => $file->getNodeId()]
×
NEW
123
                );
×
124

NEW
125
                $searchResultEntry = new SearchResultEntry(
×
NEW
126
                        $thumbnailUrl,
×
NEW
127
                        $file->getName() ?? $this->l10n->t('Unnamed document'),
×
NEW
128
                        $subline,
×
NEW
129
                        $this->urlGenerator->getAbsoluteURL($link),
×
NEW
130
                        $icon,
×
NEW
131
                );
×
132

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

NEW
136
                return $searchResultEntry;
×
137
        }
138

139
        private function formatSubline(string $path): string {
NEW
140
                if (strrpos($path, '/') > 0) {
×
NEW
141
                        $path = ltrim(dirname($path), '/');
×
NEW
142
                        return $this->l10n->t('in %s', [$path]);
×
143
                } else {
NEW
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