register('title'); I18nHandler::getInstance()->register('topic'); $this->aclObjectTypeID = ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room'); } /** * @inheritDoc */ public function readFormParameters() { parent::readFormParameters(); // read i18n values I18nHandler::getInstance()->readValues(); // handle i18n plain input 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['userLimit'])) { $this->userLimit = \intval($_POST['userLimit']); } if (isset($_POST['topicUseHtml'])) { $this->topicUseHtml = true; } } /** * @inheritDoc */ public function validate() { parent::validate(); // validate title if (!I18nHandler::getInstance()->validateValue('title')) { if (I18nHandler::getInstance()->isPlainValue('title')) { throw new UserInputException('title'); } else { throw new UserInputException('title', 'multilingual'); } } // validate topic if (!I18nHandler::getInstance()->validateValue('topic', false, true)) { throw new UserInputException('topic'); } if (\mb_strlen($this->topic) > 10000) { throw new UserInputException('topic', 'tooLong'); } if ($this->userLimit < 0) { throw new UserInputException('userLimit', 'negative'); } } /** * @inheritDoc */ public function save() { parent::save(); $fields = [ 'title' => $this->title, 'topic' => $this->topic, 'topicUseHtml' => (int)$this->topicUseHtml, 'userLimit' => $this->userLimit, 'position' => 0, // TODO ]; // create room $this->objectAction = new RoomAction( [ ], 'create', [ 'data' => \array_merge( $this->additionalFields, $fields ), ] ); $returnValues = $this->objectAction->executeAction(); // save i18n values $this->saveI18nValue( $returnValues['returnValues'], [ 'title', 'topic', ] ); // save ACL ACLHandler::getInstance()->save($returnValues['returnValues']->roomID, $this->aclObjectTypeID); $this->saved(); // reset values $this->title = $this->topic = ''; $this->userLimit = 0; $this->topicUseHtml = false; I18nHandler::getInstance()->reset(); ACLHandler::getInstance()->disableAssignVariables(); // show success message WCF::getTPL()->assign('success', true); } /** * Saves i18n values. * * @param Room $room * @param string[] $columns */ public function saveI18nValue(Room $room, $columns) { $data = [ ]; foreach ($columns as $columnName) { $languageItem = 'chat.room.room' . $room->roomID . '.' . $columnName; if (I18nHandler::getInstance()->isPlainValue($columnName)) { if ($room->{$columnName} === $languageItem) { I18nHandler::getInstance()->remove($languageItem); } } else { $packageID = PackageCache::getInstance()->getPackageID('be.bastelstu.chat'); I18nHandler::getInstance()->save( $columnName, $languageItem, 'chat.room', $packageID ); $data[$columnName] = $languageItem; } } if (!empty($data)) { (new RoomEditor($room))->update($data); } } /** * @inheritDoc */ public function assignVariables() { parent::assignVariables(); ACLHandler::getInstance()->assignVariables($this->aclObjectTypeID); I18nHandler::getInstance()->assignVariables(); WCF::getTPL()->assign([ 'action' => 'add', 'aclObjectTypeID' => $this->aclObjectTypeID, 'userLimit' => $this->userLimit, 'topicUseHtml' => $this->topicUseHtml, ]); } }