|
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) { |
|
74
|
|
|
/** @var \OCA\AnnouncementCenter\Manager $manager */ |
|
75
|
|
|
$manager = $this->getContainer()->query('OCA\AnnouncementCenter\Manager'); |
|
76
|
|
|
try { |
|
77
|
|
|
$announcement = $manager->getAnnouncement((int) $name); |
|
78
|
|
|
} catch (\InvalidArgumentException $e) { |
|
79
|
|
|
return false; |
|
80
|
|
|
} |
|
81
|
|
|
return $announcement['comments'] !== false; |
|
82
|
|
|
}); |
|
83
|
3 |
|
}); |
|
84
|
3 |
|
} |
|
85
|
|
|
|
|
86
|
3 |
|
protected function registerNotificationNotifier() { |
|
87
|
|
|
$this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() { |
|
88
|
1 |
|
return $this->getContainer()->query('OCA\AnnouncementCenter\Notification\Notifier'); |
|
89
|
3 |
|
}, function() { |
|
90
|
1 |
|
$l = $this->getContainer()->getServer()->getL10NFactory()->get('announcementcenter'); |
|
91
|
|
|
return [ |
|
92
|
1 |
|
'id' => 'announcementcenter', |
|
93
|
1 |
|
'name' => $l->t('Announcements'), |
|
94
|
1 |
|
]; |
|
95
|
3 |
|
}); |
|
96
|
3 |
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|