Added sort options for TodaysBirthdaysBoxController
authorMarcel Werk <burntime@woltlab.com>
Tue, 30 Oct 2018 15:41:48 +0000 (16:41 +0100)
committerMarcel Werk <burntime@woltlab.com>
Tue, 30 Oct 2018 15:41:48 +0000 (16:41 +0100)
Closes #2765

wcfsetup/install/files/lib/system/box/TodaysBirthdaysBoxController.class.php

index 89376f7c52a21a1e831f9f1acbed5117457b8e55..d4ef519ecae648024c4a15fd35e38368d3f04f53 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\box;
+use wcf\data\DatabaseObject;
 use wcf\data\user\option\UserOption;
 use wcf\system\cache\builder\UserOptionCacheBuilder;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
@@ -16,7 +17,7 @@ use wcf\util\DateUtil;
  * @package    WoltLabSuite\Core\System\Box
  * @since      3.0
  */
-class TodaysBirthdaysBoxController extends AbstractBoxController {
+class TodaysBirthdaysBoxController extends AbstractDatabaseObjectListBoxController {
        /**
         * @inheritDoc
         */
@@ -28,6 +29,44 @@ class TodaysBirthdaysBoxController extends AbstractBoxController {
         */
        protected $templateName = 'boxTodaysBirthdays';
        
+       /**
+        * @inheritDoc
+        */
+       public $defaultLimit = 5;
+       
+       /**
+        * @inheritDoc
+        */
+       protected $sortFieldLanguageItemPrefix = 'wcf.user.sortField';
+       
+       /**
+        * @inheritDoc
+        */
+       public $validSortFields = [
+               'username',
+               'activityPoints',
+               'registrationDate'
+       ];
+       
+       /**
+        * @inheritDoc
+        */
+       protected function getObjectList() {}
+       
+       /**
+        * @inheritDoc
+        */
+       protected function getTemplate() {}
+       
+       /**
+        * @inheritDoc
+        */
+       public function hasContent() {
+               parent::hasContent();
+               
+               return AbstractBoxController::hasContent();
+       }
+       
        /**
         * @inheritDoc
         */
@@ -54,8 +93,8 @@ class TodaysBirthdaysBoxController extends AbstractBoxController {
                                        // ignore deleted users
                                        if ($userProfile === null) continue;
                                        
-                                       // show a maximum of 10 users
-                                       if ($i == 10) break;
+                                       // show a maximum of x users
+                                       if ($i == $this->box->limit) break;
                                        
                                        $birthdayUserOption->setUser($userProfile->getDecoratedObject());
                                        
@@ -66,6 +105,14 @@ class TodaysBirthdaysBoxController extends AbstractBoxController {
                                }
                                
                                if (!empty($visibleUserProfiles)) {
+                                       // sort users
+                                       DatabaseObject::sort($visibleUserProfiles, $this->sortField, $this->sortOrder);
+                                       
+                                       // apply limit
+                                       if (count($visibleUserProfiles) > $this->box->limit) {
+                                               $visibleUserProfiles = array_slice($visibleUserProfiles, 0, $this->box->limit);
+                                       }
+                                       
                                        $this->content = WCF::getTPL()->fetch($this->templateName, 'wcf', [
                                                'birthdayUserProfiles' => $visibleUserProfiles
                                        ], true);