-
Notifications
You must be signed in to change notification settings - Fork 19
/
Application.php
106 lines (89 loc) · 2.86 KB
/
Application.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* Nextcloud - OpenProject
*
*
* @author Julien Veyssier <eneiluj@posteo.net>
* @copyright Julien Veyssier 2020
*/
namespace OCA\OpenProject\AppInfo;
use Closure;
use OCA\Files\Event\LoadSidebar;
use OCA\OpenProject\Listener\LoadSidebarScript;
use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\Notification\IManager as INotificationManager;
use OCA\OpenProject\Dashboard\OpenProjectWidget;
use OCA\OpenProject\Search\OpenProjectSearchProvider;
use OCA\OpenProject\Notification\Notifier;
/**
* Class Application
*
* @package OCA\OpenProject\AppInfo
*/
class Application extends App implements IBootstrap {
public const APP_ID = 'integration_openproject';
/**
* @var mixed
*/
private $config;
/**
* Constructor
*
* @param array<string> $urlParams
*/
public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
$container = $this->getContainer();
$this->config = $container->get(IConfig::class);
$manager = $container->get(INotificationManager::class);
$manager->registerNotifierService(Notifier::class);
}
public function register(IRegistrationContext $context): void {
$context->registerDashboardWidget(OpenProjectWidget::class);
$context->registerSearchProvider(OpenProjectSearchProvider::class);
// register sidebar tab
$context->registerEventListener(
LoadSidebar::class,
LoadSidebarScript::class
);
}
public function boot(IBootContext $context): void {
$context->injectFn(Closure::fromCallable([$this, 'registerNavigation']));
}
public function registerNavigation(IUserSession $userSession): void {
$user = $userSession->getUser();
if ($user !== null) {
$userId = $user->getUID();
$container = $this->getContainer();
if ($this->config->getUserValue($userId, self::APP_ID, 'navigation_enabled', '0') === '1') {
$openprojectUrl = $this->config->getUserValue($userId, self::APP_ID, 'url', '');
if ($openprojectUrl !== '') {
$container->get(INavigationManager::class)->add(function () use ($container, $openprojectUrl) {
$urlGenerator = $container->get(IURLGenerator::class);
$l10n = $container->get(IL10N::class);
return [
'id' => self::APP_ID,
'order' => 10,
// the route that will be shown on startup
'href' => $openprojectUrl,
// the icon that will be shown in the navigation
// this file needs to exist in img/
'icon' => $urlGenerator->imagePath(self::APP_ID, 'app.svg'),
// the title of your application. This will be used in the
// navigation or on the settings page of your app
'name' => $l10n->t('OpenProject'),
];
});
}
}
}
}
}