2 namespace wcf\data\conversation
;
3 use wcf\data\conversation\label\ConversationLabel
;
4 use wcf\data\conversation\label\ConversationLabelList
;
5 use wcf\data\user\User
;
6 use wcf\data\user\UserProfile
;
7 use wcf\data\DatabaseObjectDecorator
;
8 use wcf\system\database\util\PreparedStatementConditionBuilder
;
12 * Represents a viewable conversation.
15 * @copyright 2001-2015 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package com.woltlab.wcf.conversation
18 * @subpackage data.conversation
19 * @category Community Framework
21 class ViewableConversation
extends DatabaseObjectDecorator
{
26 protected $__participantSummary = null;
30 * @var \wcf\data\user\UserProfile
32 protected $userProfile = null;
35 * last poster's profile
36 * @var \wcf\data\user\UserProfile
38 protected $lastPosterProfile = null;
41 * @see \wcf\data\DatabaseObjectDecorator::$baseClass
43 protected static $baseClass = 'wcf\data\conversation\Conversation';
46 * list of assigned labels
47 * @var array<\wcf\data\conversation\label\ConversationLabel>
49 protected $labels = array();
52 * Returns the user profile object.
54 * @return \wcf\data\user\UserProfile
56 public function getUserProfile() {
57 if ($this->userProfile
=== null) {
58 $this->userProfile
= new UserProfile(new User(null, $this->getDecoratedObject()->data
));
61 return $this->userProfile
;
65 * Returns the last poster's profile object.
67 * @return \wcf\data\user\UserProfile
69 public function getLastPosterProfile() {
70 if ($this->lastPosterProfile
=== null) {
71 if ($this->userID
&& $this->userID
== $this->lastPosterID
) {
72 $this->lastPosterProfile
= $this->getUserProfile();
75 $this->lastPosterProfile
= new UserProfile(new User(null, array(
76 'userID' => $this->lastPosterID
,
77 'username' => $this->lastPoster
,
78 'avatarID' => $this->lastPosterAvatarID
,
79 'avatarName' => $this->lastPosterAvatarName
,
80 'avatarExtension' => $this->lastPosterAvatarExtension
,
81 'width' => $this->lastPosterAvatarWidth
,
82 'height' => $this->lastPosterAvatarHeight
,
83 'email' => $this->lastPosterEmail
,
84 'disableAvatar' => $this->lastPosterDisableAvatar
,
85 'enableGravatar' => $this->lastPosterEnableGravatar
,
86 'gravatarFileExtension' => $this->lastPosterGravatarFileExtension
91 return $this->lastPosterProfile
;
95 * Returns the number of pages in this conversation.
99 public function getPages() {
100 if (WCF
::getUser()->conversationMessagesPerPage
) {
101 $messagesPerPage = WCF
::getUser()->conversationMessagesPerPage
;
104 $messagesPerPage = CONVERSATION_MESSAGES_PER_PAGE
;
107 return intval(ceil(($this->replies +
1) / $messagesPerPage));
111 * Returns a summary of the participants.
113 * @return array<\wcf\data\user\User>
115 public function getParticipantSummary() {
116 if ($this->__participantSummary
=== null) {
117 $this->__participantSummary
= array();
119 if ($this->participantSummary
) {
120 $data = unserialize($this->participantSummary
);
121 if ($data !== false) {
122 foreach ($data as $userData) {
123 $this->__participantSummary
[] = new User(null, array(
124 'userID' => $userData['userID'],
125 'username' => $userData['username'],
126 'hideConversation' => $userData['hideConversation']
133 return $this->__participantSummary
;
139 * @param \wcf\data\conversation\label\ConversationLabel $label
141 public function assignLabel(ConversationLabel
$label) {
142 $this->labels
[$label->labelID
] = $label;
146 * Returns a list of assigned labels.
148 * @return array<\wcf\data\conversation\label\ConversationLabel>
150 public function getAssignedLabels() {
151 return $this->labels
;
155 * Converts a conversation into a viewable conversation.
157 * @param \wcf\data\conversation\Conversation $conversation
158 * @param \wcf\data\conversation\label\ConversationLabelList $labelList
159 * @return \wcf\data\conversation\ViewableConversation
161 public static function getViewableConversation(Conversation
$conversation, ConversationLabelList
$labelList = null) {
162 $conversation = new ViewableConversation($conversation);
164 if ($labelList === null) {
165 $labelList = ConversationLabel
::getLabelsByUser();
168 $labels = $labelList->getObjects();
169 if (!empty($labels)) {
170 $conditions = new PreparedStatementConditionBuilder();
171 $conditions->add("conversationID = ?", array($conversation->conversationID
));
172 $conditions->add("labelID IN (?)", array(array_keys($labels)));
174 $sql = "SELECT labelID
175 FROM wcf".WCF_N
."_conversation_label_to_object
177 $statement = WCF
::getDB()->prepareStatement($sql);
178 $statement->execute($conditions->getParameters());
180 while ($row = $statement->fetchArray()) {
181 $conversation->assignLabel($labels[$row['labelID']]);
185 return $conversation;