1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00
Tims-Chat/file/lib/system/command/AbstractUnsuspensionCommand.class.php

94 lines
2.8 KiB
PHP
Raw Normal View History

2013-06-22 15:11:22 +00:00
<?php
namespace chat\system\command;
use \chat\data\suspension;
use \chat\util\ChatUtil;
use \wcf\data\user\User;
use \wcf\system\WCF;
/**
* Default implementation for suspension commands
2014-02-28 16:06:50 +00:00
*
2013-06-22 15:11:22 +00:00
* @author Tim Düsterhus
2014-02-27 22:05:09 +00:00
* @copyright 2010-2014 Tim Düsterhus
2013-06-22 15:11:22 +00:00
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @package be.bastelstu.chat
* @subpackage system.chat.command
*/
abstract class AbstractUnsuspensionCommand extends AbstractRestrictedCommand {
public $user = null;
public $suspensionAction = null;
public $link = '';
public $room = null;
public function __construct(\chat\system\command\CommandHandler $commandHandler) {
parent::__construct($commandHandler);
$username = rtrim($commandHandler->getParameters(), ',');
$this->user = User::getUserByUsername($username);
if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException($username);
$profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
'object' => $this->user
));
$this->link = "[url='".$profile."']".$this->user->username.'[/url]';
$this->executeAction();
$this->didInit();
}
public function executeAction() {
if (static::IS_GLOBAL) $room = new \chat\data\room\Room(null, array('roomID' => null));
else $room = $this->room;
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, static::SUSPENSION_TYPE)) {
$action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
'revoker' => WCF::getUser()->userID
));
$action->executeAction();
}
else {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('chat.suspension.notExists'));
2013-06-22 15:11:22 +00:00
}
}
/**
* @see \chat\system\command\IRestrictedChatCommand::checkPermission()
*/
public function checkPermission() {
parent::checkPermission();
2013-06-22 16:28:50 +00:00
$this->room = $this->commandHandler->getRoom();
2013-06-22 15:57:33 +00:00
if (WCF::getSession()->getPermission('admin.chat.canManageSuspensions')) return;
2013-06-22 15:11:22 +00:00
$ph = new \chat\system\permission\PermissionHandler();
2013-06-22 15:57:33 +00:00
if (static::IS_GLOBAL) {
WCF::getSession()->checkPermissions(array('mod.chat.canG'.static::SUSPENSION_TYPE));
2013-06-22 15:57:33 +00:00
}
else {
2013-06-22 16:28:50 +00:00
if (!WCF::getSession()->getPermission('mod.chat.canG'.static::SUSPENSION_TYPE)) {
2013-06-22 15:57:33 +00:00
if (!$ph->getPermission($this->room, 'mod.can'.ucfirst(static::SUSPENSION_TYPE))) {
throw new \wcf\system\exception\PermissionDeniedException();
}
}
}
2013-06-22 15:11:22 +00:00
}
/**
* @see \chat\system\command\ICommand::getType()
*/
public function getType() {
return \chat\data\message\Message::TYPE_MODERATE;
}
/**
* @see \chat\system\command\ICommand::getMessage()
*/
public function getMessage() {
return serialize(array(
'link' => $this->link,
2013-06-22 15:40:24 +00:00
'type' => 'un'.(static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE,
2013-06-22 15:11:22 +00:00
));
}
}