<?php
+
namespace wcf\system\box;
-use wcf\data\user\UserProfileList;
+
+ use wcf\data\condition\Condition;
use wcf\data\DatabaseObject;
+use wcf\data\user\UserProfileList;
use wcf\system\cache\builder\MostActiveMembersCacheBuilder;
use wcf\system\cache\builder\MostLikedMembersCacheBuilder;
use wcf\system\cache\builder\NewestMembersCacheBuilder;
/**
* Box controller for a list of users.
- *
- * @author Matthias Schmidt
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\System\Box
- * @since 3.0
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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');
+ }
+ }
}
<?php
+
namespace wcf\system\cache\builder;
+
+ use wcf\data\condition\Condition;
use wcf\data\user\UserList;
+ use wcf\system\condition\IObjectListCondition;
/**
* Caches a list of the newest members.
*
- * @author Matthias Schmidt
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\System\Cache\Builder
- * @since 3.0
+ * @author Matthias Schmidt
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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();
+ }
}