1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2025-01-02 23:20:08 +00:00

Add optional reasons to suspensions

Also use $pageLinks in chatSuspension.tpl
and add the missing name to testrooms name
This commit is contained in:
Maximilian Mader 2013-06-22 02:19:52 +02:00
parent eb27166c6c
commit 3028edba7d
7 changed files with 29 additions and 65 deletions

View File

@ -84,6 +84,7 @@
<th class="columnTime{if $sortField == 'time'} active {@$sortOrder}{/if}"><a href="{link application='chat' controller='ChatSuspensionList'}pageNo={@$pageNo}&sortField=time&sortOrder={if $sortField == 'time' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}chat.general.time{/lang}</a></th> <th class="columnTime{if $sortField == 'time'} active {@$sortOrder}{/if}"><a href="{link application='chat' controller='ChatSuspensionList'}pageNo={@$pageNo}&sortField=time&sortOrder={if $sortField == 'time' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}chat.general.time{/lang}</a></th>
<th class="columnExpires{if $sortField == 'expires'} active {@$sortOrder}{/if}"><a href="{link application='chat' controller='ChatSuspensionList'}pageNo={@$pageNo}&sortField=expires&sortOrder={if $sortField == 'expires' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}chat.general.expires{/lang}</a></th> <th class="columnExpires{if $sortField == 'expires'} active {@$sortOrder}{/if}"><a href="{link application='chat' controller='ChatSuspensionList'}pageNo={@$pageNo}&sortField=expires&sortOrder={if $sortField == 'expires' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}chat.general.expires{/lang}</a></th>
<th class="columnIssuer{if $sortField == 'issuer'} active {@$sortOrder}{/if}"><a href="{link application='chat' controller='ChatSuspensionList'}pageNo={@$pageNo}&sortField=issuer&sortOrder={if $sortField == 'issuer' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}chat.acp.suspension.issuer{/lang}</a></th> <th class="columnIssuer{if $sortField == 'issuer'} active {@$sortOrder}{/if}"><a href="{link application='chat' controller='ChatSuspensionList'}pageNo={@$pageNo}&sortField=issuer&sortOrder={if $sortField == 'issuer' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}chat.acp.suspension.issuer{/lang}</a></th>
<th class="columnMessage{if $sortField == 'reason'} active {@$sortOrder}{/if}"><a href="{link application='chat' controller='ChatSuspensionList'}pageNo={@$pageNo}&sortField=reason&sortOrder={if $sortField == 'reason' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}chat.acp.suspension.reason{/lang}</a></th>
</tr> </tr>
</thead> </thead>
@ -97,6 +98,7 @@
<td id="columnTime">{$suspension->time|plainTime}</td> <td id="columnTime">{$suspension->time|plainTime}</td>
<td id="columnExpires">{$suspension->expires|plainTime} ({$suspension->expires|dateDiff})</td> <td id="columnExpires">{$suspension->expires|plainTime} ({$suspension->expires|dateDiff})</td>
<td id="columnIssuer"><a href="{link application='chat' controller='ChatSuspensionList'}issuerUserID={$suspension->issuer}{/link}">{$suspension->issuerUsername}</a></td> <td id="columnIssuer"><a href="{link application='chat' controller='ChatSuspensionList'}issuerUserID={$suspension->issuer}{/link}">{$suspension->issuerUsername}</a></td>
<td id="columnMessage" {if $suspension->reason != $suspension->reason|truncate:30} class="jsTooltip" title="{$suspension->reason}"{/if}>{$suspension->reason|truncate:30}</a></td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>
@ -104,7 +106,7 @@
</div> </div>
<div class="contentNavigation"> <div class="contentNavigation">
{pages print=true assign=pagesLinks application="chat" controller="ChatSuspensionList" link="pageNo=%d&username=$username&issuerUsername=$issuerUsername&roomID=$roomID&suspensionType=$suspensionType"} {@$pagesLinks}
</div> </div>
{else} {else}
<p class="info">{lang}wcf.global.noItems{/lang}</p> <p class="info">{lang}wcf.global.noItems{/lang}</p>

View File

