1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

PHPDoc and bugfixes

This commit is contained in:
Tim Düsterhus 2012-10-20 16:23:00 +02:00
parent d1101fe101
commit 0dc39c9df9
9 changed files with 56 additions and 16 deletions

View File

@ -46,6 +46,7 @@ public function __toString() {
/**
* Returns the formatted message.
*
* @param string $outputType outputtype for messageparser
* @return string
*/
public function getFormattedMessage($outputType = 'text/html') {

View File

@ -41,6 +41,7 @@ public function __toString() {
/**
* Returns whether the user is allowed to enter the room.
*
* @param \wcf\data\user\User $user
* @return boolean
*/
public function canEnter(\wcf\data\user\User $user = null) {
@ -70,6 +71,7 @@ public function canEnter(\wcf\data\user\User $user = null) {
/**
* Returns whether the user is allowed to write messages in this room.
*
* @param \wcf\data\user\User $user
* @return boolean
*/
public function canWrite(\wcf\data\user\User $user = null) {

View File

@ -52,7 +52,6 @@ public function didInit() {
/**
* Default-Receiver: Everyone
*
* @return null
* @see \wcf\system\chat\command\ICommand::getReceiver()
*/
public function getReceiver() {

View File

@ -18,6 +18,11 @@ public function __construct(CommandHandler $commandHandler) {
$this->checkPermission();
}
/**
* Fires checkPermission event.
*
* @see \wcf\system\chat\command\IRestrictedCommand
*/
public function checkPermission() {
EventHandler::getInstance()->fireAction($this, 'checkPermission');
}

View File

@ -12,7 +12,16 @@
* @subpackage system.chat.command
*/
final class CommandHandler {
/**
* char that indicates a command
* @var string
*/
const COMMAND_CHAR = '/';
/**
* message text
* @var string
*/
private $text = '';
/**
@ -29,7 +38,8 @@ public function __construct($text) {
*/
public function isCommand($text = null) {
if ($text === null) $text = $this->text;
return StringUtil::substring($text, 0, StringUtil::length(static::COMMAND_CHAR)) == static::COMMAND_CHAR;
return StringUtil::startsWith($text, static::COMMAND_CHAR);
}
/**

View File

@ -11,5 +11,10 @@
* @subpackage system.chat.command
*/
interface IRestrictedCommand {
function checkPermission();
/**
* Checks the permission to use this command. Has to throw
* \wcf\system\exception\PermissionDeniedException when the
* user is not allowed to use the command.
*/
public function checkPermission();
}

View File

@ -11,12 +11,21 @@
* @subpackage system.chat.command
*/
class UserNotFoundException extends \Exception {
/**
* given username
* @var string
*/
private $username = '';
public function __construct($username) {
$this->username = $username;
}
/**
* Returns the given username
*
* @return string
*/
public function getUsername() {
return $this->username;
}

View File

@ -1,6 +1,7 @@
<?php
namespace wcf\system\chat\command\commands;
use \wcf\data\user\User;
use \wcf\system\WCF;
use \wcf\util\ChatUtil;
/**
@ -35,6 +36,13 @@ public function __construct(\wcf\system\chat\command\CommandHandler $commandHand
$this->didInit();
}
/**
* @see \wcf\system\chat\command\IRestrictedChatCommand::checkPermission()
*/
public function checkPermission() {
WCF::getSession()->checkPermission('mod.chat.canRestore');
}
/**
* @see \wcf\system\chat\command\ICommand::getType()
*/
@ -48,11 +56,4 @@ public function getType() {
public function getMessage() {
return 'restored '.$this->link;
}
/**
* @see \wcf\system\chat\command\ICommand::getReceiver()
*/
public function getReceiver() {
return \wcf\system\WCF::getUser()->userID;
}
}

View File

@ -15,13 +15,21 @@
* @subpackage system.chat.permissions
*/
class ChatPermissionHandler {
/**
* permissions set for the active user
* @var array<boolean>
*/
protected $chatPermissions = array();
protected $user = null, $userProfile = null;
/**
* given user decorated in a user profile
* @var \wcf\data\user\UserProfile
*/
protected $user = null;
public function __construct(\wcf\data\user\User $user = null) {
if ($user === null) $user = WCF::getUser();
$this->user = $user;
$this->userProfile = new \wcf\data\user\UserProfile($this->user);
$this->user = new \wcf\data\user\UserProfile($this->user);
$packageID = \wcf\util\ChatUtil::getPackageID();
$ush = \wcf\system\user\storage\UserStorageHandler::getInstance();
@ -86,7 +94,7 @@ public function getPermission(\wcf\data\chat\room\ChatRoom $room, $permission) {
if (!isset($this->chatPermissions[$room->roomID][$permission])) {
$permission = str_replace(array('user.', 'mod.'), array('user.chat.', 'mod.chat.'), $permission);
return $this->userProfile->getPermission($permission);
return $this->user->getPermission($permission);
}
return (boolean) $this->chatPermissions[$room->roomID][$permission];
}