Merge branch 'master' of github.com:WoltLab/WCF
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / form / UserOptionEditForm.class.php
1 <?php
2 namespace wcf\acp\form;
3 use wcf\data\user\option\UserOption;
4 use wcf\data\user\option\UserOptionAction;
5 use wcf\form\AbstractForm;
6 use wcf\system\cache\builder\UserOptionCacheBuilder;
7 use wcf\system\exception\IllegalLinkException;
8 use wcf\system\language\I18nHandler;
9 use wcf\system\WCF;
10
11 /**
12 * Shows the user option edit form.
13 *
14 * @author Marcel Werk
15 * @copyright 2001-2013 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package com.woltlab.wcf
18 * @subpackage acp.form
19 * @category Community Framework
20 */
21 class UserOptionEditForm extends UserOptionAddForm {
22 /**
23 * @see wcf\page\AbstractPage::$activeMenuItem
24 */
25 public $activeMenuItem = 'wcf.acp.menu.link.user.option';
26
27 /**
28 * user option id
29 * @var integer
30 */
31 public $optionID = 0;
32
33 /**
34 * user option object
35 * @var wcf\data\user\option\UserOption
36 */
37 public $userOption = null;
38
39 /**
40 * @see wcf\page\IPage::readParameters()
41 */
42 public function readParameters() {
43 parent::readParameters();
44
45 if (isset($_REQUEST['id'])) $this->optionID = intval($_REQUEST['id']);
46 $this->userOption = new UserOption($this->optionID);
47 if (!$this->userOption->optionID) {
48 throw new IllegalLinkException();
49 }
50 }
51
52 /**
53 * @see wcf\form\IForm::save()
54 */
55 public function save() {
56 AbstractForm::save();
57
58 I18nHandler::getInstance()->save('optionName', 'wcf.user.option.'.$this->userOption->optionName, 'wcf.user.option');
59 I18nHandler::getInstance()->save('optionDescription', 'wcf.user.option.'.$this->userOption->optionName.'.description', 'wcf.user.option');
60
61 $this->objectAction = new UserOptionAction(array($this->userOption), 'update', array('data' => array(
62 'categoryName' => $this->categoryName,
63 'optionType' => $this->optionType,
64 'defaultValue' => $this->defaultValue,
65 'showOrder' => $this->showOrder,
66 'outputClass' => $this->outputClass,
67 'validationPattern' => $this->validationPattern,
68 'selectOptions' => $this->selectOptions,
69 'required' => $this->required,
70 'askDuringRegistration' => $this->askDuringRegistration,
71 'searchable' => $this->searchable,
72 'editable' => $this->editable,
73 'visible' => $this->visible
74 )));
75 $this->objectAction->executeAction();
76 $this->saved();
77
78 WCF::getTPL()->assign('success', true);
79 }
80
81 /**
82 * @see wcf\page\IPage::readData()
83 */
84 public function readData() {
85 parent::readData();
86
87 I18nHandler::getInstance()->setOptions('optionName', 1, 'wcf.user.option.'.$this->userOption->optionName, 'wcf.user.option.option\d+');
88 I18nHandler::getInstance()->setOptions('optionDescription', 1, 'wcf.user.option.'.$this->userOption->optionName.'.description', 'wcf.user.option.option\d+.description');
89
90 if (!count($_POST)) {
91 $this->categoryName = $this->userOption->categoryName;
92 $this->optionType = $this->userOption->optionType;
93 $this->defaultValue = $this->userOption->defaultValue;
94 $this->validationPattern = $this->userOption->validationPattern;
95 $this->selectOptions = $this->userOption->selectOptions;
96 $this->required = $this->userOption->required;
97 $this->askDuringRegistration = $this->userOption->askDuringRegistration;
98 $this->editable = $this->userOption->editable;
99 $this->visible = $this->userOption->visible;
100 $this->searchable = $this->userOption->searchable;
101 $this->showOrder = $this->userOption->showOrder;
102 $this->outputClass = $this->userOption->outputClass;
103 }
104 }
105
106 /**
107 * @see wcf\page\IPage::assignVariables()
108 */
109 public function assignVariables() {
110 parent::assignVariables();
111
112 I18nHandler::getInstance()->assignVariables(!empty($_POST));
113
114 WCF::getTPL()->assign(array(
115 'action' => 'edit',
116 'optionID' => $this->optionID,
117 'userOption' => $this->userOption
118 ));
119 }
120 }