<?php
namespace wcf\system\user\activity\event;
use wcf\data\article\ViewableArticleList;
-use wcf\data\comment\response\CommentResponseList;
-use wcf\data\comment\CommentList;
-use wcf\data\user\UserList;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
/**
* User activity event implementation for responses to article comments.
- *
+ *
* @author Marcel Werk
- * @copyright 2001-2019 WoltLab GmbH
+ * @copyright 2001-2020 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\System\User\Activity\Event
* @since 3.0
*/
class ArticleCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
+ use TCommentResponseUserActivityEvent;
+
/**
* @inheritDoc
*/
public function prepare(array $events) {
- $responseIDs = [];
- foreach ($events as $event) {
- $responseIDs[] = $event->objectID;
- }
-
- // fetch responses
- $responseList = new CommentResponseList();
- $responseList->setObjectIDs($responseIDs);
- $responseList->readObjects();
- $responses = $responseList->getObjects();
-
- // fetch comments
- $commentIDs = $comments = [];
- foreach ($responses as $response) {
- $commentIDs[] = $response->commentID;
- }
- if (!empty($commentIDs)) {
- $commentList = new CommentList();
- $commentList->setObjectIDs($commentIDs);
- $commentList->readObjects();
- $comments = $commentList->getObjects();
- }
+ $this->readResponseData($events);
// fetch articles
- $articleContentIDs = [];
- foreach ($comments as $comment) {
- $articleContentIDs[] = $comment->objectID;
- }
-
$articles = $articleContentToArticle = [];
- if (!empty($articleContentIDs)) {
+ if (!empty($this->commentObjectIDs)) {
$articleList = new ViewableArticleList();
- $articleList->getConditionBuilder()->add("article.articleID IN (SELECT articleID FROM wcf".WCF_N."_article_content WHERE articleContentID IN (?))", [$articleContentIDs]);
+ $articleList->getConditionBuilder()->add("article.articleID IN (SELECT articleID FROM wcf".WCF_N."_article_content WHERE articleContentID IN (?))", [$this->commentObjectIDs]);
$articleList->readObjects();
foreach ($articleList as $article) {
$articles[$article->articleID] = $article;
}
}
- // fetch users
- $userIDs = $users = [];
- foreach ($comments as $comment) {
- $userIDs[] = $comment->userID;
- }
- if (!empty($userIDs)) {
- $userList = new UserList();
- $userList->setObjectIDs($userIDs);
- $userList->readObjects();
- $users = $userList->getObjects();
- }
-
// set message
foreach ($events as $event) {
- if (isset($responses[$event->objectID])) {
- $response = $responses[$event->objectID];
- $comment = $comments[$response->commentID];
- if (isset($articleContentToArticle[$comment->objectID]) && isset($users[$comment->userID])) {
+ if (isset($this->responses[$event->objectID])) {
+ $response = $this->responses[$event->objectID];
+ $comment = $this->comments[$response->commentID];
+ if (isset($articleContentToArticle[$comment->objectID]) && isset($this->commentAuthors[$comment->userID])) {
$article = $articles[$articleContentToArticle[$comment->objectID]];
// check permissions
// title
$text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleCommentResponse', [
- 'commentAuthor' => $users[$comment->userID],
+ 'commentAuthor' => $this->commentAuthors[$comment->userID],
'commentID' => $comment->commentID,
'responseID' => $response->responseID,
- 'article' => $article
+ 'article' => $article,
]);
$event->setTitle($text);
<?php
namespace wcf\system\user\activity\event;
-use wcf\data\comment\response\CommentResponseList;
-use wcf\data\comment\CommentList;
use wcf\data\page\PageCache;
-use wcf\data\user\UserList;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
/**
* User activity event implementation for responses to page comments.
- *
+ *
* @author Joshua Ruesweg
- * @copyright 2001-2019 WoltLab GmbH
+ * @copyright 2001-2020 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\System\User\Activity\Event
* @since 5.2
*/
class PageCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
+ use TCommentResponseUserActivityEvent;
+
/**
* @inheritDoc
*/
public function prepare(array $events) {
- $responseIDs = [];
- foreach ($events as $event) {
- $responseIDs[] = $event->objectID;
- }
-
- // fetch responses
- $responseList = new CommentResponseList();
- $responseList->setObjectIDs($responseIDs);
- $responseList->readObjects();
- $responses = $responseList->getObjects();
-
- // fetch comments
- $commentIDs = $comments = [];
- foreach ($responses as $response) {
- $commentIDs[] = $response->commentID;
- }
-
- if (!empty($commentIDs)) {
- $commentList = new CommentList();
- $commentList->setObjectIDs($commentIDs);
- $commentList->readObjects();
- $comments = $commentList->getObjects();
- }
-
- // fetch users
- $userIDs = $users = [];
- foreach ($comments as $comment) {
- $userIDs[] = $comment->userID;
- }
-
- if (!empty($userIDs)) {
- $userList = new UserList();
- $userList->setObjectIDs($userIDs);
- $userList->readObjects();
- $users = $userList->getObjects();
- }
+ $this->readResponseData($events);
// set message
foreach ($events as $event) {
- if (isset($responses[$event->objectID])) {
- $response = $responses[$event->objectID];
- $comment = $comments[$response->commentID];
- if (PageCache::getInstance()->getPage($comment->objectID) && isset($users[$comment->userID])) {
+ if (isset($this->responses[$event->objectID])) {
+ $response = $this->responses[$event->objectID];
+ $comment = $this->comments[$response->commentID];
+ if (PageCache::getInstance()->getPage($comment->objectID) && isset($this->commentAuthors[$comment->userID])) {
$page = PageCache::getInstance()->getPage($comment->objectID);
// check permissions
// title
$text = WCF::getLanguage()->getDynamicVariable('wcf.page.recentActivity.pageCommentResponse', [
- 'commentAuthor' => $users[$comment->userID],
+ 'commentAuthor' => $this->commentAuthors[$comment->userID],
'commentID' => $comment->commentID,
'responseID' => $response->responseID,
- 'page' => $page
+ 'page' => $page,
]);
$event->setTitle($text);
<?php
namespace wcf\system\user\activity\event;
-use wcf\data\comment\response\CommentResponseList;
-use wcf\data\comment\CommentList;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
* User activity event implementation for profile comment responses.
*
* @author Marcel Werk
- * @copyright 2001-2019 WoltLab GmbH
+ * @copyright 2001-2020 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\System\User\Activity\Event
*/
class ProfileCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
+ use TCommentResponseUserActivityEvent;
+
/**
* @inheritDoc
*/
return;
}
- $responseIDs = [];
- foreach ($events as $event) {
- $responseIDs[] = $event->objectID;
- }
-
- // fetch responses
- $responseList = new CommentResponseList();
- $responseList->setObjectIDs($responseIDs);
- $responseList->readObjects();
- $responses = $responseList->getObjects();
-
- // fetch comments
- $commentIDs = $comments = [];
- foreach ($responses as $response) {
- $commentIDs[] = $response->commentID;
- }
- if (!empty($commentIDs)) {
- $commentList = new CommentList();
- $commentList->setObjectIDs($commentIDs);
- $commentList->readObjects();
- $comments = $commentList->getObjects();
- }
+ $this->readResponseData($events);
// fetch users
$userIDs = $users = [];
- foreach ($comments as $comment) {
+ foreach ($this->comments as $comment) {
$userIDs[] = $comment->objectID;
- $userIDs[] = $comment->userID;
}
if (!empty($userIDs)) {
$users = UserProfileRuntimeCache::getInstance()->getObjects($userIDs);
// set message
foreach ($events as $event) {
- if (isset($responses[$event->objectID])) {
- $response = $responses[$event->objectID];
- $comment = $comments[$response->commentID];
- if (isset($users[$comment->objectID]) && isset($users[$comment->userID])) {
+ if (isset($this->responses[$event->objectID])) {
+ $response = $this->responses[$event->objectID];
+ $comment = $this->comments[$response->commentID];
+ if (isset($users[$comment->objectID]) && isset($this->commentAuthors[$comment->userID])) {
if (!$users[$comment->objectID]->isProtected()) {
$event->setIsAccessible();
// title
$text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', [
- 'commentAuthor' => $users[$comment->userID],
+ 'commentAuthor' => $this->commentAuthors[$comment->userID],
'commentID' => $comment->commentID,
'responseID' => $response->responseID,
- 'user' => $users[$comment->objectID]
+ 'user' => $users[$comment->objectID],
]);
$event->setTitle($text);
--- /dev/null
+<?php
+namespace wcf\system\user\activity\event;
+use wcf\data\comment\Comment;
+use wcf\data\comment\response\CommentResponse;
+use wcf\data\user\activity\event\ViewableUserActivityEvent;
+use wcf\data\user\User;
+use wcf\system\cache\runtime\CommentResponseRuntimeCache;
+use wcf\system\cache\runtime\CommentRuntimeCache;
+use wcf\system\cache\runtime\UserRuntimeCache;
+
+/**
+ * Provides a method to read the comment response, comment, and user objects related to comment
+ * response user activity events.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\User\Activity\Event
+ * @since 5.3
+ */
+trait TCommentResponseUserActivityEvent {
+ /**
+ * user objects for the comment authors
+ * @var User[]
+ */
+ protected $commentAuthors = [];
+
+ /**
+ * ids of the objects the comments belongs to
+ * @var int[]
+ */
+ protected $commentObjectIDs = [];
+
+ /**
+ * comment objects the responses belongs to
+ * @var Comment[]
+ */
+ protected $comments = [];
+
+ /**
+ * comment response the comment response user activity events belong to
+ * @var CommentResponse[]
+ */
+ protected $responses = [];
+
+ /**
+ * Reads the data of the comment responses the given events belong to.
+ *
+ * @param ViewableUserActivityEvent[] $events
+ */
+ protected function readResponseData(array $events) {
+ $responseIDs = [];
+ foreach ($events as $event) {
+ $responseIDs[] = $event->objectID;
+ }
+
+ $this->responses = CommentResponseRuntimeCache::getInstance()->getObjects($responseIDs);
+
+ $commentIDs = [];
+ foreach ($this->responses as $response) {
+ $commentIDs[] = $response->commentID;
+ }
+
+ if (!empty($commentIDs)) {
+ $this->comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
+ }
+
+ $userIDs = [];
+ foreach ($this->comments as $comment) {
+ $userIDs[] = $comment->userID;
+ $this->commentObjectIDs[] = $comment->objectID;
+ }
+ if (!empty($userIDs)) {
+ $this->commentAuthors = UserRuntimeCache::getInstance()->getObjects($userIDs);
+ }
+ }
+}