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
;
94 $userIDs[] = $comment->userID
;
96 $comment = new StructuredComment($comment);
97 $comment->setIsDeletable($this->commentManager
->canDeleteComment($comment->getDecoratedObject()));
98 $comment->setIsEditable($this->commentManager
->canEditComment($comment->getDecoratedObject()));
102 // fetch last responses
103 if (!empty($responseIDs)) {
104 $responseList = new CommentResponseList();
105 $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array(array_keys($responseIDs)));
106 $responseList->readObjects();
108 foreach ($responseList as $response) {
109 $response = new StructuredCommentResponse($response);
110 $response->setIsDeletable($this->commentManager
->canDeleteResponse($response->getDecoratedObject()));
111 $response->setIsEditable($this->commentManager
->canEditResponse($response->getDecoratedObject()));
113 $commentID = $responseIDs[$response->responseID
];
114 $this->objects
[$commentID]->addResponse($response);
116 $userIDs[] = $response->userID
;
120 // fetch user data and avatars
121 if (!empty($userIDs)) {
122 $userIDs = array_unique($userIDs);
124 $users = UserProfile
::getUserProfiles($userIDs);
125 foreach ($this->objects
as $comment) {
126 if (isset($users[$comment->userID
])) {
127 $comment->setUserProfile($users[$comment->userID
]);
130 foreach ($comment as $response) {
131 if (isset($users[$response->userID
])) {
132 $response->setUserProfile($users[$response->userID
]);
140 * Fetches the like data.
144 public function getLikeData() {
145 if (empty($this->objectIDs
)) return array();
148 $commentObjectType = LikeHandler
::getInstance()->getObjectType('com.woltlab.wcf.comment');
149 LikeHandler
::getInstance()->loadLikeObjects($commentObjectType, $this->getObjectIDs());
150 $likeData['comment'] = LikeHandler
::getInstance()->getLikeObjects($commentObjectType);
152 if (!empty($this->responseIDs
)) {
153 $responseObjectType = LikeHandler
::getInstance()->getObjectType('com.woltlab.wcf.comment.response');
154 LikeHandler
::getInstance()->loadLikeObjects($responseObjectType, $this->responseIDs
);
155 $likeData['response'] = LikeHandler
::getInstance()->getLikeObjects($responseObjectType);
162 * Returns minimum comment time.
166 public function getMinCommentTime() {
167 return $this->minCommentTime
;