1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00
Tims-Chat/files/lib/system/box/RoomListBoxController.class.php

144 lines
3.1 KiB
PHP
Raw Normal View History

2018-08-16 22:30:59 +00:00
<?php
2022-03-04 17:10:24 +00:00
2018-08-16 22:30:59 +00:00
/*
2022-03-04 17:10:24 +00:00
* Copyright (c) 2010-2022 Tim Düsterhus.
2018-08-16 22:30:59 +00:00
*
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
2022-03-04 17:10:24 +00:00
* Change Date: 2026-03-04
2018-08-16 22:30:59 +00:00
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
* or later of the General Public License.
*/
namespace chat\system\box;
2022-03-04 17:10:24 +00:00
use chat\data\room\Room;
use chat\data\room\RoomList;
use chat\page\RoomListPage;
2022-03-04 17:10:24 +00:00
use chat\page\RoomPage;
use wcf\system\box\AbstractDatabaseObjectListBoxController;
use wcf\system\request\LinkHandler;
use wcf\system\request\RequestHandler;
use wcf\system\WCF;
2018-08-16 22:30:59 +00:00
/**
* Dynamic box controller implementation for a list of rooms.
*/
2022-03-04 17:10:24 +00:00
class RoomListBoxController extends AbstractDatabaseObjectListBoxController
{
/**
* @inheritDoc
*/
protected static $supportedPositions = [
'contentBottom',
'contentTop',
'sidebarLeft',
'sidebarRight',
];
/**
* @inheritDoc
*/
protected $conditionDefinition = 'be.bastelstu.chat.box.roomList.condition';
/**
* @var int
*/
protected $activeRoomID;
/**
* @inheritDoc
*/
public function __construct()
{
parent::__construct();
$activeRequest = RequestHandler::getInstance()->getActiveRequest();
if ($activeRequest && $activeRequest->getRequestObject() instanceof RoomPage) {
$this->activeRoomID = $activeRequest->getRequestObject()->room->roomID;
}
}
/**
* Sets the active room ID.
*/
public function setActiveRoomID($activeRoomID)
{
$this->activeRoomID = $activeRoomID;
}
/**
* Returns the active room ID.
*
* @return int
*/
public function getActiveRoomID()
{
return $this->activeRoomID;
}
/**
* @inheritDoc
*/
public function hasLink()
{
return true;
}
/**
* @inheritDoc
*/
public function getLink()
{
return LinkHandler::getInstance()->getControllerLink(RoomListPage::class);
2022-03-04 17:10:24 +00:00
}
/**
* @inheritDoc
*/
protected function getObjectList()
{
return new RoomList();
}
/**
* @inheritDoc
*/
protected function getTemplate()
{
$templateName = 'boxRoomList';
if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') {
$templateName = 'boxRoomListSidebar';
}
return WCF::getTPL()->fetch($templateName, 'chat', [
'boxRoomList' => $this->objectList,
'boxID' => $this->getBox()->boxID,
'activeRoomID' => $this->activeRoomID ?: 0,
], true);
}
/**
* @inheritDoc
*/
public function hasContent()
{
if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') {
parent::hasContent();
foreach ($this->objectList as $room) {
if ($room->canSee()) {
return true;
}
}
return false;
} else {
return Room::canSeeAny();
}
}
2018-08-16 22:30:59 +00:00
}