2 namespace wcf\system\box
;
3 use wcf\data\user\UserProfileList
;
4 use wcf\data\DatabaseObject
;
5 use wcf\system\cache\builder\MostActiveMembersCacheBuilder
;
6 use wcf\system\cache\builder\MostLikedMembersCacheBuilder
;
7 use wcf\system\cache\builder\NewestMembersCacheBuilder
;
8 use wcf\system\cache\runtime\UserProfileRuntimeCache
;
9 use wcf\system\event\EventHandler
;
10 use wcf\system\request\LinkHandler
;
14 * Box controller for a list of users.
16 * @author Matthias Schmidt
17 * @copyright 2001-2016 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package WoltLabSuite\Core\System\Box
22 class UserListBoxController
extends AbstractDatabaseObjectListBoxController
{
24 * maps special sort fields to cache builders
27 public $cacheBuilders = [
28 'activityPoints' => MostActiveMembersCacheBuilder
::class,
29 'likesReceived' => MostLikedMembersCacheBuilder
::class,
30 'registrationDate' => NewestMembersCacheBuilder
::class
36 protected $sortFieldLanguageItemPrefix = 'wcf.user.sortField';
39 * ids of the shown users loaded from cache
47 public $validSortFields = [
56 public function __construct() {
57 if (!empty($this->validSortFields
) && MODULE_LIKE
) {
58 $this->validSortFields
[] = 'likesReceived';
61 parent
::__construct();
67 public function getLink() {
68 if (MODULE_MEMBERS_LIST
) {
70 if ($this->box
->sortField
) {
71 $parameters = 'sortField='.$this->box
->sortField
.'&sortOrder='.$this->box
->sortOrder
;
74 return LinkHandler
::getInstance()->getLink('MembersList', [], $parameters);
83 protected function getObjectList() {
84 // use specialized cache builders
85 if ($this->box
->sortOrder
&& $this->box
->sortField
&& isset($this->cacheBuilders
[$this->box
->sortField
])) {
86 $this->userIDs
= call_user_func([$this->cacheBuilders
[$this->box
->sortField
], 'getInstance'])->getData([
87 'limit' => $this->box
->limit
,
88 'sortOrder' => $this->sortOrder
92 if ($this->userIDs
!== null) {
93 UserProfileRuntimeCache
::getInstance()->cacheObjectIDs($this->userIDs
);
96 return new UserProfileList();
102 protected function getTemplate() {
104 if ($this->userIDs
!== null) {
105 $userProfiles = UserProfileRuntimeCache
::getInstance()->getObjects($this->userIDs
);
107 // filter `null` values of users that have been deleted in the meantime
108 $userProfiles = array_filter($userProfiles, function($userProfile) {
109 return $userProfile !== null;
112 DatabaseObject
::sort($userProfiles, $this->sortField
, $this->sortOrder
);
115 return WCF
::getTPL()->fetch('boxUserList', 'wcf', [
116 'boxUsers' => $this->userIDs
!== null ?
$userProfiles : $this->objectList
->getObjects(),
117 'boxSortField' => $this->box
->sortField
124 public function hasContent() {
125 $hasContent = parent
::hasContent();
127 if ($this->userIDs
!== null) {
128 return !empty($this->userIDs
);
137 public function hasLink() {
138 return MODULE_MEMBERS_LIST
== 1;
144 public function readObjects() {
145 if ($this->userIDs
=== null) {
146 parent
::readObjects();
149 EventHandler
::getInstance()->fireAction($this, 'readObjects');