2012-02-04 20:57:39 +00:00
|
|
|
<?php
|
2013-01-27 19:10:06 +00:00
|
|
|
namespace chat\acp\form;
|
2012-02-04 20:57:39 +00:00
|
|
|
use \wcf\system\exception\UserInputException;
|
|
|
|
use \wcf\system\language\I18nHandler;
|
|
|
|
use \wcf\system\WCF;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the chatroom add form.
|
2014-02-28 16:06:50 +00:00
|
|
|
*
|
2012-02-26 16:55:44 +00:00
|
|
|
* @author Tim Düsterhus
|
2014-02-27 22:05:09 +00:00
|
|
|
* @copyright 2010-2014 Tim Düsterhus
|
2012-02-04 20:57:39 +00:00
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
2013-01-19 19:36:40 +00:00
|
|
|
* @package be.bastelstu.chat
|
2012-02-04 20:57:39 +00:00
|
|
|
* @subpackage acp.form
|
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
class RoomAddForm extends \wcf\form\AbstractForm {
|
2012-02-04 20:57:39 +00:00
|
|
|
/**
|
2013-01-07 19:34:18 +00:00
|
|
|
* @see \wcf\acp\page\AbstractPage::$activeMenuItem
|
2012-02-04 20:57:39 +00:00
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
public $activeMenuItem = 'chat.acp.menu.link.room.add';
|
2012-02-04 20:57:39 +00:00
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\page\AbstractPage::$neededPermissions
|
2012-02-04 20:57:39 +00:00
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
public $neededPermissions = array('admin.chat.canAddRoom');
|
2012-02-04 20:57:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Title of the room
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $title = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Topic of the room
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $topic = '';
|
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\page\AbstractPage::__construct()
|
|
|
|
*/
|
2012-06-16 18:08:05 +00:00
|
|
|
public function __run() {
|
2013-01-19 19:36:40 +00:00
|
|
|
$this->objectTypeID = \wcf\system\acl\ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room');
|
2012-02-26 16:55:44 +00:00
|
|
|
|
2012-06-16 18:08:05 +00:00
|
|
|
parent::__run();
|
2012-02-26 16:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\IPage::readParameters()
|
2012-02-04 20:57:39 +00:00
|
|
|
*/
|
|
|
|
public function readParameters() {
|
|
|
|
parent::readParameters();
|
2014-02-28 16:06:50 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
I18nHandler::getInstance()->register('title');
|
|
|
|
I18nHandler::getInstance()->register('topic');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\form\IForm::readFormParameters()
|
2012-02-04 20:57:39 +00:00
|
|
|
*/
|
|
|
|
public function readFormParameters() {
|
|
|
|
parent::readFormParameters();
|
2013-04-20 15:19:17 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
I18nHandler::getInstance()->readValues();
|
2013-04-20 15:19:17 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
if (I18nHandler::getInstance()->isPlainValue('title')) $this->title = I18nHandler::getInstance()->getValue('title');
|
|
|
|
if (I18nHandler::getInstance()->isPlainValue('topic')) $this->topic = I18nHandler::getInstance()->getValue('topic');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\form\IForm::save()
|
2012-02-04 20:57:39 +00:00
|
|
|
*/
|
|
|
|
public function save() {
|
|
|
|
parent::save();
|
2013-04-20 15:19:17 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
// save room
|
2013-11-27 23:51:17 +00:00
|
|
|
$this->objectAction = new \chat\data\room\RoomAction(array(), 'create', array('data' => array_merge($this->additionalFields, array(
|
2012-02-04 20:57:39 +00:00
|
|
|
'title' => $this->title,
|
|
|
|
'topic' => $this->topic
|
2013-11-27 23:51:17 +00:00
|
|
|
))));
|
2012-02-11 16:42:56 +00:00
|
|
|
$this->objectAction->executeAction();
|
|
|
|
$returnValues = $this->objectAction->getReturnValues();
|
2013-01-27 19:10:06 +00:00
|
|
|
$roomEditor = new \chat\data\room\RoomEditor($returnValues['returnValues']);
|
2012-02-04 20:57:39 +00:00
|
|
|
$roomID = $returnValues['returnValues']->roomID;
|
|
|
|
|
|
|
|
if (!I18nHandler::getInstance()->isPlainValue('title')) {
|
2013-01-19 19:36:40 +00:00
|
|
|
I18nHandler::getInstance()->save('title', 'chat.room.title'.$roomID, 'chat.room', \chat\util\ChatUtil::getPackageID());
|
2012-02-04 20:57:39 +00:00
|
|
|
|
|
|
|
// update title
|
2013-01-27 19:10:06 +00:00
|
|
|
$roomEditor->update(array(
|
|
|
|
'title' => 'chat.room.title'.$roomID
|
2012-02-04 20:57:39 +00:00
|
|
|
));
|
|
|
|
}
|
2012-02-26 16:55:44 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
if (!I18nHandler::getInstance()->isPlainValue('topic')) {
|
2013-01-19 19:36:40 +00:00
|
|
|
I18nHandler::getInstance()->save('topic', 'chat.room.topic'.$roomID, 'chat.room', \chat\util\ChatUtil::getPackageID());
|
2012-02-26 16:55:44 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
// update topic
|
2013-01-27 19:10:06 +00:00
|
|
|
$roomEditor->update(array(
|
2013-01-19 19:36:40 +00:00
|
|
|
'topic' => 'chat.room.topic'.$roomID
|
2012-02-04 20:57:39 +00:00
|
|
|
));
|
|
|
|
}
|
2012-02-26 16:55:44 +00:00
|
|
|
|
|
|
|
\wcf\system\acl\ACLHandler::getInstance()->save($roomID, $this->objectTypeID);
|
2013-09-08 12:45:40 +00:00
|
|
|
\wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables();
|
2013-07-08 19:36:51 +00:00
|
|
|
\chat\system\permission\PermissionHandler::clearCache();
|
2012-02-26 16:55:44 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
$this->saved();
|
2012-02-26 16:55:44 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
// reset values
|
|
|
|
$this->topic = $this->title = '';
|
2013-04-30 11:23:52 +00:00
|
|
|
I18nHandler::getInstance()->reset();
|
2012-02-26 16:55:44 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
// show success
|
|
|
|
WCF::getTPL()->assign(array(
|
|
|
|
'success' => true
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\page\IPage::assignVariables()
|
2012-02-04 20:57:39 +00:00
|
|
|
*/
|
|
|
|
public function assignVariables() {
|
|
|
|
parent::assignVariables();
|
|
|
|
|
|
|
|
I18nHandler::getInstance()->assignVariables();
|
2013-09-08 12:45:40 +00:00
|
|
|
\wcf\system\acl\ACLHandler::getInstance()->assignVariables($this->objectTypeID);
|
2012-02-04 20:57:39 +00:00
|
|
|
|
|
|
|
WCF::getTPL()->assign(array(
|
|
|
|
'action' => 'add',
|
|
|
|
'title' => $this->title,
|
2012-02-26 16:55:44 +00:00
|
|
|
'topic' => $this->topic,
|
|
|
|
'objectTypeID' => $this->objectTypeID
|
2012-02-04 20:57:39 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|