$statement->execute($conditions->getParameters());
$userToGroups = $statement->fetchMap('userID', 'groupID', false);
- $sql = "SELECT user_avatar.*, option_value.*, user_table.*
+ $sql = "SELECT option_value.*, user_table.*
FROM wcf1_user user_table
LEFT JOIN wcf1_user_option_value option_value
ON option_value.userID = user_table.userID
- LEFT JOIN wcf1_user_avatar user_avatar
- ON user_avatar.avatarID = user_table.avatarID
" . $conditions . "
ORDER BY " . (($this->sortField != 'email' && isset($this->options[$this->sortField])) ? 'option_value.userOption' . $this->options[$this->sortField]->optionID : 'user_table.' . $this->sortField) . " " . $this->sortOrder;
$statement = WCF::getDB()->prepare($sql);
--- /dev/null
+<?php
+
+namespace wcf\data\user;
+
+use wcf\data\DatabaseObjectList;
+use wcf\data\file\FileList;
+
+/**
+ * Contains methods to load avatar files for a list of `UserProfile`.
+ *
+ * @author Olaf Braun
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ *
+ * @property UserProfile[] $objects
+ * @mixin DatabaseObjectList
+ */
+trait TUserAvatarObjectList
+{
+ public bool $loadAvatarFiles = true;
+
+ protected function loadAvatarFiles(): void
+ {
+ if (!$this->loadAvatarFiles) {
+ return;
+ }
+
+ $avatarFileIDs = [];
+ foreach ($this->objects as $user) {
+ if ($user->avatarFileID !== null) {
+ $avatarFileIDs[] = $user->avatarFileID;
+ }
+ }
+ if ($avatarFileIDs === []) {
+ return;
+ }
+
+ $fileList = new FileList();
+ $fileList->loadThumbnails = true;
+ $fileList->setObjectIDs($avatarFileIDs);
+ $fileList->readObjects();
+ $files = $fileList->getObjects();
+
+ foreach ($this->objects as $user) {
+ if ($user->avatarFileID !== null) {
+ $user->setFileAvatar($files[$user->avatarFileID]);
+ }
+ }
+ }
+}
use wcf\data\DatabaseObjectDecorator;
use wcf\data\file\File;
-use wcf\data\file\thumbnail\FileThumbnailList;
+use wcf\data\file\FileList;
use wcf\data\ITitledLinkObject;
use wcf\data\trophy\Trophy;
use wcf\data\trophy\TrophyCache;
use wcf\data\user\avatar\AvatarDecorator;
use wcf\data\user\avatar\DefaultAvatar;
use wcf\data\user\avatar\IUserAvatar;
-use wcf\data\user\avatar\UserAvatar;
use wcf\data\user\cover\photo\DefaultUserCoverPhoto;
use wcf\data\user\cover\photo\IUserCoverPhoto;
use wcf\data\user\cover\photo\UserCoverPhoto;
*/
public function getAvatar()
{
- // TODO simplify this function?
if ($this->avatar === null) {
if (!$this->disableAvatar) {
if ($this->canSeeAvatar()) {
if ($this->avatarFileID !== null) {
$data = UserStorageHandler::getInstance()->getField('avatar', $this->userID);
if ($data === null) {
- $this->avatar = new File($this->avatarFileID);
+ $fileList = new FileList();
+ $fileList->setObjectIDs([$this->avatarFileID]);
+ $fileList->loadThumbnails = true;
+ $fileList->readObjects();
- $thumbnailList = new FileThumbnailList();
- $thumbnailList->getConditionBuilder()->add("fileID = ?", [$this->avatarFileID]);
- $thumbnailList->readObjects();
- foreach ($thumbnailList as $thumbnail) {
- $this->avatar->addThumbnail($thumbnail);
- }
+ $this->avatar = $fileList->getSingleObject();
UserStorageHandler::getInstance()->update(
$this->userID,
} else {
$this->avatar = \unserialize($data);
}
- } elseif ($this->avatarID) {
- if (!$this->fileHash) {
- $data = UserStorageHandler::getInstance()->getField('avatar', $this->userID);
- if ($data === null) {
- $this->avatar = new UserAvatar($this->avatarID);
- UserStorageHandler::getInstance()->update(
- $this->userID,
- 'avatar',
- \serialize($this->avatar)
- );
- } else {
- $this->avatar = \unserialize($data);
- }
- } else {
- $this->avatar = new UserAvatar(null, $this->getDecoratedObject()->data);
- }
} else {
$parameters = ['avatar' => null];
EventHandler::getInstance()->fireAction($this, 'getAvatar', $parameters);
namespace wcf\data\user;
-use wcf\data\file\FileList;
-
/**
* Represents a list of user profiles.
*
*/
class UserProfileList extends UserList
{
+ use TUserAvatarObjectList;
+
/**
* @inheritDoc
*/
*/
public $decoratorClassName = UserProfile::class;
- public bool $loadAvatarFiles = true;
-
/**
* @inheritDoc
*/
$this->loadAvatarFiles();
}
-
- protected function loadAvatarFiles(): void
- {
- if (!$this->loadAvatarFiles) {
- return;
- }
-
- $avatarFileIDs = [];
- foreach ($this->objects as $user) {
- if ($user->avatarFileID !== null) {
- $avatarFileIDs[] = $user->avatarFileID;
- }
- }
- if ($avatarFileIDs === []) {
- return;
- }
-
- $fileList = new FileList();
- $fileList->loadThumbnails = true;
- $fileList->setObjectIDs($avatarFileIDs);
- $fileList->readObjects();
- $files = $fileList->getObjects();
-
- foreach ($this->objects as $user) {
- if ($user->avatarFileID !== null) {
- $user->setFileAvatar($files[$user->avatarFileID]);
- }
- }
- }
}
namespace wcf\data\user\follow;
+use wcf\data\user\TUserAvatarObjectList;
use wcf\data\user\User;
use wcf\data\user\UserProfile;
*/
class UserFollowerList extends UserFollowList
{
+ use TUserAvatarObjectList;
+
/**
* @inheritDoc
*/
parent::__construct();
$this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar";
- $this->sqlSelects .= ", user_avatar.*";
$this->sqlJoins .= "
LEFT JOIN wcf1_user user_table
- ON user_table.userID = user_follow.userID
- LEFT JOIN wcf1_user_avatar user_avatar
- ON user_avatar.avatarID = user_table.avatarID";
+ ON user_table.userID = user_follow.userID";
+ }
+
+ #[\Override]
+ public function readObjects()
+ {
+ parent::readObjects();
+
+ $this->loadAvatarFiles();
}
}
{
UserFollowList::__construct();
- $this->sqlSelects .= "user_avatar.*, user_follow.followID, user_option_value.*";
+ $this->sqlSelects .= "user_follow.followID, user_option_value.*";
$this->sqlJoins .= "
LEFT JOIN wcf1_user user_table
ON user_table.userID = user_follow.followUserID
LEFT JOIN wcf1_user_option_value user_option_value
- ON user_option_value.userID = user_table.userID
- LEFT JOIN wcf1_user_avatar user_avatar
- ON user_avatar.avatarID = user_table.avatarID";
+ ON user_option_value.userID = user_table.userID";
$this->sqlSelects .= ", user_table.*";
}
namespace wcf\data\user\ignore;
+use wcf\data\user\TUserAvatarObjectList;
use wcf\data\user\User;
use wcf\data\user\UserProfile;
*/
class ViewableUserIgnoreList extends UserIgnoreList
{
+ use TUserAvatarObjectList;
+
/**
* @inheritDoc
*/
}
$this->sqlSelects .= "user_ignore.ignoreID";
$this->sqlSelects .= ", user_option_value.*";
- $this->sqlSelects .= ", user_avatar.*";
$this->sqlJoins .= "
LEFT JOIN wcf1_user user_table
ON user_table.userID = user_ignore.ignoreUserID
LEFT JOIN wcf1_user_option_value user_option_value
- ON user_option_value.userID = user_table.userID
- LEFT JOIN wcf1_user_avatar user_avatar
- ON user_avatar.avatarID = user_table.avatarID";
+ ON user_option_value.userID = user_table.userID";
$this->sqlSelects .= ", user_table.*";
}
+
+ #[\Override]
+ public function readObjects()
+ {
+ parent::readObjects();
+
+ $this->loadAvatarFiles();
+ }
}
use wcf\data\option\OptionAction;
use wcf\data\session\SessionList;
use wcf\data\user\group\UserGroup;
+use wcf\data\user\TUserAvatarObjectList;
use wcf\data\user\User;
use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
*/
class UsersOnlineList extends SessionList
{
+ use TUserAvatarObjectList;
+
/**
* @inheritDoc
*/
{
parent::__construct();
- $this->sqlSelects .= "user_avatar.*, user_option_value.*, user_group.userOnlineMarking, user_table.*";
+ $this->sqlSelects .= "user_option_value.*, user_group.userOnlineMarking, user_table.*";
$this->sqlConditionJoins .= "
LEFT JOIN wcf1_user user_table
ON user_table.userID = session.userID
LEFT JOIN wcf1_user_option_value user_option_value
ON user_option_value.userID = user_table.userID
- LEFT JOIN wcf1_user_avatar user_avatar
- ON user_avatar.avatarID = user_table.avatarID
LEFT JOIN wcf1_user_group user_group
ON user_group.groupID = user_table.userOnlineGroupID";
}
$this->objectIDs = $this->indexToObject;
$this->rewind();
+
+ $this->loadAvatarFiles();
}
/**
namespace wcf\data\user\profile\visitor;
use wcf\data\DatabaseObjectList;
+use wcf\data\user\TUserAvatarObjectList;
use wcf\data\user\User;
use wcf\data\user\UserProfile;
*/
class UserProfileVisitorList extends DatabaseObjectList
{
+ use TUserAvatarObjectList;
+
/**
* @inheritDoc
*/
parent::__construct();
$this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar";
- $this->sqlSelects .= ", user_avatar.*";
$this->sqlJoins .= "
LEFT JOIN wcf1_user user_table
- ON user_table.userID = user_profile_visitor.userID
- LEFT JOIN wcf1_user_avatar user_avatar
- ON user_avatar.avatarID = user_table.avatarID";
+ ON user_table.userID = user_profile_visitor.userID";
+ }
+
+ #[\Override]
+ public function readObjects()
+ {
+ parent::readObjects();
+
+ $this->loadAvatarFiles();
}
}