-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnouncementMailFixPlugin.inc.php
103 lines (90 loc) · 3.05 KB
/
AnnouncementMailFixPlugin.inc.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
<?php
/**
* @file PluginTemplatePlugin.inc.php
*
* Copyright (c) 2017-2021 Simon Fraser University
* Copyright (c) 2017-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PluginTemplatePlugin
* @brief Plugin class for the PluginTemplate plugin.
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class AnnouncementMailFixPlugin extends GenericPlugin
{
/**
* @copydoc GenericPlugin::register()
*/
public function register($category, $path, $mainContextId = NULL)
{
$success = parent::register($category, $path);
HookRegistry::register('LoadHandler', [$this, 'setPageHandler']);
if ($success && $this->getEnabled()) {
// Display the publication statement on the article details page
HookRegistry::register('Announcement::add', [$this, 'announcementHooks']);
// HookRegistry::register('Announcement::edit', [$this, 'announcementHooks']);
}
return $success;
}
/**
* Provide a name for this plugin
*
* The name will appear in the Plugin Gallery where editors can
* install, enable and disable plugins.
*
* @return string
*/
public function getDisplayName()
{
return __('plugins.generic.announcementMailFix.displayName');
}
/**
* Provide a description for this plugin
*
* The description will appear in the Plugin Gallery where editors can
* install, enable and disable plugins.
*
* @return string
*/
public function getDescription()
{
return __('plugins.generic.announcementMailFix.description');
}
public function announcementHooks($hookName, $args)
{
if (!$this->getRequest()->getUserVar('sendEmail')) {
return false;
};
$announcement = &$args[0];
$this->sendAnnouncementMail($announcement);
return true;
}
private function sendAnnouncementMail($announcement)
{
import('lib.pkp.classes.notification.managerDelegate.AnnouncementNotificationManager');
$announcementNotificationManager = new AnnouncementNotificationManager(NOTIFICATION_TYPE_NEW_ANNOUNCEMENT);
$announcementNotificationManager->initialize($announcement);
$notificationSubscriptionSettingsDao = DAORegistry::getDAO('NotificationSubscriptionSettingsDAO'); /* @var $notificationSubscriptionSettingsDao NotificationSubscriptionSettingsDAO */
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
$allUsers = $userGroupDao->getUsersByContextId($this->getCurrentContextId());
while ($user = $allUsers->next()) {
if ($user->getDisabled()) continue;
$blockedEmails = $notificationSubscriptionSettingsDao->getNotificationSubscriptionSettings('blocked_emailed_notification', $user->getId(), $this->getCurrentContextId());
if (!in_array(NOTIFICATION_TYPE_NEW_ANNOUNCEMENT, $blockedEmails)) {
$announcementNotificationManager->notify($user);
}
}
}
public function setPageHandler($hookName, $params)
{
$page = $params[0];
switch ($page) {
case $this->getName():
define('HANDLER_CLASS', 'AnnouncementMailFixPageHandler');
$this->import('AnnouncementMailFixPageHandler');
return true;
break;
}
return false;
}
}