From: Matthias Schmidt Date: Tue, 20 Apr 2021 14:04:42 +0000 (+0200) Subject: Merge branch '5.3' X-Git-Tag: 5.4.0_Alpha_1~73 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c00ef2d14555e2efbe06a8e003bbec20a0c8363c;p=GitHub%2FWoltLab%2FWCF.git Merge branch '5.3' --- c00ef2d14555e2efbe06a8e003bbec20a0c8363c diff --cc wcfsetup/install/files/lib/system/box/UserListBoxController.class.php index f182c4f1db,7af672c311..a468675c75 --- a/wcfsetup/install/files/lib/system/box/UserListBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/UserListBoxController.class.php @@@ -1,9 -1,8 +1,10 @@@ - * @package WoltLabSuite\Core\System\Box - * @since 3.0 + * + * @author Matthias Schmidt + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Box + * @since 3.0 */ -class UserListBoxController extends AbstractDatabaseObjectListBoxController { - /** - * maps special sort fields to cache builders - * @var string[] - */ - public $cacheBuilders = [ - 'activityPoints' => MostActiveMembersCacheBuilder::class, - 'likesReceived' => MostLikedMembersCacheBuilder::class, - 'registrationDate' => NewestMembersCacheBuilder::class - ]; - - /** - * @inheritDoc - */ - protected $conditionDefinition = 'com.woltlab.wcf.box.userList.condition'; - - /** - * @inheritDoc - */ - public $defaultLimit = 5; - - /** - * @inheritDoc - */ - protected $sortFieldLanguageItemPrefix = 'wcf.user.sortField'; - - /** - * ids of the shown users loaded from cache - * @var integer[]|null - */ - public $userIDs; - - /** - * @inheritDoc - */ - public $validSortFields = [ - 'username', - 'activityPoints', - 'registrationDate' - ]; - - /** - * @inheritDoc - */ - public function __construct() { - if (!empty($this->validSortFields) && MODULE_LIKE) { - $this->validSortFields[] = 'likesReceived'; - } - - parent::__construct(); - } - - /** - * @inheritDoc - */ - public function getLink() { - if (MODULE_MEMBERS_LIST) { - $parameters = ''; - if ($this->sortField) { - $parameters = 'sortField='.$this->sortField.'&sortOrder='.$this->sortOrder; - } - - return LinkHandler::getInstance()->getLink('MembersList', [], $parameters); - } - - return ''; - } - - /** - * @inheritDoc - */ - protected function getObjectList() { - // use specialized cache builders - if ($this->sortOrder && $this->sortField && isset($this->cacheBuilders[$this->sortField])) { - $conditions = array_filter($this->box->getConditions(), function(Condition $condition) { - return $condition->getObjectType()->getProcessor() instanceof IObjectListCondition; - }); - - $this->userIDs = call_user_func([$this->cacheBuilders[$this->sortField], 'getInstance'])->getData([ - 'conditions' => $conditions, - 'limit' => $this->limit, - 'sortOrder' => $this->sortOrder, - ]); - } - - if ($this->userIDs !== null) { - UserProfileRuntimeCache::getInstance()->cacheObjectIDs($this->userIDs); - } - - return new UserProfileList(); - } - - /** - * @inheritDoc - */ - protected function getTemplate() { - $userProfiles = []; - if ($this->userIDs !== null) { - $userProfiles = UserProfileRuntimeCache::getInstance()->getObjects($this->userIDs); - - // filter `null` values of users that have been deleted in the meantime - $userProfiles = array_filter($userProfiles, function($userProfile) { - return $userProfile !== null; - }); - - DatabaseObject::sort($userProfiles, $this->sortField, $this->sortOrder); - } - - return WCF::getTPL()->fetch('boxUserList', 'wcf', [ - 'boxUsers' => $this->userIDs !== null ? $userProfiles : $this->objectList->getObjects(), - 'boxSortField' => $this->box->sortField - ], true); - } - - /** - * @inheritDoc - */ - public function hasContent() { - $hasContent = parent::hasContent(); - - if ($this->userIDs !== null) { - return !empty($this->userIDs); - } - - return $hasContent; - } - - /** - * @inheritDoc - */ - public function hasLink() { - return MODULE_MEMBERS_LIST == 1; - } - - /** - * @inheritDoc - */ - public function readObjects() { - if ($this->userIDs === null) { - parent::readObjects(); - } - else { - EventHandler::getInstance()->fireAction($this, 'readObjects'); - } - } +class UserListBoxController extends AbstractDatabaseObjectListBoxController +{ + /** + * maps special sort fields to cache builders + * @var string[] + */ + public $cacheBuilders = [ + 'activityPoints' => MostActiveMembersCacheBuilder::class, + 'likesReceived' => MostLikedMembersCacheBuilder::class, + 'registrationDate' => NewestMembersCacheBuilder::class, + ]; + + /** + * @inheritDoc + */ + protected $conditionDefinition = 'com.woltlab.wcf.box.userList.condition'; + + /** + * @inheritDoc + */ + public $defaultLimit = 5; + + /** + * @inheritDoc + */ + protected $sortFieldLanguageItemPrefix = 'wcf.user.sortField'; + + /** + * ids of the shown users loaded from cache + * @var int[]|null + */ + public $userIDs; + + /** + * @inheritDoc + */ + public $validSortFields = [ + 'username', + 'activityPoints', + 'registrationDate', + ]; + + /** + * @inheritDoc + */ + public function __construct() + { + if (!empty($this->validSortFields) && MODULE_LIKE) { + $this->validSortFields[] = 'likesReceived'; + } + + parent::__construct(); + } + + /** + * @inheritDoc + */ + public function getLink() + { + if (MODULE_MEMBERS_LIST) { + $parameters = ''; + if ($this->sortField) { + $parameters = 'sortField=' . $this->sortField . '&sortOrder=' . $this->sortOrder; + } + + return LinkHandler::getInstance()->getLink('MembersList', [], $parameters); + } + + return ''; + } + + /** + * @inheritDoc + */ + protected function getObjectList() + { + // use specialized cache builders + if ($this->sortOrder && $this->sortField && isset($this->cacheBuilders[$this->sortField])) { ++ $conditions = \array_filter($this->box->getConditions(), static function (Condition $condition) { ++ return $condition->getObjectType()->getProcessor() instanceof IObjectListCondition; ++ }); ++ + $this->userIDs = \call_user_func([$this->cacheBuilders[$this->sortField], 'getInstance'])->getData([ ++ 'conditions' => $conditions, + 'limit' => $this->limit, + 'sortOrder' => $this->sortOrder, + ]); + } + + if ($this->userIDs !== null) { + UserProfileRuntimeCache::getInstance()->cacheObjectIDs($this->userIDs); + } + + return new UserProfileList(); + } + + /** + * @inheritDoc + */ + protected function getTemplate() + { + $userProfiles = []; + if ($this->userIDs !== null) { + $userProfiles = UserProfileRuntimeCache::getInstance()->getObjects($this->userIDs); + + // filter `null` values of users that have been deleted in the meantime + $userProfiles = \array_filter($userProfiles, static function ($userProfile) { + return $userProfile !== null; + }); + + DatabaseObject::sort($userProfiles, $this->sortField, $this->sortOrder); + } + + return WCF::getTPL()->fetch('boxUserList', 'wcf', [ + 'boxUsers' => $this->userIDs !== null ? $userProfiles : $this->objectList->getObjects(), + 'boxSortField' => $this->box->sortField, + ], true); + } + + /** + * @inheritDoc + */ + public function hasContent() + { + $hasContent = parent::hasContent(); + + if ($this->userIDs !== null) { + return !empty($this->userIDs); + } + + return $hasContent; + } + + /** + * @inheritDoc + */ + public function hasLink() + { + return MODULE_MEMBERS_LIST == 1; + } + + /** + * @inheritDoc + */ + public function readObjects() + { + if ($this->userIDs === null) { + parent::readObjects(); + } else { + EventHandler::getInstance()->fireAction($this, 'readObjects'); + } + } } diff --cc wcfsetup/install/files/lib/system/cache/builder/AbstractSortedUserCacheBuilder.class.php index a6c1a23b77,fee3852aec..5dd665d5cb --- a/wcfsetup/install/files/lib/system/cache/builder/AbstractSortedUserCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/AbstractSortedUserCacheBuilder.class.php @@@ -1,67 -1,73 +1,77 @@@ - * @package WoltLabSuite\Core\System\Cache\Builder - * @since 3.0 + * @author Matthias Schmidt + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Cache\Builder + * @since 3.0 */ -abstract class AbstractSortedUserCacheBuilder extends AbstractCacheBuilder { - /** - * default limit value if no limit parameter is provided - * @var integer - */ - protected $defaultLimit = 5; - - /** - * default sort order if no sort order parameter is provided - * @var string - */ - protected $defaultSortOrder = 'DESC'; - - /** - * @inheritDoc - */ - protected $maxLifetime = 300; - - /** - * if `true`, only positive values of the database column will be considered - * @var boolean - */ - protected $positiveValuesOnly = false; - - /** - * database table column used for sorting - * @var string - */ - protected $sortField; - - /** - * @inheritDoc - */ - protected function rebuild(array $parameters) { - $sortOrder = $this->defaultSortOrder; - if (!empty($parameters['sortOrder'])) { - $sortOrder = $parameters['sortOrder']; - } - - $userProfileList = new UserList(); - if ($this->positiveValuesOnly) { - $userProfileList->getConditionBuilder()->add('user_table.'.$this->sortField.' > ?', [0]); - } - if (isset($parameters['conditions'])) { - /** @var Condition $condition */ - foreach ($parameters['conditions'] as $condition) { - /** @var IObjectListCondition $processor */ - $processor = $condition->getObjectType()->getProcessor(); - $processor->addObjectListCondition($userProfileList, $condition->conditionData); - } - } - $userProfileList->sqlOrderBy = 'user_table.'.$this->sortField.' '.$sortOrder; - $userProfileList->sqlLimit = !empty($parameters['limit']) ? $parameters['limit'] : $this->defaultLimit; - $userProfileList->readObjectIDs(); - - return $userProfileList->getObjectIDs(); - } +abstract class AbstractSortedUserCacheBuilder extends AbstractCacheBuilder +{ + /** + * default limit value if no limit parameter is provided + * @var int + */ + protected $defaultLimit = 5; + + /** + * default sort order if no sort order parameter is provided + * @var string + */ + protected $defaultSortOrder = 'DESC'; + + /** + * @inheritDoc + */ + protected $maxLifetime = 300; + + /** + * if `true`, only positive values of the database column will be considered + * @var bool + */ + protected $positiveValuesOnly = false; + + /** + * database table column used for sorting + * @var string + */ + protected $sortField; + + /** + * @inheritDoc + */ + protected function rebuild(array $parameters) + { + $sortOrder = $this->defaultSortOrder; + if (!empty($parameters['sortOrder'])) { + $sortOrder = $parameters['sortOrder']; + } + + $userProfileList = new UserList(); + if ($this->positiveValuesOnly) { + $userProfileList->getConditionBuilder()->add('user_table.' . $this->sortField . ' > ?', [0]); + } ++ if (isset($parameters['conditions'])) { ++ /** @var Condition $condition */ ++ foreach ($parameters['conditions'] as $condition) { ++ /** @var IObjectListCondition $processor */ ++ $processor = $condition->getObjectType()->getProcessor(); ++ $processor->addObjectListCondition($userProfileList, $condition->conditionData); ++ } ++ } + $userProfileList->sqlOrderBy = 'user_table.' . $this->sortField . ' ' . $sortOrder; + $userProfileList->sqlLimit = !empty($parameters['limit']) ? $parameters['limit'] : $this->defaultLimit; + $userProfileList->readObjectIDs(); + + return $userProfileList->getObjectIDs(); + } }