Removed unused class
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / form / SmileyAddForm.class.php
CommitLineData
dcc2332d
MW
1<?php
2namespace wcf\acp\form;
3use wcf\data\category\Category;
4use wcf\data\category\CategoryNodeTree;
5use wcf\data\package\PackageCache;
6use wcf\data\smiley\SmileyAction;
7use wcf\data\smiley\SmileyEditor;
8use wcf\form\AbstractForm;
9use wcf\system\exception\UserInputException;
10use wcf\system\language\I18nHandler;
11use wcf\system\WCF;
12use wcf\util\StringUtil;
13
14/**
15 * Shows the smiley add form.
16 *
17 * @author Tim Duesterhus
18 * @copyright 2001-2013 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package com.woltlab.wcf.bbcode
21 * @subpackage acp.form
22 * @category Community Framework
23 */
24class SmileyAddForm extends AbstractForm {
25 /**
26 * @see wcf\page\AbstractPage::$activeMenuItem
27 */
28 public $activeMenuItem = 'wcf.acp.menu.link.smiley.add';
29
30 /**
31 * @see wcf\page\AbstractPage::$templateName
32 */
33 public $templateName = 'smileyAdd';
34
35 /**
36 * @see wcf\page\AbstractPage::$neededPermissions
37 */
38 public $neededPermissions = array('admin.content.smiley.canManageSmiley');
39
40 /**
41 * primary smiley code
42 * @var string
43 */
44 public $smileyCode = '';
45
46 /**
47 * showorder value
48 * @var integer
49 */
50 public $showOrder = 0;
51
52 /**
53 * categoryID value
54 * @var integer
55 */
56 public $categoryID = 0;
57
58 /**
59 * smileyTitle
60 * @var string
61 */
62 public $smileyTitle = '';
63
64 /**
65 * aliases value
66 * @var string
67 */
68 public $aliases = '';
69
70 /**
71 * node tree with available smiley categories
72 * @var wcf\data\category\CategoryNodeTree
73 */
74 public $categoryNodeTree = null;
75
76 /**
77 * @see wcf\page\IPage::assignVariables()
78 */
79 public function assignVariables() {
80 parent::assignVariables();
81
82 I18nHandler::getInstance()->assignVariables();
83
84 WCF::getTPL()->assign(array(
85 'action' => 'add',
86 'smileyTitle' => $this->smileyTitle,
87 'showOrder' => $this->showOrder,
88 'categoryID' => $this->categoryID,
89 'smileyCode' => $this->smileyCode,
90 'aliases' => $this->aliases,
91 'categoryNodeList' => $this->categoryNodeTree->getIterator()
92 ));
93 }
94
95 /**
96 * @see wcf\page\IPage::readData()
97 */
98 public function readData() {
99 parent::readData();
100
101 $this->categoryNodeTree = new CategoryNodeTree('com.woltlab.wcf.bbcode.smiley', 0, true);
102 }
103
104 /**
105 * @see \wcf\page\IPage::readParameters()
106 */
107 public function readParameters() {
108 parent::readParameters();
109
110 I18nHandler::getInstance()->register('smileyTitle');
111 }
112
113
114 /**
115 * @see wcf\page\IForm::readFormParameters()
116 */
117 public function readFormParameters() {
118 parent::readFormParameters();
119
120 I18nHandler::getInstance()->readValues();
121
122 if (I18nHandler::getInstance()->isPlainValue('smileyTitle')) $this->smileyTitle = I18nHandler::getInstance()->getValue('smileyTitle');
123
124 if (isset($_POST['showOrder'])) {
125 $this->showOrder = intval($_POST['showOrder']);
126 }
127 if (isset($_POST['smileyCode'])) {
128 $this->smileyCode = StringUtil::trim($_POST['smileyCode']);
129 }
130 if (isset($_POST['categoryID'])) {
131 $this->categoryID = intval($_POST['categoryID']);
132 }
133 if (isset($_POST['aliases'])) {
134 $this->aliases = StringUtil::unifyNewlines(StringUtil::trim($_POST['aliases']));
135 }
136 }
137
138 /**
139 * @see wcf\page\IForm::save()
140 */
141 public function save() {
142 parent::save();
143
144 $this->objectAction = new SmileyAction(array(), 'create', array(
145 'data' => array(
146 'smileyTitle' => $this->smileyTitle,
147 'smileyCode' => $this->smileyCode,
148 'showOrder' => $this->showOrder,
149 'categoryID' => $this->categoryID ?: null,
150 'packageID' => PackageCache::getInstance()->getPackageID('com.woltlab.wcf.bbcode'),
151 'aliases' => $this->aliases
152 )
153 ));
154 $this->objectAction->executeAction();
155 $returnValues = $this->objectAction->getReturnValues();
156 $smileyEditor = new SmileyEditor($returnValues['returnValues']);
157 $smileyID = $returnValues['returnValues']->smileyID;
158
159 if (!I18nHandler::getInstance()->isPlainValue('smileyTitle')) {
160 I18nHandler::getInstance()->save('smileyTitle', 'wcf.smiley.title'.$smileyID, 'wcf.smiley', PackageCache::getInstance()->getPackageID('com.woltlab.wcf.bbcode'));
161
162 // update title
163 $smileyEditor->update(array(
164 'title' => 'wcf.smiley.title'.$smileyID
165 ));
166 }
167
168 // reset values
169 $this->smileyCode = '';
170 $this->categoryID = 0;
171 $this->showOrder = 0;
172
173 I18nHandler::getInstance()->reset();
174
175 $this->saved();
176
177 // show success message
178 WCF::getTPL()->assign('success', true);
179 }
180
181 /**
182 * @see wcf\page\IForm::validate()
183 */
184 public function validate() {
185 parent::validate();
186
187 // validate title
188 if (!I18nHandler::getInstance()->validateValue('smileyTitle')) {
189 throw new UserInputException('smileyTitle');
190 }
191
192 if ($this->categoryID !== 0) {
193 $category = new Category($this->categoryID);
194 if (!$category->categoryID) {
195 throw new UserInputException('categoryID', 'notValid');
196 }
197 }
198
199 if ($this->smileyCode === '') {
200 throw new UserInputException('smileyCode');
201 }
202
203 // TODO: Validate uniqueness of smileyCode and aliases
204 }
205}