[FEATURE] Backend User: display "online" badge 77/40377/7
authorFelix Kopp <felix-source@phorax.com>
Wed, 17 Jun 2015 17:26:00 +0000 (19:26 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 19 Jun 2015 10:11:35 +0000 (12:11 +0200)
To gain quick overview of people in project being online
at the moment the small label "online" is added to listing.

Resolves: #67574
Releases: master
Change-Id: I098977dc17ab7edacc9ed9b9e122471ed0d5e3c5
Reviewed-on: http://review.typo3.org/40377
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/beuser/Classes/Controller/BackendUserController.php
typo3/sysext/beuser/Classes/Domain/Repository/BackendUserSessionRepository.php
typo3/sysext/beuser/Resources/Private/Language/locallang.xlf
typo3/sysext/beuser/Resources/Private/Partials/BackendUser/IndexListRow.html
typo3/sysext/beuser/Resources/Private/Partials/BackendUser/OnlineListRow.html
typo3/sysext/beuser/Resources/Private/Templates/BackendUser/Index.html
typo3/sysext/core/Documentation/Changelog/master/Feature-67574-DisplayOnlineStatusInBackendUserList.rst [new file with mode: 0644]

index e685f48..8eec855 100644 (file)
@@ -109,6 +109,17 @@ class BackendUserController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionCont
                        $this->switchUser($switchUser);
                }
                $compareUserList = $this->moduleData->getCompareUserList();
