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

LibreSign / libresign / 20469125400

23 Dec 2025 06:57PM UTC coverage: 43.466%. First build
20469125400

Pull #6243

github

web-flow
Merge d8263f711 into 4f1a71d46
Pull Request #6243: feat: unified search

4 of 87 new or added lines in 2 files covered. (4.6%)

5937 of 13659 relevant lines covered (43.47%)

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\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
        ) {
NEW
35
        }
×
36

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

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

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

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

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

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

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

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

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

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

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

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

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

NEW
111
                $link = $this->urlGenerator->linkToRoute(
×
NEW
112
                        'files.View.showFile',
×
NEW
113
                        ['fileid' => $file->getNodeId()]
×
NEW
114
                );
×
115

NEW
116
                $searchResultEntry = new SearchResultEntry(
×
NEW
117
                        $thumbnailUrl,
×
NEW
118
                        $file->getName() ?? $this->l10n->t('Unnamed document'),
×
NEW
119
                        $subline,
×
NEW
120
                        $this->urlGenerator->getAbsoluteURL($link),
×
NEW
121
                        $icon,
×
NEW
122
                );
×
123

NEW
124
                $searchResultEntry->addAttribute('fileId', (string)$file->getNodeId());
×
NEW
125
                $searchResultEntry->addAttribute('path', $path);
×
126

NEW
127
                return $searchResultEntry;
×
128
        }
129

130
        private function formatSubline(string $path): string {
NEW
131
                if (strrpos($path, '/') > 0) {
×
NEW
132
                        $path = ltrim(dirname($path), '/');
×
NEW
133
                        return $this->l10n->t('in %s', [$path]);
×
134
                } else {
NEW
135
                        return '';
×
136
                }
137
        }
138

139
}
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

© 2025 Coveralls, Inc