/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); // fetch response ids $responseIDs = $userIDs = array(); foreach ($this->objects as &$comment) { if (!$this->minCommentTime || $comment->time < $this->minCommentTime) { $this->minCommentTime = $comment->time; } $commentResponseIDs = $comment->getResponseIDs(); foreach ($commentResponseIDs as $responseID) { $this->responseIDs[] = $responseID; $responseIDs[$responseID] = $comment->commentID; } if ($comment->userID) { $userIDs[] = $comment->userID; } $comment = new StructuredComment($comment); $comment->setIsDeletable($this->commentManager->canDeleteComment($comment->getDecoratedObject())); $comment->setIsEditable($this->commentManager->canEditComment($comment->getDecoratedObject())); } unset($comment); // fetch last responses if (!empty($responseIDs)) { $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array(array_keys($responseIDs))); $responseList->readObjects(); foreach ($responseList as $response) { $response = new StructuredCommentResponse($response); $response->setIsDeletable($this->commentManager->canDeleteResponse($response->getDecoratedObject())); $response->setIsEditable($this->commentManager->canEditResponse($response->getDecoratedObject())); $commentID = $responseIDs[$response->responseID]; $this->objects[$commentID]->addResponse($response); if ($response->userID) { $userIDs[] = $response->userID; } } } // fetch user data and avatars if (!empty($userIDs)) { $userIDs = array_unique($userIDs); $users = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $comment) { if ($comment->userID && isset($users[$comment->userID])) { $comment->setUserProfile($users[$comment->userID]); } foreach ($comment as $response) { if ($response->userID && isset($users[$response->userID])) { $response->setUserProfile($users[$response->userID]); } } } } }
/** * Renders a comment. * * @param \wcf\data\comment\Comment $comment * @return string */ protected function renderComment(Comment $comment) { $comment = new StructuredComment($comment); $comment->setIsDeletable($this->commentProcessor->canDeleteComment($comment->getDecoratedObject())); $comment->setIsEditable($this->commentProcessor->canEditComment($comment->getDecoratedObject())); // set user profile if ($comment->userID) { $userProfile = UserProfile::getUserProfile($comment->userID); $comment->setUserProfile($userProfile); } WCF::getTPL()->assign(array('commentList' => array($comment), 'commentManager' => $this->commentProcessor)); return WCF::getTPL()->fetch('commentList'); }