Completed
Pull Request — master (#12)
by Joas
08:14
created

Application   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 95.56%

Importance

Changes 10
Bugs 1 Features 3
Metric Value
wmc 7
c 10
b 1
f 3
lcom 1
cbo 0
dl 0
loc 63
ccs 43
cts 45
cp 0.9556
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A registerNavigationEntry() 0 15 1
A __construct() 0 6 1
A register() 0 7 1
A registerAdminPanel() 0 3 1
A registerActivityExtension() 0 5 1
A registerCommentsEntity() 0 8 1
A registerNotificationNotifier() 0 11 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, Joas Schilling <[email protected]>
4
 *
5
 * @author Joas Schilling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\AnnouncementCenter\AppInfo;
25
26
use OCP\AppFramework\App;
27
use OCP\Comments\CommentsEntityEvent;
28
29
class Application extends App {
30 5
	public function __construct (array $urlParams = array()) {
31 5
		parent::__construct('announcementcenter', $urlParams);
32 5
		$container = $this->getContainer();
33
34 5
		$container->registerAlias('PageController', 'OCA\AnnouncementCenter\Controller\PageController');
35 5
	}
36
37 3
	public function register() {
38 3
		$this->registerNavigationEntry();
39 3
		$this->registerAdminPanel();
40 3
		$this->registerActivityExtension();
41 3
		$this->registerNotificationNotifier();
42 3
		$this->registerCommentsEntity();
43 3
	}
44
45 3
	protected function registerNavigationEntry() {
46 3
		$server = $this->getContainer()->getServer();
47
48
		$server->getNavigationManager()->add(function() use ($server) {
49 1
			$urlGenerator = $server->getURLGenerator();
50 1
			$l = $server->getL10NFactory()->get('announcementcenter');
51
			return [
52 1
				'id' => 'announcementcenter',
53 1
				'order' => 10,
54 1
				'href' => $urlGenerator->linkToRoute('announcementcenter.page.index'),
55 1
				'icon' => $urlGenerator->imagePath('announcementcenter', 'announcementcenter.svg'),
56 1
				'name' => $l->t('Announcements'),
57 1
			];
58 3
		});
59 3
	}
60
61 3
	protected function registerAdminPanel() {
62 3
		\OCP\App::registerAdmin('announcementcenter', 'settings/admin');
63 3
	}
64
65 3
	protected function registerActivityExtension() {
66
		$this->getContainer()->getServer()->getActivityManager()->registerExtension(function() {
67 1
			return $this->getContainer()->query('OCA\AnnouncementCenter\Activity\Extension');
68 3
		});
69 3
	}
70
71 3
	protected function registerCommentsEntity() {
72
		$this->getContainer()->getServer()->getEventDispatcher()->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) {
73
			$event->addEntityCollection('announcement', function($name) {
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
				// TODO check for existance with the manager
75
				return true;
76
			});
77 3
		});
78 3
	}
79
80 3
	protected function registerNotificationNotifier() {
81
		$this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() {
82 1
			return $this->getContainer()->query('OCA\AnnouncementCenter\Notification\Notifier');
83 3
		}, function() {
84 1
			$l = $this->getContainer()->getServer()->getL10NFactory()->get('announcementcenter');
85
			return [
86 1
				'id' => 'announcementcenter',
87 1
				'name' => $l->t('Announcements'),
88 1
			];
89 3
		});
90 3
	}
91
}
92