@ -31,7 +31,7 @@ class ChatSuspensionListPage extends \wcf\page\SortablePage {
/** /**
* @see \wcf\page\SortablePage::$validSortFields * @see \wcf\page\SortablePage::$validSortFields
*/ */
public $validSortFields = array('suspensionID', 'userID', 'username', 'roomID', 'type', 'expires', 'issuer', 'time'); public $validSortFields = array('suspensionID', 'userID', 'username', 'roomID', 'type', 'expires', 'issuer', 'time', 'reason');
/** /**
* @see \wcf\page\MultipleLinkPage::$objectListClassName * @see \wcf\page\MultipleLinkPage::$objectListClassName

View File

@ -1,9 +1,6 @@
<?php <?php
namespace chat\system\command\commands; namespace chat\system\command\commands;
use \chat\data\suspension; use \chat\data\suspension;
use \chat\util\ChatUtil;
use \wcf\data\user\User;
use \wcf\system\WCF;
/** /**
* Bans a user. * Bans a user.
@ -15,26 +12,5 @@
* @subpackage system.chat.command.commands * @subpackage system.chat.command.commands
*/ */
class BanCommand extends MuteCommand { class BanCommand extends MuteCommand {
public function executeAction() { const SUSPENSION_TYPE = suspension\Suspension::TYPE_BAN;
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_BAN)) {
if ($suspension->expires > $this->expires) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
}
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action->executeAction();
}
$this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array(
'data' => array(
'userID' => $this->user->userID,
'roomID' => WCF::getUser()->chatRoomID,
'type' => suspension\Suspension::TYPE_BAN,
'expires' => $this->expires,
'time' => TIME_NOW,
'issuer' => WCF::getUser()->userID
)
));
$this->suspensionAction->executeAction();
}
} }

View File

@ -1,9 +1,6 @@
<?php <?php
namespace chat\system\command\commands; namespace chat\system\command\commands;
use \chat\data\suspension; use \chat\data\suspension;
use \chat\util\ChatUtil;
use \wcf\data\user\User;
use \wcf\system\WCF;
/** /**
* Globally bans a user. * Globally bans a user.
@ -14,29 +11,6 @@
* @package be.bastelstu.chat * @package be.bastelstu.chat
* @subpackage system.chat.command.commands * @subpackage system.chat.command.commands
*/ */
class GbanCommand extends MuteCommand { class GbanCommand extends GmuteCommand {
public function executeAction() { const SUSPENSION_TYPE = suspension\Suspension::TYPE_BAN;
$room = new \chat\data\room\Room(null, array('roomID' => null));
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_BAN)) {
if ($suspension->expires > $this->expires) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
}
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action->executeAction();
}
$this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array(
'data' => array(
'userID' => $this->user->userID,
'roomID' => null,
'type' => suspension\Suspension::TYPE_BAN,
'expires' => $this->expires,
'time' => TIME_NOW,
'issuer' => WCF::getUser()->userID
)
));
$this->suspensionAction->executeAction();
}
} }

View File

@ -18,8 +18,8 @@ class GmuteCommand extends MuteCommand {
public function executeAction() { public function executeAction() {
$room = new \chat\data\room\Room(null, array('roomID' => null)); $room = new \chat\data\room\Room(null, array('roomID' => null));
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_MUTE)) { if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, static::SUSPENSION_TYPE)) {
if ($suspension->expires > $this->expires) { if ($suspension->expires >= $this->expires) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists')); throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
} }
@ -31,10 +31,11 @@ public function executeAction() {
'data' => array( 'data' => array(
'userID' => $this->user->userID, 'userID' => $this->user->userID,
'roomID' => null, 'roomID' => null,
'type' => suspension\Suspension::TYPE_MUTE, 'type' => self::SUSPENSION_TYPE,
'expires' => $this->expires, 'expires' => $this->expires,
'time' => TIME_NOW, 'time' => TIME_NOW,
'issuer' => WCF::getUser()->userID 'issuer' => WCF::getUser()->userID,
'reason' => $this->reason
) )
)); ));
$this->suspensionAction->executeAction(); $this->suspensionAction->executeAction();

