1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-11-01 14:20:07 +00:00
Tims-Chat/file/lib/page/RoomListPage.class.php

87 lines
1.9 KiB
PHP
Raw Normal View History

2011-12-18 15:08:51 +00:00
<?php
2013-01-19 19:36:40 +00:00
namespace chat\page;
use \chat\data;
2011-12-18 15:08:51 +00:00
use \wcf\system\cache\CacheHandler;
2013-01-19 19:36:40 +00:00
use \wcf\system\exception\IllegalLinkException;
2011-12-18 15:08:51 +00:00
use \wcf\system\WCF;
/**
* Outputs roomlist.
2011-12-18 15:08:51 +00:00
*
* @author Tim Düsterhus
2013-01-19 19:36:40 +00:00
* @copyright 2010-2013 Tim Düsterhus
2011-12-18 15:08:51 +00:00
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
2013-01-19 19:36:40 +00:00
* @package be.bastelstu.chat
2011-12-18 15:08:51 +00:00
* @subpackage page
*/
2013-01-19 19:36:40 +00:00
class RoomListPage extends \wcf\page\AbstractPage {
2012-08-08 14:51:24 +00:00
/**
* @see wcf\page\AbstractPage::$loginRequired
*/
public $loginRequired = true;
/**
* @see \wcf\page\AbstractPage::$neededModules
*/
2011-12-18 15:08:51 +00:00
public $neededModules = array('CHAT_ACTIVE');
/**
* @see \wcf\page\AbstractPage::$neededPermissions
*/
public $neededPermissions = array();
2012-10-20 14:20:52 +00:00
/**
* the room the user current is in
2013-01-19 19:36:40 +00:00
* @var \chat\data\room\Room
2012-10-20 14:20:52 +00:00
*/
2012-06-10 16:48:08 +00:00
public $room = null;
2012-10-20 14:20:52 +00:00
/**
* all rooms in the current installation
2013-01-19 19:36:40 +00:00
* @var array<\chat\data\room\Room>
2012-10-20 14:20:52 +00:00
*/
2011-12-18 15:08:51 +00:00
public $rooms = array();
/**
* @see \wcf\page\AbstractPage::$useTemplate
*/
2011-12-18 15:08:51 +00:00
public $useTemplate = false;
/**
* @see \wcf\page\IPage::readData()
2011-12-18 15:08:51 +00:00
*/
public function readData() {
parent::readData();
2013-01-19 19:36:40 +00:00
$this->rooms = data\room\Room::getCache();
2011-12-18 15:08:51 +00:00
2013-01-19 19:36:40 +00:00
$roomID = \chat\util\ChatUtil::readUserData('roomID');
2012-10-20 14:20:52 +00:00
if (!isset($this->rooms[$roomID])) throw new IllegalLinkException();
2012-09-07 20:37:25 +00:00
$this->room = $this->rooms[$roomID];
2011-12-18 15:08:51 +00:00
}
/**
* @see \wcf\page\IPage::show()
*/
public function show() {
parent::show();
@header('Content-type: application/json');
$json = array();
foreach ($this->rooms as $room) {
2011-12-26 11:45:05 +00:00
if (!$room->canEnter()) continue;
2012-10-20 14:20:52 +00:00
2011-12-18 15:08:51 +00:00
$json[] = array(
'title' => WCF::getLanguage()->get($room->title),
'link' => \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
2013-01-19 19:36:40 +00:00
'application' => 'chat',
2011-12-18 15:08:51 +00:00
'object' => $room
)),
'active' => $room->roomID == $this->room->roomID
);
}
echo \wcf\util\JSON::encode($json);
exit;
}
}