Force grouping in users online list
authorAlexander Ebert <ebert@woltlab.com>
Thu, 8 Jun 2017 12:10:52 +0000 (14:10 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 8 Jun 2017 12:10:52 +0000 (14:10 +0200)
See #2296

wcfsetup/install/files/lib/page/UsersOnlineListPage.class.php

index 69a6a71af16ab8396423edf19c1a3b13cf1d64db..a5dfb401b24959d5d537e67af653d01f0fbb9635 100644 (file)
@@ -92,6 +92,9 @@ class UsersOnlineListPage extends SortablePage {
                                $this->objectList->getConditionBuilder()->add('session.userID IS NOT NULL');
                        }
                }
+               
+               $this->objectList->sqlSelects .= ", CASE WHEN session.userID IS NULL THEN 1 ELSE 0 END AS userIsGuest";
+               $this->objectList->sqlSelects .= ", CASE WHEN session.spiderID IS NOT NULL THEN 1 ELSE 0 END AS userIsRobot";
        }
        
        /**
@@ -124,6 +127,14 @@ class UsersOnlineListPage extends SortablePage {
         */
        protected function readObjects() {
                if ($this->sqlOrderBy) $this->sqlOrderBy = ($this->sortField == 'lastActivityTime' ? 'session.' : '').$this->sqlOrderBy;
+               
+               $originalSqlOrderBy = $this->sqlOrderBy;
+               // sort in this order: users -> guests -> robots
+               $this->sqlOrderBy = "userIsGuest ASC, userIsRobot DESC, " . $this->sqlOrderBy;
+               
                parent::readObjects();
+               
+               // restore original order
+               $this->sqlOrderBy = $originalSqlOrderBy;
        }
 }