first commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/notification/Notification.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class Notification
|
||||
*
|
||||
* @ingroup notification
|
||||
*
|
||||
* @see NotificationDAO
|
||||
*
|
||||
* @brief OJS subclass for Notifications (defines OJS-specific types).
|
||||
*/
|
||||
|
||||
namespace APP\notification;
|
||||
|
||||
use PKP\notification\PKPNotification;
|
||||
|
||||
class Notification extends PKPNotification
|
||||
{
|
||||
public const NOTIFICATION_TYPE_PUBLISHED_ISSUE = 0x10000015;
|
||||
|
||||
// OJS-specific trivial notifications
|
||||
public const NOTIFICATION_TYPE_BOOK_REQUESTED = 0x3000001;
|
||||
public const NOTIFICATION_TYPE_BOOK_CREATED = 0x3000002;
|
||||
public const NOTIFICATION_TYPE_BOOK_UPDATED = 0x3000003;
|
||||
public const NOTIFICATION_TYPE_BOOK_DELETED = 0x3000004;
|
||||
public const NOTIFICATION_TYPE_BOOK_MAILED = 0x3000005;
|
||||
public const NOTIFICATION_TYPE_BOOK_SETTINGS_SAVED = 0x3000006;
|
||||
public const NOTIFICATION_TYPE_BOOK_SUBMISSION_ASSIGNED = 0x3000007;
|
||||
public const NOTIFICATION_TYPE_BOOK_AUTHOR_ASSIGNED = 0x3000008;
|
||||
public const NOTIFICATION_TYPE_BOOK_AUTHOR_DENIED = 0x3000009;
|
||||
public const NOTIFICATION_TYPE_BOOK_AUTHOR_REMOVED = 0x300000A;
|
||||
public const NOTIFICATION_TYPE_OPEN_ACCESS = 0x300000B;
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\APP\notification\Notification', '\Notification');
|
||||
define('NOTIFICATION_TYPE_PUBLISHED_ISSUE', Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE);
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/notification/NotificationManager.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class NotificationManager
|
||||
*
|
||||
* @ingroup notification
|
||||
*
|
||||
* @see NotificationDAO
|
||||
* @see Notification
|
||||
*
|
||||
* @brief Class for Notification Manager.
|
||||
*/
|
||||
|
||||
namespace APP\notification;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\core\Request;
|
||||
use APP\facades\Repo;
|
||||
use APP\notification\managerDelegate\ApproveSubmissionNotificationManager;
|
||||
use PKP\notification\PKPNotificationManager;
|
||||
use PKP\plugins\Hook;
|
||||
|
||||
class NotificationManager extends PKPNotificationManager
|
||||
{
|
||||
/** @var array Cache each user's most privileged role for each submission */
|
||||
public $privilegedRoles;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a URL for the notification based on its type and associated object
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Notification $notification
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNotificationUrl($request, $notification)
|
||||
{
|
||||
$router = $request->getRouter();
|
||||
$dispatcher = $router->getDispatcher();
|
||||
$contextDao = Application::getContextDAO();
|
||||
$context = $contextDao->getById($notification->getContextId());
|
||||
|
||||
switch ($notification->getType()) {
|
||||
case Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE:
|
||||
return $dispatcher->url($request, Application::ROUTE_PAGE, $context->getPath(), 'issue', 'current');
|
||||
default:
|
||||
return parent::getNotificationUrl($request, $notification);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the contents for the notification based on its type and associated object
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Notification $notification
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNotificationMessage($request, $notification)
|
||||
{
|
||||
// Allow hooks to override default behavior
|
||||
$message = null;
|
||||
Hook::call('NotificationManager::getNotificationMessage', [&$notification, &$message]);
|
||||
if ($message) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
switch ($notification->getType()) {
|
||||
case Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE:
|
||||
return __('notification.type.issuePublished');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_REQUESTED:
|
||||
return __('plugins.generic.booksForReview.notification.bookRequested');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_CREATED:
|
||||
return __('plugins.generic.booksForReview.notification.bookCreated');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_UPDATED:
|
||||
return __('plugins.generic.booksForReview.notification.bookUpdated');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_DELETED:
|
||||
return __('plugins.generic.booksForReview.notification.bookDeleted');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_MAILED:
|
||||
return __('plugins.generic.booksForReview.notification.bookMailed');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_SETTINGS_SAVED:
|
||||
return __('plugins.generic.booksForReview.notification.settingsSaved');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_SUBMISSION_ASSIGNED:
|
||||
return __('plugins.generic.booksForReview.notification.submissionAssigned');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_AUTHOR_ASSIGNED:
|
||||
return __('plugins.generic.booksForReview.notification.authorAssigned');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_AUTHOR_DENIED:
|
||||
return __('plugins.generic.booksForReview.notification.authorDenied');
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_AUTHOR_REMOVED:
|
||||
return __('plugins.generic.booksForReview.notification.authorRemoved');
|
||||
default:
|
||||
return parent::getNotificationMessage($request, $notification);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get an article title from a notification's associated object
|
||||
*
|
||||
* @param Notification $notification
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function _getArticleTitle($notification)
|
||||
{
|
||||
assert($notification->getAssocType() == Application::ASSOC_TYPE_SUBMISSION);
|
||||
assert(is_numeric($notification->getAssocId()));
|
||||
$article = Repo::submission()->get($notification->getAssocId());
|
||||
if (!$article) {
|
||||
return null;
|
||||
}
|
||||
return $article->getLocalizedTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* get notification style class
|
||||
*
|
||||
* @param Notification $notification
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStyleClass($notification)
|
||||
{
|
||||
switch ($notification->getType()) {
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_REQUESTED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_CREATED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_UPDATED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_DELETED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_MAILED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_SETTINGS_SAVED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_SUBMISSION_ASSIGNED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_AUTHOR_ASSIGNED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_AUTHOR_DENIED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_AUTHOR_REMOVED:
|
||||
return 'notifySuccess';
|
||||
default: return parent::getStyleClass($notification);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a CSS class containing the icon of this notification type
|
||||
*
|
||||
* @param Notification $notification
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIconClass($notification)
|
||||
{
|
||||
switch ($notification->getType()) {
|
||||
case Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE:
|
||||
return 'notifyIconPublished';
|
||||
case Notification::NOTIFICATION_TYPE_NEW_ANNOUNCEMENT:
|
||||
return 'notifyIconNewAnnouncement';
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_REQUESTED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_CREATED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_UPDATED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_DELETED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_MAILED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_SETTINGS_SAVED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_SUBMISSION_ASSIGNED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_AUTHOR_ASSIGNED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_AUTHOR_DENIED:
|
||||
case Notification::NOTIFICATION_TYPE_BOOK_AUTHOR_REMOVED:
|
||||
return 'notifyIconSuccess';
|
||||
default: return parent::getIconClass($notification);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKPNotificationManager::getMgrDelegate()
|
||||
*/
|
||||
protected function getMgrDelegate($notificationType, $assocType, $assocId)
|
||||
{
|
||||
switch ($notificationType) {
|
||||
case Notification::NOTIFICATION_TYPE_APPROVE_SUBMISSION:
|
||||
case Notification::NOTIFICATION_TYPE_VISIT_CATALOG:
|
||||
assert($assocType == Application::ASSOC_TYPE_SUBMISSION && is_numeric($assocId));
|
||||
return new ApproveSubmissionNotificationManager($notificationType);
|
||||
}
|
||||
// Otherwise, fall back on parent class
|
||||
return parent::getMgrDelegate($notificationType, $assocType, $assocId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKPNotificationManager::getNotificationSettingsMap()
|
||||
*/
|
||||
public function getNotificationSettingsMap()
|
||||
{
|
||||
$settingsMap = parent::getNotificationSettingsMap();
|
||||
$settingsMap[Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE] = [
|
||||
'settingName' => 'notificationPublishedIssue',
|
||||
'emailSettingName' => 'emailNotificationPublishedIssue',
|
||||
'settingKey' => 'notification.type.issuePublished',
|
||||
];
|
||||
$settingsMap[Notification::NOTIFICATION_TYPE_OPEN_ACCESS] = [
|
||||
'settingName' => 'notificationOpenAccess',
|
||||
'emailSettingName' => 'emailNotificationOpenAccess',
|
||||
'settingKey' => 'notification.type.openAccess',
|
||||
];
|
||||
return $settingsMap;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\APP\notification\NotificationManager', '\NotificationManager');
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/notification/form/NotificationSettingsForm.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class NotificationSettingsForm
|
||||
*
|
||||
* @ingroup notification_form
|
||||
*
|
||||
* @brief Form to edit notification settings.
|
||||
*/
|
||||
|
||||
namespace APP\notification\form;
|
||||
|
||||
use APP\notification\Notification;
|
||||
use PKP\context\Context;
|
||||
use PKP\notification\form\PKPNotificationSettingsForm;
|
||||
|
||||
class NotificationSettingsForm extends PKPNotificationSettingsForm
|
||||
{
|
||||
/**
|
||||
* @copydoc PKPNotificationSettingsForm::getNotificationSettingsCategories()
|
||||
*/
|
||||
public function getNotificationSettingCategories(?Context $context = null)
|
||||
{
|
||||
$categories = parent::getNotificationSettingCategories($context);
|
||||
for ($i = 0; $i < count($categories); $i++) {
|
||||
if ($categories[$i]['categoryKey'] === 'notification.type.public') {
|
||||
$categories[$i]['settings'][] = Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE;
|
||||
$categories[$i]['settings'][] = Notification::NOTIFICATION_TYPE_OPEN_ACCESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $categories;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\APP\notification\form\NotificationSettingsForm', '\NotificationSettingsForm');
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/notification/managerDelegate/ApproveSubmissionNotificationManager.php
|
||||
*
|
||||
* Copyright (c) 2016-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class ApproveSubmissionNotificationManager
|
||||
*
|
||||
* @ingroup classes_notification_managerDelegate
|
||||
*
|
||||
* @brief Notification manager delegate that handles notifications related with
|
||||
* submission approval process.
|
||||
*/
|
||||
|
||||
namespace APP\notification\managerDelegate;
|
||||
|
||||
use PKP\notification\managerDelegate\PKPApproveSubmissionNotificationManager;
|
||||
use PKP\notification\PKPNotification;
|
||||
|
||||
class ApproveSubmissionNotificationManager extends PKPApproveSubmissionNotificationManager
|
||||
{
|
||||
/**
|
||||
* @copydoc PKPNotificationOperationManager::getNotificationTitle()
|
||||
*/
|
||||
public function getNotificationTitle($notification)
|
||||
{
|
||||
switch ($notification->getType()) {
|
||||
case PKPNotification::NOTIFICATION_TYPE_APPROVE_SUBMISSION:
|
||||
case PKPNotification::NOTIFICATION_TYPE_FORMAT_NEEDS_APPROVED_SUBMISSION:
|
||||
return __('notification.type.approveSubmissionTitle');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKPNotificationOperationManager::getNotificationMessage()
|
||||
*/
|
||||
public function getNotificationMessage($request, $notification)
|
||||
{
|
||||
switch ($notification->getType()) {
|
||||
case PKPNotification::NOTIFICATION_TYPE_FORMAT_NEEDS_APPROVED_SUBMISSION:
|
||||
return __('notification.type.formatNeedsApprovedSubmission');
|
||||
case PKPNotification::NOTIFICATION_TYPE_APPROVE_SUBMISSION:
|
||||
return __('notification.type.approveSubmission');
|
||||
}
|
||||
|
||||
return parent::getNotificationMessage($request, $notification);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\APP\notification\managerDelegate\ApproveSubmissionNotificationManager', '\ApproveSubmissionNotificationManager');
|
||||
}
|
||||
Reference in New Issue
Block a user