1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-26 22:20:08 +00:00
Tims-Chat/file/lib/acp/form/ChatRoomAddForm.class.php

149 lines
3.7 KiB
PHP
Raw Normal View History

2012-02-04 20:57:39 +00:00
<?php
namespace wcf\acp\form;
use \wcf\system\exception\UserInputException;
use \wcf\system\language\I18nHandler;
use \wcf\system\WCF;
/**
* Shows the chatroom add form.
*
* @author Tim Düsterhus
2012-02-04 20:57:39 +00:00
* @copyright 2010-2012 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @package be.bastelstu.wcf.chat
2012-02-04 20:57:39 +00:00
* @subpackage acp.form
*/
class ChatRoomAddForm extends ACPForm {
/**
* @see \wcf\acp\form\ACPForm::$activeMenuItem
2012-02-04 20:57:39 +00:00
*/
public $activeMenuItem = 'wcf.acp.menu.link.chat.room.add';
/**
* @see \wcf\page\AbstractPage::$neededPermissions
2012-02-04 20:57:39 +00:00
*/
public $neededPermissions = array('admin.content.chat.canAddRoom');
/**
* Title of the room
*
* @var string
*/
public $title = '';
/**
* Topic of the room
*
* @var string
*/
public $topic = '';
/**
* @see \wcf\page\AbstractPage::__construct()
*/
public function __construct() {
$this->objectTypeID = \wcf\system\acl\ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.wcf.chat.room');
parent::__construct();
}
/**
* @see \wcf\page\IPage::readParameters()
2012-02-04 20:57:39 +00:00
*/
public function readParameters() {
parent::readParameters();
I18nHandler::getInstance()->register('title');
I18nHandler::getInstance()->register('topic');
}
/**
* @see \wcf\form\IForm::readFormParameters()
2012-02-04 20:57:39 +00:00
*/
public function readFormParameters() {
parent::readFormParameters();
I18nHandler::getInstance()->readValues();
if (I18nHandler::getInstance()->isPlainValue('title')) $this->title = I18nHandler::getInstance()->getValue('title');
if (I18nHandler::getInstance()->isPlainValue('topic')) $this->topic = I18nHandler::getInstance()->getValue('topic');
}
/**
* @see \wcf\form\IForm::validate()
2012-02-04 20:57:39 +00:00
*/
public function validate() {
parent::validate();
// validate title
2012-02-05 19:50:13 +00:00
if (!I18nHandler::getInstance()->validateValue('title')) {
throw new UserInputException('title');
2012-02-04 20:57:39 +00:00
}
}
/**
* @see \wcf\form\IForm::save()
2012-02-04 20:57:39 +00:00
*/
public function save() {
parent::save();
// save room
$this->objectAction = new \wcf\data\chat\room\ChatRoomAction(array(), 'create', array('data' => array(
2012-02-04 20:57:39 +00:00
'title' => $this->title,
'topic' => $this->topic
)));
$this->objectAction->executeAction();
$returnValues = $this->objectAction->getReturnValues();
2012-02-04 20:57:39 +00:00
$chatRoomEditor = new \wcf\data\chat\room\ChatRoomEditor($returnValues['returnValues']);
$roomID = $returnValues['returnValues']->roomID;
if (!I18nHandler::getInstance()->isPlainValue('title')) {
I18nHandler::getInstance()->save('title', 'wcf.chat.room.title'.$roomID, 'wcf.chat.room', \wcf\util\ChatUtil::getPackageID());
2012-02-04 20:57:39 +00:00
// update title
$chatRoomEditor->update(array(
2012-02-05 17:29:16 +00:00
'title' => 'wcf.chat.room.title'.$roomID
2012-02-04 20:57:39 +00:00
));
}
2012-02-04 20:57:39 +00:00
if (!I18nHandler::getInstance()->isPlainValue('topic')) {
I18nHandler::getInstance()->save('topic', 'wcf.chat.room.topic'.$roomID, 'wcf.chat.room', \wcf\util\ChatUtil::getPackageID());
2012-02-04 20:57:39 +00:00
// update topic
$chatRoomEditor->update(array(
2012-02-05 17:29:16 +00:00
'topic' => 'wcf.chat.room.topic'.$roomID
2012-02-04 20:57:39 +00:00
));
}
\wcf\system\acl\ACLHandler::getInstance()->save($roomID, $this->objectTypeID);
2012-03-03 20:36:52 +00:00
\wcf\system\chat\permission\ChatPermissionHandler::clearCache();
2012-02-04 20:57:39 +00:00
$this->saved();
2012-02-04 20:57:39 +00:00
// reset values
$this->topic = $this->title = '';
I18nHandler::getInstance()->disableAssignValueVariables();
2012-02-04 20:57:39 +00:00
// show success
WCF::getTPL()->assign(array(
'success' => true
));
}
/**
* @see \wcf\page\IPage::assignVariables()
2012-02-04 20:57:39 +00:00
*/
public function assignVariables() {
parent::assignVariables();
I18nHandler::getInstance()->assignVariables();
WCF::getTPL()->assign(array(
'action' => 'add',
'title' => $this->title,
'topic' => $this->topic,
'objectTypeID' => $this->objectTypeID
2012-02-04 20:57:39 +00:00
));
}
}