From 16643a4ed36cf1eac07da4fb37e3bdb41e262696 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sat, 10 Jan 2015 00:42:32 +0100 Subject: [PATCH 1/9] Add maxUsers column to room database definition --- install.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sql b/install.sql index 66d416b..91df76c 100644 --- a/install.sql +++ b/install.sql @@ -38,6 +38,7 @@ CREATE TABLE chat1_room ( showOrder INT(10) NOT NULL DEFAULT 0, permanent TINYINT(1) NOT NULL DEFAULT 1, owner INT(10) DEFAULT NULL, + maxUsers INT(10) NOT NULL DEFAULT 0 KEY (showOrder), KEY (owner) From 8c68694c008c41ce1efe93af6e948eccfdb7a745 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sat, 10 Jan 2015 00:43:51 +0100 Subject: [PATCH 2/9] Add possibility to define maxUsers in RoomAddForm --- file/lib/acp/form/RoomAddForm.class.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/file/lib/acp/form/RoomAddForm.class.php b/file/lib/acp/form/RoomAddForm.class.php index 76f3c56..f875891 100644 --- a/file/lib/acp/form/RoomAddForm.class.php +++ b/file/lib/acp/form/RoomAddForm.class.php @@ -38,6 +38,13 @@ class RoomAddForm extends \wcf\form\AbstractForm { */ public $topic = ''; + /** + * Maximum number of users + * + * @var integer + */ + public $maxUsers = 0; + /** * @see \wcf\page\AbstractPage::__construct() */ @@ -67,6 +74,7 @@ public function readFormParameters() { if (I18nHandler::getInstance()->isPlainValue('title')) $this->title = I18nHandler::getInstance()->getValue('title'); if (I18nHandler::getInstance()->isPlainValue('topic')) $this->topic = I18nHandler::getInstance()->getValue('topic'); + if (isset($_POST['maxUsers']) $this->maxUsers = intval($_POST['maxUsers']); } /** @@ -90,7 +98,8 @@ public function save() { // save room $this->objectAction = new \chat\data\room\RoomAction(array(), 'create', array('data' => array_merge($this->additionalFields, array( 'title' => $this->title, - 'topic' => $this->topic + 'topic' => $this->topic, + 'maxUsers' => $this->maxUsers )))); $this->objectAction->executeAction(); $returnValues = $this->objectAction->getReturnValues(); @@ -116,7 +125,7 @@ public function save() { } \wcf\system\acl\ACLHandler::getInstance()->save($roomID, $this->objectTypeID); - \wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables(); + \wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables(); \chat\system\permission\PermissionHandler::clearCache(); $this->saved(); @@ -144,6 +153,7 @@ public function assignVariables() { 'action' => 'add', 'title' => $this->title, 'topic' => $this->topic, + 'maxUsers' => $this->maxUsers, 'objectTypeID' => $this->objectTypeID )); } From 418443bb45d413485708e4206d48795b5003180e Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sat, 10 Jan 2015 00:45:16 +0100 Subject: [PATCH 3/9] Update RoomEditForm according to RoomAddForm --- file/lib/acp/form/RoomEditForm.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/file/lib/acp/form/RoomEditForm.class.php b/file/lib/acp/form/RoomEditForm.class.php index 44381b3..f8aa15e 100644 --- a/file/lib/acp/form/RoomEditForm.class.php +++ b/file/lib/acp/form/RoomEditForm.class.php @@ -83,13 +83,14 @@ public function save() { } \wcf\system\acl\ACLHandler::getInstance()->save($this->roomID, $this->objectTypeID); - \wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables(); + \wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables(); \chat\system\permission\PermissionHandler::clearCache(); // update room $this->objectAction = new \chat\data\room\RoomAction(array($this->roomID), 'update', array('data' => array_merge($this->additionalFields, array( 'title' => $this->title, - 'topic' => $this->topic + 'topic' => $this->topic, + 'maxUsers' => $this->maxUsers )))); $this->objectAction->executeAction(); @@ -113,6 +114,7 @@ public function readData() { $this->title = $this->roomObj->title; $this->topic = $this->roomObj->topic; + $this->maxUsers = $this->roomObj->maxUsers; } } From f5edd746427d6086b603d5112ab6c8f82722d16c Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sat, 10 Jan 2015 00:46:14 +0100 Subject: [PATCH 4/9] Add input for maxUsers to roomAdd.tpl --- acptemplate/roomAdd.tpl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/acptemplate/roomAdd.tpl b/acptemplate/roomAdd.tpl index 0946c98..7414a6c 100644 --- a/acptemplate/roomAdd.tpl +++ b/acptemplate/roomAdd.tpl @@ -71,6 +71,22 @@ {include file='multipleLanguageInputJavascript' elementIdentifier='topic' forceSelection=false} + +
+
+ + {if $errorField == 'topic'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}chat.acp.room.topic.error.{@$errorType}{/lang} + {/if} + + {/if} +
+ +
{lang}wcf.acl.permissions{/lang}
From 48976d793b5b1f1b569f855b267b05f1275473dc Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sat, 10 Jan 2015 00:47:08 +0100 Subject: [PATCH 5/9] Implement maxUsers in RoomAction --- file/lib/data/room/RoomAction.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/file/lib/data/room/RoomAction.class.php b/file/lib/data/room/RoomAction.class.php index 8ba22aa..dd9e4bd 100644 --- a/file/lib/data/room/RoomAction.class.php +++ b/file/lib/data/room/RoomAction.class.php @@ -147,6 +147,7 @@ public function getRoomList() { 'roomID' => (int) $room->roomID, 'active' => $this->parameters['room'] && $room->roomID == $this->parameters['room']->roomID, 'userCount' => count($room->getUsers()), + 'maxUsers' => (int) $room->maxUsers, 'permissions' => array( 'canBan' => (boolean) $room->canBan(), 'canMute' => (boolean) $room->canMute() @@ -169,6 +170,12 @@ public function validateJoin() { $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); if ($room === null) throw new exception\UserInputException('roomID'); if (!$room->canEnter()) throw new exception\PermissionDeniedException(); + + if ($room->maxUsers && count($room->getUsers()) >= $room->maxUsers) { + $errorMessage = WCF::getLanguage()->getDynamicVariable('chat.global.error.join.full', array('room' => $room)); + + throw new exception\UserInputException('room', $errorMessage); + } } /** @@ -260,6 +267,7 @@ public function join() { )), 'roomID' => (int) $room->roomID, 'userCount' => count($room->getUsers()), + 'maxUsers' => (int) $room->maxUsers, 'permissions' => array( 'canBan' => (boolean) $room->canBan(), 'canMute' => (boolean) $room->canMute() From 1e3852f5ae125b2f2bc227c9a5c38b81f0ff9527 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sat, 10 Jan 2015 00:47:49 +0100 Subject: [PATCH 6/9] Check for maxUsers in chat.tpl --- template/chat.tpl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/template/chat.tpl b/template/chat.tpl index 18cfe0a..e03b339 100644 --- a/template/chat.tpl +++ b/template/chat.tpl @@ -4,7 +4,7 @@ {if $room}{$room} - {/if}{lang}chat.global.title{/lang} - {PAGE_TITLE|language} {include file='headInclude'} - {if $room} + {if $room && (!$room->maxUsers || $room->getUsers()|count < $room->maxUsers)} {include file='javascriptInclude' application='chat'}