1cac2542bc0ac62cb7dc5e7448417233539bfe20
[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\request\LinkHandler;
6 use wcf\system\user\notification\event\AbstractUserNotificationEvent;
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 AbstractUserNotificationEvent {
20 /**
21 * @see \wcf\system\user\notification\event\AbstractUserNotificationEvent::$stackable
22 */
23 protected $stackable = true;
24
25 /**
26 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getTitle()
27 */
28 public function getTitle() {
29 $count = count($this->getAuthors());
30 if ($count > 1) {
31 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.title.stacked', array(
32 'count' => $count,
33 'timesTriggered' => $this->timesTriggered
34 ));
35 }
36
37 return $this->getLanguage()->get('wcf.user.notification.commentResponseOwner.title');
38 }
39
40 /**
41 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getMessage()
42 */
43 public function getMessage() {
44 // @todo: use cache or a single query to retrieve required data
45 $comment = new Comment($this->userNotificationObject->commentID);
46 if ($comment->userID) {
47 $commentAuthor = new User($comment->userID);
48 }
49 else {
50 $commentAuthor = new User(null, array(
51 'username' => $comment->username
52 ));
53 }
54
55 $authors = array_values($this->getAuthors());
56 $count = count($authors);
57 if ($count > 1) {
58 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.message.stacked', array(
59 'author' => $commentAuthor,
60 'authors' => $authors,
61 'count' => $count,
62 'others' => max($count - 1, 0)
63 ));
64 }
65
66 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.message', array(
67 'author' => $this->author,
68 'commentAuthor' => $commentAuthor
69 ));
70 }
71
72 /**
73 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getEmailMessage()
74 */
75 public function getEmailMessage($notificationType = 'instant') {
76 $comment = new Comment($this->userNotificationObject->commentID);
77 $owner = new User($comment->objectID);
78 if ($comment->userID) {
79 $commentAuthor = new User($comment->userID);
80 }
81 else {
82 $commentAuthor = new User(null, array(
83 'username' => $comment->username
84 ));
85 }
86
87 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.mail', array(
88 'response' => $this->userNotificationObject,
89 'author' => $this->author,
90 'commentAuthor' => $commentAuthor,
91 'owner' => $owner,
92 'notificationType' => $notificationType
93 ));
94 }
95
96 /**
97 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getLink()
98 */
99 public function getLink() {
100 return LinkHandler::getInstance()->getLink('User', array('object' => WCF::getUser()), '#wall');
101 }
102
103 /**
104 * @see \wcf\system\user\notification\event\IUserNotificationEvent::getEventHash()
105 */
106 public function getEventHash() {
107 return sha1($this->eventID . '-' . $this->userNotificationObject->commentID);
108 }
109 }