2 namespace wcf\data\comment
;
3 use wcf\data\comment\response\CommentResponseList
;
4 use wcf\data\comment\response\StructuredCommentResponse
;
5 use wcf\data\user\UserProfile
;
6 use wcf\system\comment\manager\ICommentManager
;
7 use wcf\system\like\LikeHandler
;
10 * Provides a structured comment list fetching last responses for every comment.
12 * @author Alexander Ebert
13 * @copyright 2001-2014 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage data.comment
17 * @category Community Framework
19 class StructuredCommentList
extends CommentList
{
21 * comment manager object
22 * @var \wcf\system\comment\manager\ICommentManager
24 public $commentManager = null;
27 * minimum comment time
30 public $minCommentTime = 0;
36 public $objectTypeID = 0;
45 * ids of the responses of the comments in the list
48 public $responseIDs = array();
51 * @see \wcf\data\DatabaseObjectList::$sqlLimit
53 public $sqlLimit = 10;
56 * @see \wcf\data\DatabaseObjectList::$sqlOrderBy
58 public $sqlOrderBy = 'comment.time DESC';
61 * Creates a new structured comment list.
63 * @param \wcf\system\comment\manager\ICommentManager $commentManager
64 * @param integer $objectTypeID
65 * @param integer $objectID
67 public function __construct(ICommentManager
$commentManager, $objectTypeID, $objectID) {
68 parent
::__construct();
70 $this->commentManager
= $commentManager;
71 $this->objectTypeID
= $objectTypeID;
72 $this->objectID
= $objectID;
74 $this->getConditionBuilder()->add("comment.objectTypeID = ?", array($objectTypeID));
75 $this->getConditionBuilder()->add("comment.objectID = ?", array($objectID));
76 $this->sqlLimit
= $this->commentManager
->getCommentsPerPage();
80 * @see \wcf\data\DatabaseObjectList::readObjects()
82 public function readObjects() {
83 parent
::readObjects();
86 $responseIDs = $userIDs = array();
87 foreach ($this->objects
as &$comment) {
88 if (!$this->minCommentTime ||
$comment->time
< $this->minCommentTime
) $this->minCommentTime
= $comment->time
;
89 $commentResponseIDs = $comment->getResponseIDs();
90 foreach ($commentResponseIDs as $responseID) {
91 $this->responseIDs
[] = $responseID;
92 $responseIDs[$responseID] = $comment->commentID
;
95 if ($comment->userID
) {
96 $userIDs[] = $comment->userID
;
99 $comment = new StructuredComment($comment);
100 $comment->setIsDeletable($this->commentManager
->canDeleteComment($comment->getDecoratedObject()));
101 $comment->setIsEditable($this->commentManager
->canEditComment($comment->getDecoratedObject()));
105 // fetch last responses
106 if (!empty($responseIDs)) {
107 $responseList = new CommentResponseList();
108 $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array(array_keys($responseIDs)));
109 $responseList->readObjects();
111 foreach ($responseList as $response) {
112 $response = new StructuredCommentResponse($response);
113 $response->setIsDeletable($this->commentManager
->canDeleteResponse($response->getDecoratedObject()));
114 $response->setIsEditable($this->commentManager
->canEditResponse($response->getDecoratedObject()));
116 $commentID = $responseIDs[$response->responseID
];
117 $this->objects
[$commentID]->addResponse($response);
119 if ($response->userID
) {
120 $userIDs[] = $response->userID
;
125 // fetch user data and avatars
126 if (!empty($userIDs)) {
127 $userIDs = array_unique($userIDs);
129 $users = UserProfile
::getUserProfiles($userIDs);
130 foreach ($this->objects
as $comment) {
131 if ($comment->userID
&& isset($users[$comment->userID
])) {
132 $comment->setUserProfile($users[$comment->userID
]);
135 foreach ($comment as $response) {
136 if ($response->userID
&& isset($users[$response->userID
])) {
137 $response->setUserProfile($users[$response->userID
]);
145 * Fetches the like data.
149 public function getLikeData() {
150 if (empty($this->objectIDs
)) return array();
153 $commentObjectType = LikeHandler
::getInstance()->getObjectType('com.woltlab.wcf.comment');
154 LikeHandler
::getInstance()->loadLikeObjects($commentObjectType, $this->getObjectIDs());
155 $likeData['comment'] = LikeHandler
::getInstance()->getLikeObjects($commentObjectType);
157 if (!empty($this->responseIDs
)) {
158 $responseObjectType = LikeHandler
::getInstance()->getObjectType('com.woltlab.wcf.comment.response');
159 LikeHandler
::getInstance()->loadLikeObjects($responseObjectType, $this->responseIDs
);
160 $likeData['response'] = LikeHandler
::getInstance()->getLikeObjects($responseObjectType);
167 * Returns minimum comment time.
171 public function getMinCommentTime() {
172 return $this->minCommentTime
;