Provider::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Audio Player
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @copyright 2020 Marcel Scherello
10
 */
11
12
declare(strict_types=1);
13
14
namespace OCA\audioplayer\Search;
15
16
use OCA\audioplayer\Controller\DbController;
17
use OCP\IL10N;
18
use OCP\IURLGenerator;
19
use OCP\IUser;
20
use OCP\Search\IProvider;
21
use OCP\Search\ISearchQuery;
22
use OCP\Search\SearchResult;
23
use OCP\Search\SearchResultEntry;
24
25
class Provider implements IProvider
26
{
27
28
    /** @var IL10N */
29
    private $l10n;
30
31
    /** @var IURLGenerator */
32
    private $urlGenerator;
33
34
    private $DBController;
35
36
    public function __construct(IL10N $l10n,
37
                                IURLGenerator $urlGenerator,
38
                                DBController $DBController)
39
    {
40
        $this->l10n = $l10n;
41
        $this->urlGenerator = $urlGenerator;
42
        $this->DBController = $DBController;
43
    }
44
45
    public function getId(): string
46
    {
47
        return 'audioplayer';
48
    }
49
50
    public function search(IUser $user, ISearchQuery $query): SearchResult
51
    {
52
        $datasets = $this->DBController->search($query->getTerm());
53
        $result = [];
54
55
        foreach ($datasets as $dataset) {
56
            $result[] = new SearchResultEntry(
57
                '',
58
                $this->l10n->t('Audio Player') . ' - ' . $dataset['name'],
59
                '',
60
                $this->urlGenerator->linkToRoute('audioplayer.page.index') . '#' . $dataset['id'],
61
                $this->urlGenerator->imagePath('audioplayer', 'app-dark.svg')
62
            );
63
        }
64
65
        return SearchResult::complete(
66
            $this->l10n->t('Audioplayer'),
67
            $result
68
        );
69
    }
70
71
    public function getName(): string
72
    {
73
        return $this->l10n->t('Audioplayer');
74
    }
75
76
    public function getOrder(string $route, array $routeParameters): int
77
    {
78
        return 10;
79
    }
80
}