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

LibreSign / libresign / 24083625942

07 Apr 2026 01:22PM UTC coverage: 55.6%. First build
24083625942

Pull #7450

github

web-flow
Merge b1c2ec824 into 1112b1165
Pull Request #7450: chore(rector): apply safe test-only batch and php82 baseline

25 of 50 new or added lines in 15 files covered. (50.0%)

10231 of 18401 relevant lines covered (55.6%)

6.61 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 {
NEW
49
                if (str_starts_with($route, Application::APP_ID . '.')) {
×
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);
×
NEW
67
                } catch (\Exception) {
×
68
                        return SearchResult::complete($this->l10n->t('LibreSign documents'), []);
×
69
                }
70

NEW
71
                $results = array_map(fn (File $file) => $this->formatResult($file, $user), $files);
×
72

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

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

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

92
                                $icon = $this->mimeTypeDetector->mimeTypeIcon($node->getMimetype());
×
93

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

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

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

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

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

133
                return $searchResultEntry;
×
134
        }
135

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

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