2 namespace wcf\system\user\activity\event;
3 use wcf\data\article\ViewableArticleList;
4 use wcf\data\comment\response\CommentResponseList;
5 use wcf\data\comment\CommentList;
6 use wcf\data\user\UserList;
7 use wcf\system\SingletonFactory;
11 * User activity event implementation for responses to article comments.
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\Activity\Event
19 class ArticleCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
23 public function prepare(array $events) {
25 foreach ($events as $event) {
26 $responseIDs[] = $event->objectID;
30 $responseList = new CommentResponseList();
31 $responseList->setObjectIDs($responseIDs);
32 $responseList->readObjects();
33 $responses = $responseList->getObjects();
36 $commentIDs = $comments = [];
37 foreach ($responses as $response) {
38 $commentIDs[] = $response->commentID;
40 if (!empty($commentIDs)) {
41 $commentList = new CommentList();
42 $commentList->setObjectIDs($commentIDs);
43 $commentList->readObjects();
44 $comments = $commentList->getObjects();
48 $articleContentIDs = [];
49 foreach ($comments as $comment) {
50 $articleContentIDs[] = $comment->objectID;
53 $articles = $articleContentToArticle = [];
54 if (!empty($articleContentIDs)) {
55 $articleList = new ViewableArticleList();
56 $articleList->getConditionBuilder()->add("article.articleID IN (SELECT articleID FROM wcf".WCF_N."_article_content WHERE articleContentID IN (?))", [$articleContentIDs]);
57 $articleList->readObjects();
58 foreach ($articleList as $article) {
59 $articles[$article->articleID] = $article;
61 $articleContentToArticle[$article->getArticleContent()->articleContentID] = $article->articleID;
66 $userIDs = $users = [];
67 foreach ($comments as $comment) {
68 $userIDs[] = $comment->userID;
70 if (!empty($userIDs)) {
71 $userList = new UserList();
72 $userList->setObjectIDs($userIDs);
73 $userList->readObjects();
74 $users = $userList->getObjects();
78 foreach ($events as $event) {
79 if (isset($responses[$event->objectID])) {
80 $response = $responses[$event->objectID];
81 $comment = $comments[$response->commentID];
82 if (isset($articleContentToArticle[$comment->objectID]) && isset($users[$comment->userID])) {
83 $article = $articles[$articleContentToArticle[$comment->objectID]];
86 if (!$article->canRead()) {
89 $event->setIsAccessible();
92 $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleCommentResponse', [
93 'commentAuthor' => $users[$comment->userID],
94 'commentID' => $comment->commentID,
95 'responseID' => $response->responseID,
98 $event->setTitle($text);
101 $event->setDescription($response->getExcerpt());
106 $event->setIsOrphaned();