From 40aa9168dd326eca7dd529d54561508bd3c37e2a Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Wed, 8 Jun 2016 00:39:18 +0200 Subject: [PATCH] add feed page for user notifications --- CHANGELOG.md | 1 + .../templates/notificationList.tpl | 8 +++ .../files/lib/page/AbstractFeedPage.class.php | 4 +- .../lib/page/NotificationFeedPage.class.php | 46 +++++++++++++ .../AbstractUserNotificationEvent.class.php | 64 ++++++++++++++++++- 5 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 wcfsetup/install/files/lib/page/NotificationFeedPage.class.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 89bf9d8872..47b30e04bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ * Overhauled language import form * Removed sitemap function/overlay * Added rebuild polls worker +* Added notification feed page #### CMS diff --git a/com.woltlab.wcf/templates/notificationList.tpl b/com.woltlab.wcf/templates/notificationList.tpl index e96652fcd3..666f018c2b 100644 --- a/com.woltlab.wcf/templates/notificationList.tpl +++ b/com.woltlab.wcf/templates/notificationList.tpl @@ -17,6 +17,14 @@ {/capture} +{capture assign='headContent'} + +{/capture} + +{capture assign='headerNavigation'} +
  • +{/capture} + {include file='userMenuSidebar'} {include file='header'} diff --git a/wcfsetup/install/files/lib/page/AbstractFeedPage.class.php b/wcfsetup/install/files/lib/page/AbstractFeedPage.class.php index 4574e54849..1d51822576 100644 --- a/wcfsetup/install/files/lib/page/AbstractFeedPage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractFeedPage.class.php @@ -37,8 +37,8 @@ abstract class AbstractFeedPage extends AbstractAuthedPage { public $objectIDs = []; /** - * list of feed-entries for the current page - * @var \wcf\data\DatabaseObjectList + * list of feed-entries for the current page object must be an \Iterator with \wcf\data\IFeedEntry-Elements + * @var \Iterator */ public $items = null; diff --git a/wcfsetup/install/files/lib/page/NotificationFeedPage.class.php b/wcfsetup/install/files/lib/page/NotificationFeedPage.class.php new file mode 100644 index 0000000000..c6ae8b7349 --- /dev/null +++ b/wcfsetup/install/files/lib/page/NotificationFeedPage.class.php @@ -0,0 +1,46 @@ + + * @package com.woltlab.wcf + * @subpackage page + * @category Community Framework + * @since 2.2 + */ +class NotificationFeedPage extends AbstractFeedPage { + /** + * @inheritDoc + */ + public function readParameters() { + parent::readParameters(); + + if (!WCF::getUser()->userID) { + throw new IllegalLinkException(); + } + + $this->title = WCF::getLanguage()->get('wcf.user.menu.community.notification'); + } + + /** + * @inheritDoc + */ + public function readData() { + parent::readData(); + + $this->items = new \ArrayIterator(); + + $notifications = UserNotificationHandler::getInstance()->getNotifications(20); + + foreach ($notifications['notifications'] as $notification) { + $this->items->append($notification['event']); + } + } +} diff --git a/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php index 36af722166..fa15b54852 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php @@ -5,14 +5,16 @@ use wcf\data\user\notification\event\UserNotificationEvent; use wcf\data\user\notification\UserNotification; use wcf\data\user\UserProfile; use wcf\data\DatabaseObjectDecorator; +use wcf\data\IFeedEntry; use wcf\system\user\notification\object\IUserNotificationObject; use wcf\system\WCF; use wcf\util\DateUtil; +use wcf\util\StringUtil; /** * Provides a default implementation for user notification events. * - * @author Marcel Werk, Oliver Kliebisch + * @author Joshua Ruesweg, Marcel Werk, Oliver Kliebisch * @copyright 2001-2016 WoltLab GmbH, Oliver Kliebisch * @license GNU Lesser General Public License * @package com.woltlab.wcf @@ -22,7 +24,7 @@ use wcf\util\DateUtil; * @method UserNotificationEvent getDecoratedObject() * @mixin UserNotificationEvent */ -abstract class AbstractUserNotificationEvent extends DatabaseObjectDecorator implements IUserNotificationEvent { +abstract class AbstractUserNotificationEvent extends DatabaseObjectDecorator implements IUserNotificationEvent, IFeedEntry { /** * @inheritDoc */ @@ -240,4 +242,62 @@ abstract class AbstractUserNotificationEvent extends DatabaseObjectDecorator imp public function getUserNotificationObject() { return $this->userNotificationObject; } + + /** + * @inheritdoc + */ + public function getComments() { + return 0; + } + + /** + * @inheritdoc + */ + public function getCategories() { + return [ + $this->notification->objectType + ]; + } + + /** + * @inheritdoc + */ + public function getExcerpt($maxLength = 255) { + return StringUtil::truncateHTML($this->getFormattedMessage(), $maxLength); + } + + /** + * @inheritdoc + */ + public function getFormattedMessage() { + return $this->getMessage(); + } + + /** + * @inheritdoc + */ + public function __toString() { + return $this->getFormattedMessage(); + } + + /** + * @inheritdoc + */ + public function getTime() { + return $this->getNotification()->time; + } + + /** + * @inheritdoc + */ + public function getUserID() { + return $this->getAuthorID(); + } + + /** + * @inheritdoc + */ + public function getUsername() { + return $this->getAuthor()->username; + } } -- 2.20.1