<event>
<name>like</name>
<objecttype>com.woltlab.wcf.user.profileComment.like.notification</objecttype>
- <classname><![CDATA[wcf\system\user\notification\event\UserProfileCommentUserNotificationEvent]]></classname>
+ <classname><![CDATA[wcf\system\user\notification\event\UserProfileCommentUserLikeNotificationEvent]]></classname>
<preset>1</preset>
</event>
<event>
<name>like</name>
<objecttype>com.woltlab.wcf.user.profileComment.response.like.notification</objecttype>
- <classname><![CDATA[wcf\system\user\notification\event\UserProfileCommentResponseUserNotificationEvent]]></classname>
+ <classname><![CDATA[wcf\system\user\notification\event\UserProfileCommentResponseLikeUserNotificationEvent]]></classname>
<preset>1</preset>
</event>
</import>
if ($userID != WCF::getUser()->userID) {
$notificationObject = new CommentUserNotificationObject($this->createdComment);
- UserNotificationHandler::getInstance()->fireEvent('comment', $objectType->objectType.'.notification', $notificationObject, array($userID));
+ UserNotificationHandler::getInstance()->fireEvent('comment', $objectType->objectType.'.notification', $notificationObject, array($userID), array(
+ 'objectUserID' => $userID
+ ));
}
}
// fire notification event
if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.notification')) {
+ $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType.'.notification');
+ $userID = $notificationObjectType->getOwnerID($this->comment->commentID);
+
$notificationObject = new CommentResponseUserNotificationObject($this->createdResponse);
if ($this->comment->userID != WCF::getUser()->userID) {
- UserNotificationHandler::getInstance()->fireEvent('commentResponse', $objectType->objectType.'.response.notification', $notificationObject, array($this->comment->userID));
+ UserNotificationHandler::getInstance()->fireEvent('commentResponse', $objectType->objectType.'.response.notification', $notificationObject, array($this->comment->userID), array(
+ 'commentID' => $this->comment->commentID,
+ 'objectID' => $this->comment->objectID,
+ 'objectUserID' => $userID,
+ 'userID' => $this->comment->userID
+ ));
}
// notify the container owner
if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.notification')) {
- $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType.'.notification');
- $userID = $notificationObjectType->getOwnerID($this->comment->commentID);
-
if ($userID != $this->comment->userID && $userID != WCF::getUser()->userID) {
- UserNotificationHandler::getInstance()->fireEvent('commentResponseOwner', $objectType->objectType.'.response.notification', $notificationObject, array($userID));
+ UserNotificationHandler::getInstance()->fireEvent('commentResponseOwner', $objectType->objectType.'.response.notification', $notificationObject, array($userID), array(
+ 'commentID' => $this->comment->commentID,
+ 'objectID' => $this->comment->objectID,
+ 'objectUserID' => $userID,
+ 'userID' => $this->comment->userID
+ ));
}
}
}
$notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType.'.like.notification');
if ($this->userID != WCF::getUser()->userID) {
$notificationObject = new CommentLikeUserNotificationObject($like);
- UserNotificationHandler::getInstance()->fireEvent('like', $objectType->objectType.'.like.notification', $notificationObject, array($this->userID), array('objectID' => $this->object->objectID));
+ UserNotificationHandler::getInstance()->fireEvent('like', $objectType->objectType.'.like.notification', $notificationObject, array($this->userID), array(
+ 'objectID' => $this->object->objectID,
+ 'objectOwnerID' => $this->userID
+ ));
}
}
}
UserNotificationHandler::getInstance()->fireEvent('like', $objectType->objectType.'.response.like.notification', $notificationObject, array($this->userID), array(
'commentID' => $comment->commentID,
'commentUserID' => $comment->userID,
- 'objectID' => $comment->objectID,
+ 'objectID' => $comment->objectID
));
}
}
--- /dev/null
+<?php
+namespace wcf\system\comment;
+use wcf\data\comment\CommentList;
+use wcf\data\user\UserProfile;
+use wcf\system\SingletonFactory;
+
+/**
+ * Handles common data resources for comment-related user notifications
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2014 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.comment
+ * @category Community Framework
+ */
+class CommentDataHandler extends SingletonFactory {
+ /**
+ * list of comment ids
+ * @var array<integer>
+ */
+ protected $commentIDs = array();
+
+ /**
+ * list of cached comment objects
+ * @var array<\wcf\data\comment\Comment>
+ */
+ protected $comments = array();
+
+ /**
+ * list of user ids
+ * @var array<integer>
+ */
+ protected $userIDs = array();
+
+ /**
+ * Caches a comment id.
+ *
+ * @param integer $commentID
+ */
+ public function cacheCommentID($commentID) {
+ if (!in_array($commentID, $this->commentIDs)) {
+ $this->commentIDs[] = $commentID;
+ }
+ }
+
+ /**
+ * Caches a user id.
+ *
+ * @param integer $userID
+ */
+ public function cacheUserID($userID) {
+ if (!in_array($userID, $this->userIDs)) {
+ $this->userIDs[] = $userID;
+ }
+ }
+
+ /**
+ * Returns a comment by id, fetches comments on first call.
+ *
+ * @param integer $commentID
+ * @return \wcf\data\comment\Comment
+ */
+ public function getComment($commentID) {
+ if (!empty($this->commentIDs)) {
+ $commentList = new CommentList();
+ $commentList->setObjectIDs($this->commentIDs);
+ $commentList->readObjects();
+ $this->comments = $commentList->getObjects();
+ $this->commentIDs = array();
+ }
+
+ if (isset($this->comments[$commentID])) {
+ return $this->comments[$commentID];
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns a user profile by id, fetches user profiles on first call.
+ *
+ * @param integer $userID
+ * @return \wcf\data\user\UserProfile
+ */
+ public function getUser($userID) {
+ if (!empty($this->userIDs)) {
+ UserProfile::getUserProfiles($this->userIDs);
+ $this->userIDs = array();
+ }
+
+ return UserProfile::getUserProfile($userID);
+ }
+}
$conditions->add("notification.userID = ?", array(WCF::getUser()->userID));
if (!$showConfirmedNotifications) $conditions->add("notification.confirmed = ?", array(0));
- $sql = "SELECT notification.notificationID, notification_event.eventID, notification.authorID,
- notification.timesTriggered, object_type.objectType, notification.objectID,
- notification.additionalData,
- notification.time".($showConfirmedNotifications ? ", notification.confirmed" : "")."
+ $sql = "SELECT notification.*, notification_event.eventID, object_type.objectType
FROM wcf".WCF_N."_user_notification notification
LEFT JOIN wcf".WCF_N."_user_notification_event notification_event
ON (notification_event.eventID = notification.eventID)
$statement = WCF::getDB()->prepareStatement($sql, $limit, $offset);
$statement->execute($conditions->getParameters());
- $authorIDs = $events = $objectTypes = $eventIDs = $notificationIDs = array();
+ $authorIDs = $objectTypes = $eventIDs = $notificationObjects = array();
while ($row = $statement->fetchArray()) {
- $events[] = $row;
-
// cache object types
if (!isset($objectTypes[$row['objectType']])) {
$objectTypes[$row['objectType']] = array(
$objectTypes[$row['objectType']]['objectIDs'][] = $row['objectID'];
$eventIDs[] = $row['eventID'];
- $notificationIDs[] = $row['notificationID'];
+
+ $notificationObjects[$row['notificationID']] = new UserNotification(null, $row);
}
// return an empty set if no notifications exist
- if (empty($events)) {
+ if (empty($notificationObjects)) {
return array(
'count' => 0,
'notifications' => array()
// load authors
$conditions = new PreparedStatementConditionBuilder();
- $conditions->add("notificationID IN (?)", array($notificationIDs));
+ $conditions->add("notificationID IN (?)", array(array_keys($notificationObjects)));
$sql = "SELECT notificationID, authorID
FROM wcf".WCF_N."_user_notification_author
".$conditions."
$eventList->readObjects();
$eventObjects = $eventList->getObjects();
- // load notification objects
- $notificationList = new UserNotificationList();
- $notificationList->getConditionBuilder()->add("user_notification.notificationID IN (?)", array($notificationIDs));
- $notificationList->readObjects();
- $notificationObjects = $notificationList->getObjects();
-
// build notification data
$notifications = array();
- foreach ($events as $event) {
- $className = $eventObjects[$event['eventID']]->className;
- $class = new $className($eventObjects[$event['eventID']]);
- $notificationID = $event['notificationID'];
-
+ foreach ($notificationObjects as $notification) {
+ $className = $eventObjects[$notification->eventID]->className;
+ $class = new $className($eventObjects[$notification->eventID]);
$class->setObject(
- $notificationObjects[$notificationID],
- $objectTypes[$event['objectType']]['objects'][$event['objectID']],
- (isset($authors[$event['authorID']]) ? $authors[$event['authorID']] : $unknownAuthor),
- unserialize($event['additionalData']),
- $event['timesTriggered']
+ $notification,
+ $objectTypes[$notification->objectType]['objects'][$notification->objectID],
+ (isset($authors[$notification->authorID]) ? $authors[$notification->authorID] : $unknownAuthor),
+ $notification->additionalData,
+ $notification->timesTriggered
);
- if (isset($authorToNotification[$notificationID])) {
+ if (isset($authorToNotification[$notification->notificationID])) {
$eventAuthors = array();
- foreach ($authorToNotification[$notificationID] as $userID) {
+ foreach ($authorToNotification[$notification->notificationID] as $userID) {
if (isset($authors[$userID])) {
$eventAuthors[$userID] = $authors[$userID];
}
$data = array(
'authors' => count($class->getAuthors()),
'event' => $class,
- 'notificationID' => $event['notificationID'],
- 'time' => $event['time']
+ 'notificationID' => $notification->notificationID,
+ 'time' => $notification->time
);
if ($showConfirmedNotifications) {
- $data['confirmed'] = $event['confirmed'];
+ $data['confirmed'] = $notification->confirmed;
}
$notifications[] = $data;
--- /dev/null
+<?php
+namespace wcf\system\user\notification\event;
+use wcf\data\user\notification\UserNotification;
+use wcf\data\user\UserProfile;
+use wcf\system\user\notification\object\IUserNotificationObject;
+
+/**
+ * Provides a default implementation for objects sharing common data.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2014 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.user.notification.event
+ * @category Community Framework
+ */
+abstract class AbstractSharedUserNotificationEvent extends AbstractUserNotificationEvent {
+ /**
+ * @see \wcf\system\user\notification\event\IUserNotificationEvent::setObject()
+ */
+ public function setObject(UserNotification $notification, IUserNotificationObject $object, UserProfile $author, array $additionalData = array(), $timesTriggered = 0) {
+ parent::setObject($notification, $object, $author, $additionalData, $timesTriggered);
+
+ $this->prepare();
+ }
+
+ /**
+ * Provide specialized handlers with object ids, these ids will be collected and should be
+ * read once the first time data is requested from the notification event.
+ */
+ abstract protected function prepare();
+}
use wcf\util\DateUtil;
/**
- * Provides default a implementation for user notification events.
+ * Provides a default implementation for user notification events.
*
* @author Marcel Werk, Oliver Kliebisch
* @copyright 2001-2014 WoltLab GmbH, Oliver Kliebisch
<?php
namespace wcf\system\user\notification\event;
use wcf\data\user\User;
+use wcf\system\comment\CommentDataHandler;
use wcf\system\request\LinkHandler;
-use wcf\system\user\notification\event\AbstractUserNotificationEvent;
use wcf\system\WCF;
/**
* @subpackage system.user.notification.event
* @category Community Framework
*/
-class UserProfileCommentLikeUserNotificationEvent extends AbstractUserNotificationEvent {
+class UserProfileCommentLikeUserNotificationEvent extends AbstractSharedUserNotificationEvent {
/**
* @see \wcf\system\user\notification\event\AbstractUserNotificationEvent::$stackable
*/
protected $stackable = true;
+ /**
+ * @see \wcf\system\user\notification\event\AbstractUserNotificationEvent::prepare()
+ */
+ protected function prepare() {
+ CommentDataHandler::getInstance()->cacheUserID($this->additionalData['objectID']);
+ }
+
/**
* @see \wcf\system\user\notification\event\IUserNotificationEvent::getTitle()
*/
$count = count($authors);
$owner = null;
if ($this->additionalData['objectID'] != WCF::getUser()->userID) {
- $owner = new User($this->additionalData['objectID']);
+ $owner = CommentDataHandler::getInstance()->getUser($this->additionalData['objectID']);
}
if ($count > 1) {
namespace wcf\system\user\notification\event;
use wcf\data\comment\Comment;
use wcf\data\user\User;
+use wcf\system\comment\CommentDataHandler;
use wcf\system\request\LinkHandler;
-use wcf\system\user\notification\event\AbstractUserNotificationEvent;
use wcf\system\WCF;
/**
* @subpackage system.user.notification.event
* @category Community Framework
*/
-class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractUserNotificationEvent {
+class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractSharedUserNotificationEvent {
/**
* @see \wcf\system\user\notification\event\AbstractUserNotificationEvent::$stackable
*/
protected $stackable = true;
+ /**
+ * @see \wcf\system\user\notification\event\AbstractUserNotificationEvent::prepare()
+ */
+ protected function prepare() {
+ CommentDataHandler::getInstance()->cacheCommentID($this->userNotificationObject->commentID);
+ }
+
/**
* @see \wcf\system\user\notification\event\IUserNotificationEvent::getTitle()
*/
<?php
namespace wcf\system\user\notification\event;
-use wcf\data\comment\Comment;
use wcf\data\user\User;
+use wcf\system\comment\CommentDataHandler;
use wcf\system\request\LinkHandler;
-use wcf\system\user\notification\event\AbstractUserNotificationEvent;
/**
* User notification event for profile commment responses.
* @subpackage system.user.notification.event
* @category Community Framework
*/
-class UserProfileCommentResponseUserNotificationEvent extends AbstractUserNotificationEvent {
+class UserProfileCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent {
/**
* @see \wcf\system\user\notification\event\AbstractUserNotificationEvent::$stackable
*/
protected $stackable = true;
+ /**
+ * @see \wcf\system\user\notification\event\AbstractUserNotificationEvent::prepare()
+ */
+ protected function prepare() {
+ CommentDataHandler::getInstance()->cacheCommentID($this->userNotificationObject->commentID);
+ CommentDataHandler::getInstance()->cacheUserID($this->additionalData['objectID']);
+ CommentDataHandler::getInstance()->cacheUserID($this->additionalData['userID']);
+ }
+
/**
* @see \wcf\system\user\notification\event\IUserNotificationEvent::getTitle()
*/
*/
public function getMessage() {
// @todo: use cache or a single query to retrieve required data
- $comment = new Comment($this->userNotificationObject->commentID);
- $owner = new User($comment->objectID);
+ $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
+ $owner = CommentDataHandler::getInstance()->getUser($comment->objectID);
if ($comment->userID) {
- $commentAuthor = new User($comment->userID);
+ $commentAuthor = CommentDataHandler::getInstance()->getUser($comment->userID);
}
else {
$commentAuthor = new User(null, array(
* @see \wcf\system\user\notification\event\IUserNotificationEvent::getEmailMessage()
*/
public function getEmailMessage($notificationType = 'instant') {
- $comment = new Comment($this->userNotificationObject->commentID);
+ $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
$user = new User($comment->objectID);
return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.mail', array(
*/
public function getLink() {
// @todo: use cache or a single query to retrieve required data
- $comment = new Comment($this->userNotificationObject->commentID);
- $user = new User($comment->objectID);
+ $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
+ $user = CommentDataHandler::getInstance()->getUser($comment->objectID);
return LinkHandler::getInstance()->getLink('User', array('object' => $user), '#wall');
}