1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Don't show dashboard box if all rooms are empty.

This commit is contained in:
Tim Düsterhus 2013-04-26 20:47:40 +02:00
parent 32e979c7c5
commit 140366f387
3 changed files with 61 additions and 55 deletions

View File

@ -90,25 +90,6 @@ public function canWrite(\wcf\data\user\User $user = null) {
return $canWrite || $ph->getPermission($this, 'mod.canAlwaysWrite'); return $canWrite || $ph->getPermission($this, 'mod.canAlwaysWrite');
} }
/**
* Returns the number of users currently active in this room.
*
* @return integer
*/
public function countUsers() {
$sql = "SELECT
COUNT(*)
FROM
wcf".WCF_N."_user_storage
WHERE
field = ?
AND fieldValue = ?";
$stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(array('roomID', $this->roomID));
return $stmt->fetchColumn();
}
/** /**
* Loads the room cache. * Loads the room cache.
*/ */
@ -134,6 +115,25 @@ public function getTitle() {
return \wcf\system\WCF::getLanguage()->get($this->title); return \wcf\system\WCF::getLanguage()->get($this->title);
} }
/**
* Returns the number of users currently active in this room.
*
* @return integer
*/
public function countUsers() {
$sql = "SELECT
COUNT(*)
FROM
wcf".WCF_N."_user_storage
WHERE
field = ?
AND fieldValue = ?";
$stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(array('roomID', $this->roomID));
return $stmt->fetchColumn();
}
/** /**
* Returns the users that are currently active in this room. * Returns the users that are currently active in this room.
* *
@ -155,6 +155,7 @@ public function getUsers() {
$userList = new \wcf\data\user\UserProfileList(); $userList = new \wcf\data\user\UserProfileList();
if (!empty($userIDs)) $userList->getConditionBuilder()->add('user_table.userID IN (?)', array($userIDs)); if (!empty($userIDs)) $userList->getConditionBuilder()->add('user_table.userID IN (?)', array($userIDs));
else $userList->getConditionBuilder()->add('1 = 0', array()); else $userList->getConditionBuilder()->add('1 = 0', array());
$userList->readObjects(); $userList->readObjects();
return $userList; return $userList;

View File

@ -37,12 +37,10 @@ public function init(\wcf\data\dashboard\box\DashboardBox $box, \wcf\page\IPage
* @see wcf\system\dashboard\box\AbstractContentDashboardBox::render() * @see wcf\system\dashboard\box\AbstractContentDashboardBox::render()
*/ */
protected function render() { protected function render() {
if (count($this->rooms)) { \wcf\system\WCF::getTPL()->assign(array(
\wcf\system\WCF::getTPL()->assign(array( 'rooms' => $this->rooms
'rooms' => $this->rooms ));
));
return \wcf\system\WCF::getTPL()->fetch('dashboardBoxOnlineList', 'chat');
return \wcf\system\WCF::getTPL()->fetch('dashboardBoxOnlineList', 'chat');
}
} }
} }

View File

@ -1,29 +1,36 @@
<header class="boxHeadline boxSubHeadline"> {hascontent}
<hgroup> <header class="boxHeadline boxSubHeadline">
<h1>{lang}chat.header.menu.chat{/lang}</h1> <hgroup>
</hgroup> <h1>{lang}chat.header.menu.chat{/lang}</h1>
</header> </hgroup>
</header>
<div class="container marginTop">
<ul class="containerList"> <div class="container marginTop">
{foreach from=$rooms item='room'} <ul class="containerList">
{assign var='users' value=$room->getUsers()} {content}
{foreach from=$rooms item='room'}
{if $users|count > 0} {assign var='users' value=$room->getUsers()}
<li>
<div> {if $users|count > 0}
<div> <li>
<hgroup class="containerHeadline"> <div>
<h1><a href="{link controller='Chat' object=$room}{/link}">{$room}</a><small> - {$room->topic|language}</small></h1> <div>
<h2><strong>{#$users|count} Users</strong></h2> <hgroup class="containerHeadline">
</hgroup> <h1><a href="{link controller='Chat' object=$room}{/link}">{$room}</a><small> - {$room->topic|language}</small></h1>
<ul class="dataList"> <h2><strong>{#$users|count} Users</strong></h2>
{foreach from=$room->getUsers() item='user'}<li><a href="{link controller='User' object=$user}{/link}" class="userLink" data-user-id="{$user->userID}">{$user}</a></li>{/foreach} </hgroup>
</ul>
</div> <ul class="dataList">
</div> {foreach from=$room->getUsers() item='user'}
</li> <li><a href="{link controller='User' object=$user}{/link}" class="userLink" data-user-id="{$user->userID}">{$user}</a></li>
{/if} {/foreach}
{/foreach} </ul>
</ul> </div>
</div> </div>
</li>
{/if}
{/foreach}
{/content}
</ul>
</div>
{/hascontent}