namespace wcf\data\conversation;
use wcf\data\conversation\label\ConversationLabel;
use wcf\data\conversation\label\ConversationLabelList;
+use wcf\data\user\UserProfileCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\WCF;
if (!empty($this->sqlSelects)) $this->sqlSelects .= ',';
$this->sqlSelects .= "conversation_to_user.*";
$this->sqlJoins .= "LEFT JOIN wcf".WCF_N."_conversation_to_user conversation_to_user ON (conversation_to_user.participantID = ".$userID." AND conversation_to_user.conversationID = conversation.conversationID)";
-
- // get avatars
- if (!empty($this->sqlSelects)) $this->sqlSelects .= ',';
- $this->sqlSelects .= "user_avatar.*, user_table.email, user_table.disableAvatar, user_table.enableGravatar, user_table.gravatarFileExtension";
- $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = conversation.userID)";
- $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_avatar user_avatar ON (user_avatar.avatarID = user_table.avatarID)";
-
- if (!empty($this->sqlSelects)) $this->sqlSelects .= ',';
- $this->sqlSelects .= "lastposter_avatar.avatarID AS lastPosterAvatarID, lastposter_avatar.avatarName AS lastPosterAvatarName, lastposter_avatar.avatarExtension AS lastPosterAvatarExtension, lastposter_avatar.width AS lastPosterAvatarWidth, lastposter_avatar.height AS lastPosterAvatarHeight,";
- $this->sqlSelects .= "lastposter.email AS lastPosterEmail, lastposter.disableAvatar AS lastPosterDisableAvatar, lastposter.enableGravatar AS lastPosterEnableGravatar, lastposter.gravatarFileExtension AS lastPosterGravatarFileExtension";
- $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user lastposter ON (lastposter.userID = conversation.lastPosterID)";
- $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_avatar lastposter_avatar ON (lastposter_avatar.avatarID = lastposter.avatarID)";
}
/**
if (!empty($this->objects)) {
$labels = $this->loadLabelAssignments();
+ $userIDs = [ ];
foreach ($this->objects as $conversationID => $conversation) {
if (isset($labels[$conversationID])) {
foreach ($labels[$conversationID] as $label) {
$conversation->assignLabel($label);
}
}
+
+ if ($conversation->userID) {
+ $userIDs[] = $conversation->userID;
+ }
+ if ($conversation->lastPosterID) {
+ $userIDs[] = $conversation->lastPosterID;
+ }
+ }
+
+ if (!empty($userIDs)) {
+ UserProfileCache::getInstance()->cacheUserIDs($userIDs);
}
}
}
use wcf\data\conversation\label\ConversationLabelList;
use wcf\data\user\User;
use wcf\data\user\UserProfile;
+use wcf\data\user\UserProfileCache;
use wcf\data\DatabaseObjectDecorator;
+use wcf\data\TLegacyUserPropertyAccess;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\WCF;
* @category Community Framework
*/
class ViewableConversation extends DatabaseObjectDecorator {
+ use TLegacyUserPropertyAccess;
+
/**
* participant summary
* @var string
*/
protected $lastPosterProfile = null;
+ /**
+ * list of assigned labels
+ * @var array<\wcf\data\conversation\label\ConversationLabel>
+ */
+ protected $labels = array();
+
/**
* @see \wcf\data\DatabaseObjectDecorator::$baseClass
*/
protected static $baseClass = 'wcf\data\conversation\Conversation';
/**
- * list of assigned labels
- * @var array<\wcf\data\conversation\label\ConversationLabel>
+ * maps legacy direct access to last poster's user profile data to the real
+ * user profile property names
+ * @var array<string>
+ * @deprecated
*/
- protected $labels = array();
+ protected static $__lastUserAvatarPropertyMapping = array(
+ 'lastPosterAvatarID' => 'avatarID',
+ 'lastPosterAvatarName' => 'avatarName',
+ 'lastPosterAvatarExtension' => 'avatarExtension',
+ 'lastPosterAvatarWidth' => 'width',
+ 'lastPosterAvatarHeight' => 'height',
+ 'lastPosterEmail' => 'email',
+ 'lastPosterDisableAvatar' => 'disableAvatar',
+ 'lastPosterEnableGravatar' => 'enableGravatar',
+ 'lastPosterGravatarFileExtension' => 'gravatarFileExtension',
+ 'lastPosterAvatarFileHash' => 'fileHash'
+ );
+
+ /**
+ * @see \wcf\data\IStorableObject::__get()
+ * @deprecated
+ */
+ public function __get($name) {
+ $value = parent::__get($name);
+ if ($value !== null) {
+ return $value;
+ }
+ else if (array_key_exists($name, $this->object->data)) {
+ return null;
+ }
+
+ $value = $this->getUserProfile()->$name;
+ if ($value !== null) {
+ return $value;
+ }
+
+ if (isset(static::$__lastUserAvatarPropertyMapping[$name])) {
+ return $this->getLastPosterProfile()->getAvatar()->{static::$__lastUserAvatarPropertyMapping[$name]};
+ }
+
+ return null;
+ }
/**
* Returns the user profile object.
*/
public function getUserProfile() {
if ($this->userProfile === null) {
- $this->userProfile = new UserProfile(new User(null, $this->getDecoratedObject()->data));
+ if ($this->userID) {
+ $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->userID);
+ }
+ else {
+ $this->userProfile = new UserProfile(new User(null, array(
+ 'username' => $this->username
+ )));
+ }
}
return $this->userProfile;
*/
public function getLastPosterProfile() {
if ($this->lastPosterProfile === null) {
- if ($this->userID && $this->userID == $this->lastPosterID) {
- $this->lastPosterProfile = $this->getUserProfile();
+ if ($this->lastPosterID) {
+ $this->lastPosterProfile = UserProfileCache::getInstance()->getUserProfile($this->lastPosterID);
}
else {
$this->lastPosterProfile = new UserProfile(new User(null, array(
- 'userID' => $this->lastPosterID,
- 'username' => $this->lastPoster,
- 'avatarID' => $this->lastPosterAvatarID,
- 'avatarName' => $this->lastPosterAvatarName,
- 'avatarExtension' => $this->lastPosterAvatarExtension,
- 'width' => $this->lastPosterAvatarWidth,
- 'height' => $this->lastPosterAvatarHeight,
- 'email' => $this->lastPosterEmail,
- 'disableAvatar' => $this->lastPosterDisableAvatar,
- 'enableGravatar' => $this->lastPosterEnableGravatar,
- 'gravatarFileExtension' => $this->lastPosterGravatarFileExtension
+ 'username' => $this->lastPoster
)));
}
}
namespace wcf\data\conversation\message;
use wcf\data\user\User;
use wcf\data\user\UserProfile;
+use wcf\data\user\UserProfileCache;
use wcf\data\DatabaseObjectDecorator;
+use wcf\data\TLegacyUserPropertyAccess;
/**
* Represents a viewable conversation message.
* @category Community Framework
*/
class ViewableConversationMessage extends DatabaseObjectDecorator {
+ use TLegacyUserPropertyAccess;
+
/**
* @see \wcf\data\DatabaseObjectDecorator::$baseClass
*/
*/
public function getUserProfile() {
if ($this->userProfile === null) {
- $this->userProfile = new UserProfile(new User(null, $this->getDecoratedObject()->data));
+ if ($this->userID) {
+ $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->userID);
+ }
+ else {
+ $this->userProfile = new UserProfile(new User(null, array(
+ 'username' => $this->username
+ )));
+ }
}
return $this->userProfile;
use wcf\data\attachment\GroupedAttachmentList;
use wcf\data\conversation\Conversation;
use wcf\data\object\type\ObjectTypeCache;
+use wcf\data\user\UserProfileCache;
use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
/**
*/
protected $conversation = null;
- /**
- * Creates a new ViewableConversationMessageList object.
- */
- public function __construct() {
- parent::__construct();
-
- $this->sqlSelects .= "user_option_value.*, user_table.*";
- $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = conversation_message.userID)";
- $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_option_value user_option_value ON (user_option_value.userID = user_table.userID)";
-
- // get avatars
- if (!empty($this->sqlSelects)) $this->sqlSelects .= ',';
- $this->sqlSelects .= "user_avatar.*";
- $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_avatar user_avatar ON (user_avatar.avatarID = user_table.avatarID)";
- }
-
/**
* @see \wcf\data\DatabaseObjectList::readObjects()
*/
parent::readObjects();
+ $userIDs = [ ];
foreach ($this->objects as $message) {
if ($message->time > $this->maxPostTime) {
$this->maxPostTime = $message->time;
if ($message->hasEmbeddedObjects) {
$this->embeddedObjectMessageIDs[] = $message->messageID;
}
+ if ($message->userID) {
+ $userIDs[] = $message->userID;
+ }
+ }
+
+ if (!empty($userIDs)) {
+ UserProfileCache::getInstance()->cacheUserIDs($userIDs);
}
if ($this->embeddedObjectLoading) {
if (!empty($this->embeddedObjectMessageIDs)) {
// add message objects to attachment object cache to save SQL queries
ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'com.woltlab.wcf.conversation.message')->getProcessor()->setCachedObjects($this->objects);
-
+
// load embedded objects
MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.conversation.message', $this->embeddedObjectMessageIDs);
}
<?php
namespace wcf\data\modification\log;
use wcf\data\conversation\Conversation;
+use wcf\data\user\UserProfileCache;
use wcf\system\log\modification\ConversationModificationLogHandler;
use wcf\system\WCF;
* @see \wcf\data\DatabaseObjectList::readObjects()
*/
public function readObjects() {
- $sql = "SELECT user_avatar.*,
- user_table.email, user_table.enableGravatar, user_table.disableAvatar, user_table.gravatarFileExtension,
- modification_log.*
- FROM wcf".WCF_N."_modification_log modification_log
- LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = modification_log.userID)
- LEFT JOIN wcf".WCF_N."_user_avatar user_avatar ON (user_avatar.avatarID = user_table.avatarID)
- WHERE modification_log.objectTypeID = ?
- AND modification_log.objectID = ?
- ".(!empty($this->sqlOrderBy) ? "ORDER BY ".$this->sqlOrderBy : '');
+ $sql = "SELECT modification_log.*
+ FROM wcf".WCF_N."_modification_log modification_log
+ WHERE modification_log.objectTypeID = ?
+ AND modification_log.objectID = ?
+ ".(!empty($this->sqlOrderBy) ? "ORDER BY ".$this->sqlOrderBy : '');
$statement = WCF::getDB()->prepareStatement($sql, $this->sqlLimit, $this->sqlOffset);
$statement->execute(array(
$this->conversationObjectTypeID,
$this->objects = $statement->fetchObjects(($this->objectClassName ?: $this->className));
// use table index as array index
- $objects = array();
+ $objects = $userIDs = [ ];
foreach ($this->objects as $object) {
$objectID = $object->{$this->getDatabaseTableIndexName()};
$objects[$objectID] = $object;
$this->indexToObject[] = $objectID;
+
+ if ($object->userID) {
+ $userIDs[] = $object->userID;
+ }
}
$this->objectIDs = $this->indexToObject;
$this->objects = $objects;
+ if (!empty($userIDs)) {
+ UserProfileCache::getInstance()->cacheUserIDs($userIDs);
+ }
+
foreach ($this->objects as &$object) {
$object = new ViewableConversationModificationLog($object);
}
namespace wcf\data\modification\log;
use wcf\data\user\User;
use wcf\data\user\UserProfile;
+use wcf\data\user\UserProfileCache;
use wcf\data\DatabaseObjectDecorator;
+use wcf\data\TLegacyUserPropertyAccess;
use wcf\system\WCF;
/**
* @category Community Framework
*/
class ViewableConversationModificationLog extends DatabaseObjectDecorator {
+ use TLegacyUserPropertyAccess;
+
/**
* @see \wcf\data\DatabaseObjectDecorator::$baseClass
*/
*/
public function getUserProfile() {
if ($this->userProfile === null) {
- $this->userProfile = new UserProfile(new User(null, $this->getDecoratedObject()->data));
+ if ($this->userID) {
+ $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->userID);
+ }
+ else {
+ $this->userProfile = new UserProfile(new User(null, array(
+ 'username' => $this->username
+ )));
+ }
}
return $this->userProfile;