Completed
Push — master ( 4f34f2...9208b7 )
by Roeland
8s
created

Application   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 70.83%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 41
ccs 17
cts 24
cp 0.7083
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A register() 0 4 1
A registerNotificationNotifier() 0 11 1
A registerCommentsEntity() 0 14 2
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 OCA\AnnouncementCenter\Controller\PageController;
27
use OCA\AnnouncementCenter\Manager;
28
use OCA\AnnouncementCenter\Notification\Notifier;
29
use OCP\AppFramework\App;
30
use OCP\Comments\CommentsEntityEvent;
31
32
class Application extends App {
33
34 12
	public function __construct() {
35 12
		parent::__construct('announcementcenter');
36 12
		$container = $this->getContainer();
37
38 12
		$container->registerAlias('PageController', PageController::class);
39 12
	}
40
41 1
	public function register() {
42 1
		$this->registerNotificationNotifier();
43 1
		$this->registerCommentsEntity();
44 1
	}
45
46
	protected function registerCommentsEntity() {
47
		$this->getContainer()->getServer()->getEventDispatcher()->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) {
48
			$event->addEntityCollection('announcement', function($name) {
49
				/** @var Manager $manager */
50
				$manager = $this->getContainer()->query(Manager::class);
51
				try {
52
					$announcement = $manager->getAnnouncement((int) $name);
53
				} catch (\InvalidArgumentException $e) {
54
					return false;
55
				}
56
				return $announcement['comments'] !== false;
57
			});
58 1
		});
59 1
	}
60
61
	protected function registerNotificationNotifier() {
62 1
		$this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() {
63 1
			return $this->getContainer()->query(Notifier::class);
64
		}, function() {
65 1
			$l = $this->getContainer()->getServer()->getL10NFactory()->get('announcementcenter');
66
			return [
67 1
				'id' => 'announcementcenter',
68 1
				'name' => $l->t('Announcements'),
69
			];
70 1
		});
71
	}
72
}
73