From 2c1d016d411ba2f390dd44d88ca8a0aeefc34654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 23 Apr 2013 16:16:27 +0200 Subject: [PATCH] Show suspensions in InfoCommand --- file/lib/data/room/Room.class.php | 8 ++++---- file/lib/data/suspension/Suspension.class.php | 5 +++-- file/lib/data/suspension/SuspensionAction.class.php | 3 ++- .../lib/system/command/commands/InfoCommand.class.php | 11 +++++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/file/lib/data/room/Room.class.php b/file/lib/data/room/Room.class.php index 248d03e..9464afa 100644 --- a/file/lib/data/room/Room.class.php +++ b/file/lib/data/room/Room.class.php @@ -45,14 +45,14 @@ public function canEnter(\wcf\data\user\User $user = null) { $canEnter = $ph->getPermission($this, 'user.canEnter'); // room suspension if ($canEnter && isset($suspensions[$this->roomID][Suspension::TYPE_BAN])) { - if ($suspensions[$this->roomID][Suspension::TYPE_BAN]['time'] > TIME_NOW) { + if ($suspensions[$this->roomID][Suspension::TYPE_BAN]->time > TIME_NOW) { $canEnter = false; } } // global suspension if ($canEnter && isset($suspensions[null][Suspension::TYPE_BAN])) { - if ($suspensions[null][Suspension::TYPE_BAN]['time'] > TIME_NOW) { + if ($suspensions[null][Suspension::TYPE_BAN]->time > TIME_NOW) { $canEnter = false; } } @@ -75,14 +75,14 @@ public function canWrite(\wcf\data\user\User $user = null) { $canWrite = $ph->getPermission($this, 'user.canWrite'); // room suspension if ($canWrite && isset($suspensions[$this->roomID][Suspension::TYPE_MUTE])) { - if ($suspensions[$this->roomID][Suspension::TYPE_MUTE]['time'] > TIME_NOW) { + if ($suspensions[$this->roomID][Suspension::TYPE_MUTE]->time > TIME_NOW) { $canWrite = false; } } // global suspension if ($canWrite && isset($suspensions[null][Suspension::TYPE_MUTE])) { - if ($suspensions[null][Suspension::TYPE_MUTE]['time'] > TIME_NOW) { + if ($suspensions[null][Suspension::TYPE_MUTE]->time > TIME_NOW) { $canWrite = false; } } diff --git a/file/lib/data/suspension/Suspension.class.php b/file/lib/data/suspension/Suspension.class.php index 4fba51c..ccf65d5 100644 --- a/file/lib/data/suspension/Suspension.class.php +++ b/file/lib/data/suspension/Suspension.class.php @@ -28,6 +28,7 @@ class Suspension extends \chat\data\CHATDatabaseObject { public static function getSuspensionsForUser(\wcf\data\user\User $user = null) { if ($user === null) $user = WCF::getUser(); $suspensions = \chat\util\ChatUtil::readUserData('suspensions', $user); + if ($suspensions === null) { $sql = "SELECT * @@ -40,8 +41,8 @@ public static function getSuspensionsForUser(\wcf\data\user\User $user = null) { $stmt->execute(array($user->userID, TIME_NOW)); $suspensions = array(); - while ($row = $stmt->fetchArray()) { - $suspensions[$row['roomID']][$row['type']] = $row; + while ($suspension = $stmt->fetchObject('\chat\data\suspension\Suspension')) { + $suspensions[$suspension->roomID][$suspension->type] = $suspension; } \chat\util\ChatUtil::writeUserData(array('suspensions' => $suspensions), $user); diff --git a/file/lib/data/suspension/SuspensionAction.class.php b/file/lib/data/suspension/SuspensionAction.class.php index e68fa06..71968eb 100644 --- a/file/lib/data/suspension/SuspensionAction.class.php +++ b/file/lib/data/suspension/SuspensionAction.class.php @@ -31,7 +31,8 @@ public function prune() { $stmt = \wcf\system\WCF::getDB()->prepareStatement($sql); $stmt->execute(array(TIME_NOW)); $objectIDs = array(); - while ($objectIDs[] = $stmt->fetchColumn()); + + while ($objectID = $stmt->fetchColumn()) $objectIDs[] = $objectID; return call_user_func(array($this->className, 'deleteAll'), $objectIDs); } diff --git a/file/lib/system/command/commands/InfoCommand.class.php b/file/lib/system/command/commands/InfoCommand.class.php index 2d0fbc9..637d5bf 100644 --- a/file/lib/system/command/commands/InfoCommand.class.php +++ b/file/lib/system/command/commands/InfoCommand.class.php @@ -3,6 +3,7 @@ use \chat\util\ChatUtil; use \wcf\data\user\User; use \wcf\system\WCF; +use \wcf\util\DateUtil; use \wcf\util\StringUtil; /** @@ -42,6 +43,16 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler) $this->lines[WCF::getLanguage()->get('wcf.chat.room')] = $room->getTitle(); } + // Suspensions + // TODO: Permissions + $suspensions = \chat\data\suspension\Suspension::getSuspensionsForUser($this->user); + foreach ($suspensions as $roomSuspensions) { + foreach ($roomSuspensions as $typeSuspension) { + $dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->time); + $this->lines[$typeSuspension->type.'-'.$typeSuspension->roomID] = str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat'))); + } + } + // ip address if (WCF::getSession()->getPermission('admin.user.canViewIpAddress')) { $session = $this->fetchSession();