From 84622365b03d94a351ceadbc0603cdf482e32608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 5 Feb 2012 18:29:16 +0100 Subject: [PATCH] Adding ChatRoomEditForm --- file/lib/acp/form/ChatRoomAddForm.class.php | 13 +- file/lib/acp/form/ChatRoomEditForm.class.php | 130 ++++++++++++++++++ .../data/chat/room/ChatRoomEditor.class.php | 7 +- 3 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 file/lib/acp/form/ChatRoomEditForm.class.php diff --git a/file/lib/acp/form/ChatRoomAddForm.class.php b/file/lib/acp/form/ChatRoomAddForm.class.php index d83cf47..46dd2f6 100644 --- a/file/lib/acp/form/ChatRoomAddForm.class.php +++ b/file/lib/acp/form/ChatRoomAddForm.class.php @@ -16,12 +16,12 @@ */ class ChatRoomAddForm extends ACPForm { /** - * @see wcf\acp\form\ACPForm::$activeMenuItem + * @see \wcf\acp\form\ACPForm::$activeMenuItem */ public $activeMenuItem = 'wcf.acp.menu.link.chat.room.add'; /** - * @see wcf\page\AbstractPage::$neededPermissions + * @see \wcf\page\AbstractPage::$neededPermissions */ public $neededPermissions = array('admin.content.chat.canAddRoom'); @@ -105,21 +105,20 @@ public function save() { $roomID = $returnValues['returnValues']->roomID; if (!I18nHandler::getInstance()->isPlainValue('title')) { - I18nHandler::getInstance()->save('title', 'wcf.chat.room.title.room'.$roomID, 'wcf.chat.room', PackageDependencyHandler::getPackageID('timwolla.wcf.chat')); + I18nHandler::getInstance()->save('title', 'wcf.chat.room.title'.$roomID, 'wcf.chat.room', PackageDependencyHandler::getPackageID('timwolla.wcf.chat')); // update title - $chatRoomEditor->update(array( - 'title' => 'wcf.chat.room.title.room'.$roomID + 'title' => 'wcf.chat.room.title'.$roomID )); } if (!I18nHandler::getInstance()->isPlainValue('topic')) { - I18nHandler::getInstance()->save('title', 'wcf.chat.room.topic.room'.$roomID, 'wcf.chat.room', PackageDependencyHandler::getPackageID('timwolla.wcf.chat')); + I18nHandler::getInstance()->save('topic', 'wcf.chat.room.topic'.$roomID, 'wcf.chat.room', PackageDependencyHandler::getPackageID('timwolla.wcf.chat')); // update topic $chatRoomEditor->update(array( - 'title' => 'wcf.chat.room.topic.room'.$roomID + 'topic' => 'wcf.chat.room.topic'.$roomID )); } diff --git a/file/lib/acp/form/ChatRoomEditForm.class.php b/file/lib/acp/form/ChatRoomEditForm.class.php new file mode 100644 index 0000000..bfebca3 --- /dev/null +++ b/file/lib/acp/form/ChatRoomEditForm.class.php @@ -0,0 +1,130 @@ + + * @package timwolla.wcf.chat + * @subpackage acp.form + */ +class ChatRoomEditForm extends ChatRoomAddForm { + /** + * @see \wcf\page\AbstractPage::$templateName + */ + public $templateName = 'chatRoomAdd'; + + /** + * @see \wcf\acp\form\ACPForm::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.chat.room.list'; + + /** + * @see \wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.content.chat.canEditRoom'); + + /** + * room id + * + * @var integer + */ + public $roomID = 0; + + /** + * room object + * + * @var \wcf\data\chat\room\ChatRoom + */ + public $roomObj = null; + + /** + * @see wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_REQUEST['id'])) $this->roomID = intval($_REQUEST['id']); + $this->roomObj = new \wcf\data\chat\room\ChatRoom($this->roomID); + if (!$this->roomObj->roomID) { + throw new \wcf\system\exception\IllegalLinkException(); + } + } + + /** + * @see wcf\form\IForm::save() + */ + public function save() { + ACPForm::save(); + + $this->title = 'wcf.chat.room.title'.$this->roomObj->roomID; + if (I18nHandler::getInstance()->isPlainValue('title')) { + I18nHandler::getInstance()->remove($this->title, PackageDependencyHandler::getPackageID('timwolla.wcf.chat')); + $this->title = I18nHandler::getInstance()->getValue('title'); + } + else { + I18nHandler::getInstance()->save('title', $this->title, 'wcf.chat.room', PackageDependencyHandler::getPackageID('timwolla.wcf.chat')); + } + + $this->topic = 'wcf.chat.room.topic'.$this->roomObj->roomID; + if (I18nHandler::getInstance()->isPlainValue('topic')) { + I18nHandler::getInstance()->remove($this->topic, PackageDependencyHandler::getPackageID('timwolla.wcf.chat')); + $this->topic = I18nHandler::getInstance()->getValue('topic'); + } + else { + I18nHandler::getInstance()->save('topic', $this->topic, 'wcf.chat.room', PackageDependencyHandler::getPackageID('timwolla.wcf.chat')); + } + + + // update room + $chatRoomAction = new LabelAction(array($this->roomID), 'update', array('data' => array( + 'title' => $this->title, + 'topic' => $this->topic + ))); + $chatRoomAction->executeAction(); + + $this->saved(); + + // show success + WCF::getTPL()->assign(array( + 'success' => true + )); + } + + /** + * @see wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + if (!count($_POST)) { + I18nHandler::getInstance()->setOptions('title', PackageDependencyHandler::getPackageID('timwolla.wcf.chat'), $this->roomObj->title, 'wcf.chat.room.title\d+'); + I18nHandler::getInstance()->setOptions('topic', PackageDependencyHandler::getPackageID('timwolla.wcf.chat'), $this->roomObj->topic, 'wcf.chat.room.topic\d+'); + + $this->title = $this->roomObj->title; + $this->topic = $this->roomObj->topic; + } + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + I18nHandler::getInstance()->assignVariables((bool) count($_POST)); + + WCF::getTPL()->assign(array( + 'roomID' => $this->roomID, + 'action' => 'edit' + )); + } +} \ No newline at end of file diff --git a/file/lib/data/chat/room/ChatRoomEditor.class.php b/file/lib/data/chat/room/ChatRoomEditor.class.php index 27eb607..6450070 100644 --- a/file/lib/data/chat/room/ChatRoomEditor.class.php +++ b/file/lib/data/chat/room/ChatRoomEditor.class.php @@ -31,14 +31,11 @@ public static function resetCache() { public static function deleteAll(array $objectIDs = array()) { parent::deleteAll($objectIDs); $packageID = \wcf\system\package\PackageDependencyHandler::getPackageID('timwolla.wcf.chat'); - $sql = "DELETE FROM wcf".WCF_N."_language_item - WHERE languageItem = ? AND packageID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); WCF::getDB()->beginTransaction(); foreach ($objectIDs as $objectID) { - $statement->execute(array('wcf.chat.room.title.room'.$objectID, $packageID)); - $statement->execute(array('wcf.chat.room.topic.room'.$objectID, $packageID)); + \wcf\system\language\I18nHandler::getInstance()->remove('wcf.chat.room.title'.$objectID, $packageID); + \wcf\system\language\I18nHandler::getInstance()->remove('wcf.chat.room.topic'.$objectID, $packageID); } WCF::getDB()->commitTransaction();