Merge branch '5.3'
authorMatthias Schmidt <gravatronics@live.com>
Tue, 20 Apr 2021 14:04:42 +0000 (16:04 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 20 Apr 2021 14:04:42 +0000 (16:04 +0200)
1  2 
wcfsetup/install/files/lib/system/box/UserListBoxController.class.php
wcfsetup/install/files/lib/system/cache/builder/AbstractSortedUserCacheBuilder.class.php

index f182c4f1db67209bb553b222fcbff21f98641436,7af672c311e09af4ba17723323093b16c75c8752..a468675c752d6a6106b1fc450068269d88f21230
@@@ -1,9 -1,8 +1,10 @@@
  <?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;
@@@ -14,158 -14,156 +16,163 @@@ use wcf\system\WCF
  
  /**
   * 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');
 +        }
 +    }
  }
index a6c1a23b77b42391a889fa991bd2422f6977392b,fee3852aec066ea5a59f8b7dcce6a574e25b378e..5dd665d5cbee62ada3f759fc0dc80a0d0d67f2a7
@@@ -1,67 -1,73 +1,77 @@@
  <?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();
 +    }
  }