68b5eea6b457de1e5f14cbd7909a74f60e6dbfdc
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\data\user\User;
4 use wcf\system\comment\CommentDataHandler;
5 use wcf\system\request\LinkHandler;
6
7 /**
8 * User notification event for profile commment responses.
9 *
10 * @author Alexander Ebert
11 * @copyright 2001-2014 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package com.woltlab.wcf
14 * @subpackage system.user.notification.event
15 * @category Community Framework
16 */
17 class UserProfileCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent {
18 /**
19 * @see \wcf\system\user\notification\event\AbstractUserNotificationEvent::$stackable
20 */
21 protected $stackable = true;
22
23 /**
24 * @see \wcf\system\user\notification\event\AbstractUserNotificationEvent::prepare()
25 */
26 protected function prepare() {
27 CommentDataHandler::getInstance()->cacheCommentID($this->userNotificationObject->commentID);
28 CommentDataHandler::getInstance()->cacheUserID($this->additionalData['objectID']);
29 CommentDataHandler::getInstance()->cacheUserID($this->additionalData['userID']);
30 }
31
32 /**
33 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getTitle()
34 */
35 public function getTitle() {
36 $count = count($this->getAuthors());
37 if ($count > 1) {
38 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.title.stacked', array(
39 'count' => $count,
40 'timesTriggered' => $this->timesTriggered
41 ));
42 }
43
44 return $this->getLanguage()->get('wcf.user.notification.commentResponse.title');
45 }
46
47 /**
48 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getMessage()
49 */
50 public function getMessage() {
51 // @todo: use cache or a single query to retrieve required data
52 $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
53 $owner = CommentDataHandler::getInstance()->getUser($comment->objectID);
54 if ($comment->userID) {
55 $commentAuthor = CommentDataHandler::getInstance()->getUser($comment->userID);
56 }
57 else {
58 $commentAuthor = new User(null, array(
59 'username' => $comment->username
60 ));
61 }
62
63 $authors = array_values($this->getAuthors());
64 $count = count($authors);
65 if ($count > 1) {
66 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.message.stacked', array(
67 'authors' => $authors,
68 'count' => $count,
69 'others' => $count - 1,
70 'owner' => $owner
71 ));
72 }
73
74 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.message', array(
75 'author' => $this->author,
76 'owner' => $owner
77 ));
78 }
79
80 /**
81 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getEmailMessage()
82 */
83 public function getEmailMessage($notificationType = 'instant') {
84 $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
85 $user = new User($comment->objectID);
86
87 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.mail', array(
88 'response' => $this->userNotificationObject,
89 'author' => $this->author,
90 'owner' => $user,
91 'notificationType' => $notificationType
92 ));
93 }
94
95 /**
96 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getLink()
97 */
98 public function getLink() {
99 // @todo: use cache or a single query to retrieve required data
100 $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
101 $user = CommentDataHandler::getInstance()->getUser($comment->objectID);
102
103 return LinkHandler::getInstance()->getLink('User', array('object' => $user), '#wall');
104 }
105
106 /**
107 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getEventHash()
108 */
109 public function getEventHash() {
110 return sha1($this->eventID . '-' . $this->userNotificationObject->commentID);
111 }
112 }