View File

@ -15,17 +15,25 @@
* @subpackage system.chat.command.commands * @subpackage system.chat.command.commands
*/ */
class MuteCommand extends \chat\system\command\AbstractRestrictedCommand { class MuteCommand extends \chat\system\command\AbstractRestrictedCommand {
const SUSPENSION_TYPE = suspension\Suspension::TYPE_MUTE;
public $user = null; public $user = null;
public $expires = 0; public $expires = 0;
public $suspensionAction = null; public $suspensionAction = null;
public $link = ''; public $link = '';
public $room = null; public $room = null;
public $reason = '';
public function __construct(\chat\system\command\CommandHandler $commandHandler) { public function __construct(\chat\system\command\CommandHandler $commandHandler) {
parent::__construct($commandHandler); parent::__construct($commandHandler);
try { try {
list($username, $modifier) = explode(',', $commandHandler->getParameters(), 2); $parameters = explode(',', $commandHandler->getParameters(), 3);
list($username, $modifier) = $parameters;
if (isset($parameters[2])) {
$this->reason = \wcf\util\StringUtil::trim($parameters[2]);
}
$modifier = ChatUtil::timeModifier(\wcf\util\StringUtil::trim($modifier)); $modifier = ChatUtil::timeModifier(\wcf\util\StringUtil::trim($modifier));
$expires = strtotime($modifier, TIME_NOW); $expires = strtotime($modifier, TIME_NOW);
$this->expires = min(max(-0x80000000, $expires), 0x7FFFFFFF); $this->expires = min(max(-0x80000000, $expires), 0x7FFFFFFF);
@ -48,8 +56,8 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
} }
public function executeAction() { public function executeAction() {
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_MUTE)) { if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, static::SUSPENSION_TYPE)) {
if ($suspension->expires > $this->expires) { if ($suspension->expires >= $this->expires) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists')); throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
} }
@ -64,7 +72,8 @@ public function executeAction() {
'type' => suspension\Suspension::TYPE_MUTE, 'type' => suspension\Suspension::TYPE_MUTE,
'expires' => $this->expires, 'expires' => $this->expires,
'time' => TIME_NOW, 'time' => TIME_NOW,
'issuer' => WCF::getUser()->userID 'issuer' => WCF::getUser()->userID,
'reason' => $this->reason
) )
)); ));
$this->suspensionAction->executeAction(); $this->suspensionAction->executeAction();
@ -95,7 +104,8 @@ public function getMessage() {
return serialize(array( return serialize(array(
'link' => $this->link, 'link' => $this->link,
'expires' => $this->expires, 'expires' => $this->expires,
'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this))) 'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this))),
'message' => $this->suspensionMessage
)); ));
} }
} }

View File

@ -50,6 +50,7 @@ CREATE TABLE chat1_suspension (
expires INT(10) NOT NULL, expires INT(10) NOT NULL,
time INT(10) NOT NULL, time INT(10) NOT NULL,
issuer INT(10) DEFAULT NULL, issuer INT(10) DEFAULT NULL,
reason VARCHAR(255) NOT NULL DEFAULT '',
UNIQUE KEY suspension (userID, roomID, type), UNIQUE KEY suspension (userID, roomID, type),
KEY (roomID), KEY (roomID),
@ -78,5 +79,5 @@ ALTER TABLE wcf1_user ADD FOREIGN KEY (chatRoomID) REFERENCES chat1_room (roomID
INSERT INTO chat1_room (title, topic, showOrder) VALUES ('chat.room.title1', 'chat.room.topic1', 1); INSERT INTO chat1_room (title, topic, showOrder) VALUES ('chat.room.title1', 'chat.room.topic1', 1);
INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Testroom 2', 'Topic of Testroom 2', 2); INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Testroom 2', 'Topic of Testroom 2', 2);
INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Testroom with a very long', 'The topic of this room is rather loing as well!', 3); INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Testroom with a very long name', 'The topic of this room is rather loing as well!', 3);
INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Room w/o topic', '', 4); INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Room w/o topic', '', 4);