Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / user / activity / event / TCommentResponseUserActivityEvent.class.php
1 <?php
2
3 namespace wcf\system\user\activity\event;
4
5 use wcf\data\comment\Comment;
6 use wcf\data\comment\response\CommentResponse;
7 use wcf\data\user\activity\event\ViewableUserActivityEvent;
8 use wcf\data\user\UserProfile;
9 use wcf\system\cache\runtime\CommentResponseRuntimeCache;
10 use wcf\system\cache\runtime\CommentRuntimeCache;
11 use wcf\system\cache\runtime\UserProfileRuntimeCache;
12
13 /**
14 * Provides a method to read the comment response, comment, and user objects related to comment
15 * response user activity events.
16 *
17 * @author Matthias Schmidt
18 * @copyright 2001-2020 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Core\System\User\Activity\Event
21 * @since 5.3
22 */
23 trait TCommentResponseUserActivityEvent
24 {
25 /**
26 * user objects for the comment authors
27 * @var UserProfile[]
28 */
29 protected $commentAuthors = [];
30
31 /**
32 * ids of the objects the comments belongs to
33 * @var int[]
34 */
35 protected $commentObjectIDs = [];
36
37 /**
38 * comment objects the responses belongs to
39 * @var Comment[]
40 */
41 protected $comments = [];
42
43 /**
44 * comment response the comment response user activity events belong to
45 * @var CommentResponse[]
46 */
47 protected $responses = [];
48
49 /**
50 * Reads the data of the comment responses the given events belong to.
51 *
52 * @param ViewableUserActivityEvent[] $events
53 */
54 protected function readResponseData(array $events)
55 {
56 $responseIDs = [];
57 foreach ($events as $event) {
58 $responseIDs[] = $event->objectID;
59 }
60
61 $this->responses = CommentResponseRuntimeCache::getInstance()->getObjects($responseIDs);
62
63 $commentIDs = [];
64 foreach ($this->responses as $response) {
65 $commentIDs[] = $response->commentID;
66 }
67
68 if (!empty($commentIDs)) {
69 $this->comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
70 }
71
72 $userIDs = [];
73 foreach ($this->comments as $comment) {
74 $userIDs[] = $comment->userID;
75 $this->commentObjectIDs[] = $comment->objectID;
76 }
77 if (!empty($userIDs)) {
78 $this->commentAuthors = UserProfileRuntimeCache::getInstance()->getObjects($userIDs);
79 }
80 }
81 }