4f03f686ec3eb4250cf422af5b83ff6cef3c93a6
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\data\user\follow\UserFollow;
4 use wcf\data\user\follow\UserFollowAction;
5 use wcf\data\user\UserProfile;
6 use wcf\system\request\LinkHandler;
7 use wcf\system\user\notification\object\IUserNotificationObject;
8 use wcf\system\user\notification\object\UserFollowUserNotificationObject;
9
10 /**
11 * Notification event for followers.
12 *
13 * @author Alexander Ebert
14 * @copyright 2001-2018 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\User\Notification\Event
17 *
18 * @method UserFollowUserNotificationObject getUserNotificationObject()
19 */
20 class UserFollowFollowingUserNotificationEvent extends AbstractUserNotificationEvent implements ITestableUserNotificationEvent {
21 use TTestableUserNotificationEvent;
22
23 /**
24 * @inheritDoc
25 */
26 protected $stackable = true;
27
28 /**
29 * @inheritDoc
30 */
31 public function getTitle() {
32 $count = count($this->getAuthors());
33 if ($count > 1) {
34 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.follow.title.stacked', ['count' => $count]);
35 }
36
37 return $this->getLanguage()->get('wcf.user.notification.follow.title');
38 }
39
40 /**
41 * @inheritDoc
42 */
43 public function getMessage() {
44 $authors = array_values($this->getAuthors());
45 $count = count($authors);
46
47 if ($count > 1) {
48 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.follow.message.stacked', [
49 'author' => $this->author,
50 'authors' => $authors,
51 'count' => $count,
52 'others' => $count - 1
53 ]);
54 }
55
56 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.follow.message', ['author' => $this->author]);
57 }
58
59 /**
60 * @inheritDoc
61 */
62 public function getEmailMessage($notificationType = 'instant') {
63 return [
64 'template' => 'email_notification_userFollowFollowing',
65 'application' => 'wcf'
66 ];
67 }
68
69 /**
70 * @inheritDoc
71 */
72 public function getLink() {
73 return LinkHandler::getInstance()->getLink('User', ['object' => $this->author]);
74 }
75
76 /**
77 * @inheritDoc
78 */
79 public function getEventHash() {
80 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->followUserID);
81 }
82
83 /**
84 * @inheritDoc
85 * @return UserFollowUserNotificationObject[]
86 * @since 3.1
87 */
88 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
89 $follow = UserFollow::getFollow($recipient->userID, $author->userID);
90 if (!$follow->followID) {
91 $follow = (new UserFollowAction([], 'create', [
92 'data' => [
93 'userID' => $recipient->userID,
94 'followUserID' => $author->userID,
95 'time' => TIME_NOW - 60 * 60
96 ]
97 ]))->executeAction()['returnValues'];
98 }
99
100 return [new UserFollowUserNotificationObject($follow)];
101 }
102
103 /**
104 * @inheritDoc
105 * @since 3.1
106 */
107 public static function getTestAdditionalData(IUserNotificationObject $object) {
108 /** @var UserFollowUserNotificationObject $object */
109
110 return [$object->followUserID];
111 }
112 }