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