bc71620804f5b40902ca25bfe164e9db1c4f1c04
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\system\user\activity\event;
4
5 use wcf\data\article\ViewableArticleList;
6 use wcf\system\SingletonFactory;
7 use wcf\system\WCF;
8
9 /**
10 * User activity event implementation for responses to article comments.
11 *
12 * @author Marcel Werk
13 * @copyright 2001-2020 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\User\Activity\Event
16 * @since 3.0
17 */
18 class ArticleCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent
19 {
20 use TCommentResponseUserActivityEvent;
21
22 /**
23 * @inheritDoc
24 */
25 public function prepare(array $events)
26 {
27 $this->readResponseData($events);
28
29 // fetch articles
30 $articles = $articleContentToArticle = [];
31 if (!empty($this->commentObjectIDs)) {
32 $articleList = new ViewableArticleList();
33 $articleList->getConditionBuilder()->add(
34 "article.articleID IN (SELECT articleID FROM wcf" . WCF_N . "_article_content WHERE articleContentID IN (?))",
35 [$this->commentObjectIDs]
36 );
37 $articleList->readObjects();
38 foreach ($articleList as $article) {
39 $articles[$article->articleID] = $article;
40
41 $articleContentToArticle[$article->getArticleContent()->articleContentID] = $article->articleID;
42 }
43 }
44
45 // set message
46 foreach ($events as $event) {
47 if (isset($this->responses[$event->objectID])) {
48 $response = $this->responses[$event->objectID];
49 $comment = $this->comments[$response->commentID];
50 if (
51 isset($articleContentToArticle[$comment->objectID])
52 && isset($this->commentAuthors[$comment->userID])
53 ) {
54 $article = $articles[$articleContentToArticle[$comment->objectID]];
55
56 // check permissions
57 if (!$article->canRead()) {
58 continue;
59 }
60 $event->setIsAccessible();
61
62 // title
63 $text = WCF::getLanguage()->getDynamicVariable(
64 'wcf.article.recentActivity.articleCommentResponse',
65 [
66 'commentAuthor' => $this->commentAuthors[$comment->userID],
67 'commentID' => $comment->commentID,
68 'responseID' => $response->responseID,
69 'article' => $article,
70 ]
71 );
72 $event->setTitle($text);
73
74 // description
75 $event->setDescription($response->getExcerpt());
76 continue;
77 }
78 }
79
80 $event->setIsOrphaned();
81 }
82 }
83 }