+
+               // Create online user list for easy parsing
+               $onlineUsers = $this->backendUserSessionRepository->findAllActive();
+               $onlineBackendUsers = array();
+               if (is_array($onlineUsers)) {
+                       foreach ($onlineUsers as $onlineUser) {
+                               $onlineBackendUsers[$onlineUser['ses_userid']] = TRUE;
+                       }
+               }
+               $this->view->assign('onlineBackendUsers', $onlineBackendUsers);
+
                $this->view->assign('demand', $demand);
                $this->view->assign('returnUrl', rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser')));
                $this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
index 57144f3..c188cc6 100644 (file)
@@ -13,6 +13,11 @@ namespace TYPO3\CMS\Beuser\Domain\Repository;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication;
+use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
+use TYPO3\CMS\Extbase\Persistence\Repository;
 
 /**
  * Repository for \TYPO3\CMS\Extbase\Domain\Model\BackendUser
@@ -20,52 +25,74 @@ namespace TYPO3\CMS\Beuser\Domain\Repository;
  * @author Felix Kopp <felix-source@phorax.com>
  * @author Pascal Dürsteler <pascal@notionlab.ch>
  */
-class BackendUserSessionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
+class BackendUserSessionRepository extends Repository {
+
+       /**
+        * Find all active sessions for all backend users
+        *
+        * @return array|NULL Array of rows, or NULL in case of SQL error
+        */
+       public function findAllActive() {
+               return $this->getDatabaseConnection()->exec_SELECTgetRows(
+                       'ses_id AS id, ses_userid, ses_iplock AS ip, ses_tstamp AS timestamp',
+                       'be_sessions',
+                       '1=1'
+               );
+       }
 
        /**
         * Find Sessions for specific BackendUser
         * Delivers an Array, not an ObjectStorage!
         *
-        * @param \TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser
+        * @param BackendUser $backendUser
         * @return array
         */
-       public function findByBackendUser(\TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser) {
+       public function findByBackendUser(BackendUser $backendUser) {
                $sessions = array();
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+               $db = $this->getDatabaseConnection();
+               $res = $db->exec_SELECTquery(
                        'ses_id AS id, ses_iplock AS ip, ses_tstamp AS timestamp',
                        'be_sessions',
                        'ses_userid = ' . (int)$backendUser->getUid(),
                        '',
                        'ses_tstamp ASC'
                );
-               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+               while ($row = $db->sql_fetch_assoc($res)) {
                        $sessions[] = array(
                                'id' => $row['id'],
                                'ip' => $row['ip'],
                                'timestamp' => $row['timestamp']
                        );
                }
-               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+               $db->sql_free_result($res);
                return $sessions;
        }
 
        /**
         * Update current session to move back to the original user.
         *
-        * @param \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication $authentication
+        * @param AbstractUserAuthentication $authentication
         * @return void
         */
-       public function switchBackToOriginalUser(\TYPO3\CMS\Core\Authentication\AbstractUserAuthentication $authentication) {
+       public function switchBackToOriginalUser(AbstractUserAuthentication $authentication) {
                $updateData = array(
                        'ses_userid' => $authentication->user['ses_backuserid'],
                        'ses_backuserid' => 0,
                );
-               $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
+               $db = $this->getDatabaseConnection();
+               $db->exec_UPDATEquery(
                        'be_sessions',
-                       'ses_id = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions') .
-                               ' AND ses_name = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::getCookieName(), 'be_sessions') .
+                       'ses_id = ' . $db->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions') .
+                               ' AND ses_name = ' . $db->fullQuoteStr(BackendUserAuthentication::getCookieName(), 'be_sessions') .
                                ' AND ses_userid=' . (int)$GLOBALS['BE_USER']->user['uid'], $updateData
                );
        }
 
+       /**
+        * @return DatabaseConnection
+        */
+       protected function getDatabaseConnection() {
+               return $GLOBALS['TYPO3_DB'];
+       }
+
 }
index 5f331a4..842cfbe 100644 (file)
                        <trans-unit id="backendUserGroupListing">
                                <source>Backend User Group Listing</source>
                        </trans-unit>
+                       <trans-unit id="online">
+                               <source>online</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>
index a181ff9..047279a 100644 (file)
@@ -8,10 +8,12 @@
                </a>
        </td>
        <td class="col-title">
-               <a href="{bu:editRecord(parameters: 'edit[be_users][{backendUser.uid}]=edit&returnUrl={returnUrl}')}">
-                       <b>{backendUser.userName}</b><br />
-                       {backendUser.realName}
-               </a>
+               <a href="{bu:editRecord(parameters: 'edit[be_users][{backendUser.uid}]=edit&returnUrl={returnUrl}')}"><b>{backendUser.userName}</b></a>
+               <f:if condition="{bu:arrayElement(array: onlineBackendUsers, key: backendUser.uid)}">
+                       <span class="label label-success"><f:translate key="online" /></span>
+               </f:if>
+               <br />
+               <a href="{bu:editRecord(parameters: 'edit[be_users][{backendUser.uid}]=edit&returnUrl={returnUrl}')}">{backendUser.realName}</a>
        </td>
        <td>
                <f:if condition="{backendUser.lastLoginDateAndTime}">
index 7d61cbd..d4a5572 100644 (file)
@@ -11,7 +11,8 @@
                                        </a>
                                </td>
                                <td class="col-title">
-                                       <b>{onlineUser.backendUser.userName}</b><br />
+                                       <b>{onlineUser.backendUser.userName}</b>
+                                       <span class="label label-success"><f:translate key="online" /></span><br />
                                        {onlineUser.backendUser.realName}
                                </td>
                        </f:then>
index 5d7e73d..d135720 100644 (file)
@@ -68,7 +68,7 @@
                                </thead>
                                <tbody>
                                        <f:for each="{paginatedBackendUsers}" as="backendUser">
-                                               <f:render partial="BackendUser/IndexListRow" arguments="{demand: demand, backendUser: backendUser, dateFormat: dateFormat, timeFormat: timeFormat, returnUrl: returnUrl}" />
+                                               <f:render partial="BackendUser/IndexListRow" arguments="{demand: demand, backendUser: backendUser, onlineBackendUsers: onlineBackendUsers, dateFormat: dateFormat, timeFormat: timeFormat, returnUrl: returnUrl}" />
                                        </f:for>
                                        <f:comment>
                                                Footer row: no officially defined style yet
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-67574-DisplayOnlineStatusInBackendUserList.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-67574-DisplayOnlineStatusInBackendUserList.rst
new file mode 100644 (file)
index 0000000..ac482fd
--- /dev/null
@@ -0,0 +1,14 @@
+============================================================
+Feature: #67574 - Display online status in backend user list
+============================================================
+
+Description
+===========
+
+A badge that shows the online status of a backend user has been integrated.
+
+
+Impact
+======
+
+The badge will be shown next to the username in the backend user list.
\ No newline at end of file