3 namespace wcf\system\box
;
5 use wcf\data\condition\Condition
;
6 use wcf\data\DatabaseObject
;
7 use wcf\data\user\UserProfileList
;
8 use wcf\system\cache\builder\MostActiveMembersCacheBuilder
;
9 use wcf\system\cache\builder\MostLikedMembersCacheBuilder
;
10 use wcf\system\cache\builder\NewestMembersCacheBuilder
;
11 use wcf\system\cache\runtime\UserProfileRuntimeCache
;
12 use wcf\system\condition\IObjectListCondition
;
13 use wcf\system\event\EventHandler
;
14 use wcf\system\request\LinkHandler
;
18 * Box controller for a list of users.
20 * @author Matthias Schmidt
21 * @copyright 2001-2019 WoltLab GmbH
22 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
25 class UserListBoxController
extends AbstractDatabaseObjectListBoxController
28 * maps special sort fields to cache builders
31 public $cacheBuilders = [
32 'activityPoints' => MostActiveMembersCacheBuilder
::class,
33 'likesReceived' => MostLikedMembersCacheBuilder
::class,
34 'registrationDate' => NewestMembersCacheBuilder
::class,
40 protected $conditionDefinition = 'com.woltlab.wcf.box.userList.condition';
45 protected static $supportedPositions = ['sidebarLeft', 'sidebarRight'];
50 public $defaultLimit = 5;
55 protected $sortFieldLanguageItemPrefix = 'wcf.user.sortField';
58 * ids of the shown users loaded from cache
66 public $validSortFields = [
75 public function __construct()
77 if (!empty($this->validSortFields
) && MODULE_LIKE
) {
78 $this->validSortFields
[] = 'likesReceived';
81 parent
::__construct();
87 public function getLink(): string
89 if (MODULE_MEMBERS_LIST
) {
91 if ($this->sortField
) {
92 $parameters = 'sortField=' . $this->sortField
. '&sortOrder=' . $this->sortOrder
;
95 return LinkHandler
::getInstance()->getLink('MembersList', [], $parameters);
104 protected function getObjectList()
106 // use specialized cache builders
107 if ($this->sortOrder
&& $this->sortField
&& isset($this->cacheBuilders
[$this->sortField
])) {
108 $conditions = \array_filter
($this->box
->getConditions(), static function (Condition
$condition) {
109 return $condition->getObjectType()->getProcessor() instanceof IObjectListCondition
;
112 $this->userIDs
= \
call_user_func([$this->cacheBuilders
[$this->sortField
], 'getInstance'])->getData([
113 'conditions' => $conditions,
114 'limit' => $this->limit
,
115 'sortOrder' => $this->sortOrder
,
119 if ($this->userIDs
!== null) {
120 UserProfileRuntimeCache
::getInstance()->cacheObjectIDs($this->userIDs
);
123 return new UserProfileList();
129 protected function getTemplate()
132 if ($this->userIDs
!== null) {
133 $userProfiles = UserProfileRuntimeCache
::getInstance()->getObjects($this->userIDs
);
135 // filter `null` values of users that have been deleted in the meantime
136 $userProfiles = \array_filter
($userProfiles, static function ($userProfile) {
137 return $userProfile !== null;
140 DatabaseObject
::sort($userProfiles, $this->sortField
, $this->sortOrder
);
143 return WCF
::getTPL()->fetch('boxUserList', 'wcf', [
144 'boxUsers' => $this->userIDs
!== null ?
$userProfiles : $this->objectList
->getObjects(),
145 'boxSortField' => $this->box
->sortField
,
152 public function hasContent()
154 $hasContent = parent
::hasContent();
156 if ($this->userIDs
!== null) {
157 return !empty($this->userIDs
);
166 public function hasLink()
168 return MODULE_MEMBERS_LIST
== 1;
174 public function readObjects()
176 if ($this->userIDs
=== null) {
177 parent
::readObjects();
179 EventHandler
::getInstance()->fireAction($this, 'readObjects');