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