1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-11-09 15:20:08 +00:00
Tims-Chat/files/lib/acp/page/SuspensionListPage.class.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

251 lines
6.4 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\acp\page;
2022-03-04 17:10:24 +00:00
use chat\data\room\Room;
use chat\data\room\RoomList;
use chat\data\suspension\Suspension;
use chat\data\suspension\SuspensionList;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\user\User;
use wcf\page\SortablePage;
use wcf\system\cache\runtime\UserRuntimeCache;
use wcf\system\WCF;
use wcf\util\StringUtil;
2018-08-16 22:30:59 +00:00
/**
* Shows the suspension list.
*/
2022-03-04 17:10:24 +00:00
class SuspensionListPage extends SortablePage
{
/**
* @inheritDoc
*/
public $activeMenuItem = 'chat.acp.menu.link.suspension.list';
/**
* @inheritDoc
*/
public $neededPermissions = [
'admin.chat.canManageSuspensions',
];
/**
* @inheritDoc
*/
public $objectListClassName = SuspensionList::class;
/**
* @inheritDoc
*/
public $validSortFields = [
'suspensionID',
'time',
'expires',
'revoked',
];
/**
* @inheritDoc
*/
public $defaultSortField = 'expiresSort';
/**
* @inheritDoc
*/
public $defaultSortOrder = 'DESC';
/**
* userID filter
* @var int
*/
public $userID;
/**
* roomID filter
* @var int
*/
public $roomID;
/**
* objectTypeID filter
* @var int
*/
public $objectTypeID;
/**
* judgeID filter
* @var int
*/
public $judgeID;
/**
* Whether to show expired entries
* @var boolean
*/
public $showExpired = true;
/**
* username filter
* @var string
*/
public $searchUsername;
/**
* judge's username filter
* @var string
*/
public $searchJudge;
/**
* Array of available suspension object types
* @var array
*/
public $availableObjectTypes = [ ];
/**
* Array of available chat rooms
* @var array
*/
public $availableRooms = [ ];
/**
* @inheritDoc
*/
public function readParameters()
{
parent::readParameters();
if (isset($_REQUEST['roomID']) && $_REQUEST['roomID'] !== '') {
$this->roomID = \intval($_REQUEST['roomID']);
}
if (isset($_REQUEST['userID']) && $_REQUEST['userID'] !== '') {
$this->userID = \intval($_REQUEST['userID']);
}
if (isset($_REQUEST['judgeID']) && $_REQUEST['judgeID'] !== '') {
$this->judgeID = \intval($_REQUEST['judgeID']);
}
if (isset($_REQUEST['objectTypeID']) && $_REQUEST['objectTypeID'] !== '') {
$this->objectTypeID = \intval($_REQUEST['objectTypeID']);
}
// Checkboxes need special handling
if (!empty($_POST) && !isset($_POST['showExpired'])) {
$this->showExpired = false;
}
if (isset($_POST['searchUsername'])) {
$this->searchUsername = StringUtil::trim($_POST['searchUsername']);
if (!empty($this->searchUsername)) {
$this->userID = User::getUserByUsername($this->searchUsername)->userID;
}
} elseif ($this->userID !== null) {
$this->searchUsername = (new User($this->userID))->username;
}
if (isset($_POST['searchJudge'])) {
$this->searchJudge = StringUtil::trim($_POST['searchJudge']);
if (!empty($this->searchJudge)) {
$this->judgeID = User::getUserByUsername($this->searchJudge)->userID;
}
} elseif ($this->judgeID !== null) {
$this->searchJudge = (new User($this->judgeID))->username;
}
}
/**
* @inheritDoc
*/
public function readData()
{
$this->availableObjectTypes = ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.suspension');
$roomList = new RoomList();
$roomList->sqlOrderBy = "room.position";
$roomList->readObjects();
$this->availableRooms = $roomList->getObjects();
parent::readData();
UserRuntimeCache::getInstance()->cacheObjectIDs(\array_map(static function (Suspension $s) {
return $s->userID;
}, $this->objectList->getObjects()));
}
/**
* @inheritDoc
*/
protected function initObjectList()
{
parent::initObjectList();
$this->objectList->sqlSelects .= 'COALESCE(suspension.revoked, suspension.expires, 2147483647) AS expiresSort';
if (!empty($this->availableRooms)) {
$this->objectList->getConditionBuilder()->add('(roomID IN (?) OR roomID IS NULL)', [ \array_map(static function (Room $room) {
return $room->roomID;
}, $this->availableRooms) ]);
} else {
$this->objectList->getConditionBuilder()->add('1 = 0');
}
if ($this->userID !== null) {
$this->objectList->getConditionBuilder()->add('userID = ?', [ $this->userID ]);
}
if ($this->roomID !== null) {
if ($this->roomID === 0) {
$this->objectList->getConditionBuilder()->add('roomID IS NULL');
} else {
$this->objectList->getConditionBuilder()->add('roomID = ?', [ $this->roomID ]);
}
}
if ($this->objectTypeID !== null) {
$this->objectList->getConditionBuilder()->add('objectTypeID = ?', [ $this->objectTypeID ]);
}
if ($this->judgeID !== null) {
$this->objectList->getConditionBuilder()->add('judgeID = ?', [ $this->judgeID ]);
}
if ($this->showExpired === false) {
$this->objectList->getConditionBuilder()->add('expires >= ?', [ TIME_NOW ]);
}
}
/**
* @inheritDoc
*/
public function assignVariables()
{
parent::assignVariables();
WCF::getTPL()->assign([
'userID' => $this->userID,
'roomID' => $this->roomID,
'objectTypeID' => $this->objectTypeID,
'judgeID' => $this->judgeID,
'availableRooms' => $this->availableRooms,
'availableObjectTypes' => $this->availableObjectTypes,
'searchUsername' => $this->searchUsername,
'searchJudge' => $this->searchJudge,
'showExpired' => $this->showExpired,
]);
}
2018-08-16 22:30:59 +00:00
}