Commit | Line | Data |
---|---|---|
320f4a6d MW |
1 | <?php |
2 | namespace wcf\acp\form; | |
320f4a6d MW |
3 | use wcf\data\user\rank\UserRank; |
4 | use wcf\data\user\rank\UserRankAction; | |
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 rank edit form. | |
12 | * | |
13 | * @author Marcel Werk | |
ca4ba303 | 14 | * @copyright 2001-2014 WoltLab GmbH |
320f4a6d | 15 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
f4f05aa5 | 16 | * @package com.woltlab.wcf |
320f4a6d MW |
17 | * @subpackage acp.form |
18 | * @category Community Framework | |
19 | */ | |
20 | class UserRankEditForm extends UserRankAddForm { | |
21 | /** | |
0ad90fc3 | 22 | * @see \wcf\page\AbstractPage::$activeMenuItem |
320f4a6d | 23 | */ |
c636e501 | 24 | public $activeMenuItem = 'wcf.acp.menu.link.user.rank'; |
320f4a6d MW |
25 | |
26 | /** | |
27 | * rank id | |
28 | * @var integer | |
29 | */ | |
30 | public $rankID = 0; | |
31 | ||
32 | /** | |
33 | * rank object | |
0ad90fc3 | 34 | * @var \wcf\data\user\rank\UserRank |
320f4a6d MW |
35 | */ |
36 | public $rank = null; | |
37 | ||
38 | /** | |
0ad90fc3 | 39 | * @see \wcf\page\IPage::readParameters() |
320f4a6d MW |
40 | */ |
41 | public function readParameters() { | |
42 | parent::readParameters(); | |
43 | ||
44 | if (isset($_REQUEST['id'])) $this->rankID = intval($_REQUEST['id']); | |
45 | $this->rank = new UserRank($this->rankID); | |
46 | if (!$this->rank->rankID) { | |
47 | throw new IllegalLinkException(); | |
48 | } | |
49 | } | |
50 | ||
51 | /** | |
0ad90fc3 | 52 | * @see \wcf\form\IForm::save() |
320f4a6d MW |
53 | */ |
54 | public function save() { | |
55 | AbstractForm::save(); | |
56 | ||
57 | $this->rankTitle = 'wcf.user.rank.userRank'.$this->rank->rankID; | |
58 | if (I18nHandler::getInstance()->isPlainValue('rankTitle')) { | |
e118b677 | 59 | I18nHandler::getInstance()->remove($this->rankTitle); |
320f4a6d MW |
60 | $this->rankTitle = I18nHandler::getInstance()->getValue('rankTitle'); |
61 | } | |
62 | else { | |
a37b39b6 | 63 | I18nHandler::getInstance()->save('rankTitle', $this->rankTitle, 'wcf.user', 1); |
320f4a6d MW |
64 | } |
65 | ||
66 | // update label | |
e94d7556 | 67 | $this->objectAction = new UserRankAction(array($this->rank), 'update', array('data' => array_merge($this->additionalFields, array( |
320f4a6d MW |
68 | 'rankTitle' => $this->rankTitle, |
69 | 'cssClassName' => ($this->cssClassName == 'custom' ? $this->customCssClassName : $this->cssClassName), | |
70 | 'groupID' => $this->groupID, | |
71 | 'requiredPoints' => $this->requiredPoints, | |
72 | 'rankImage' => $this->rankImage, | |
73 | 'repeatImage' => $this->repeatImage, | |
74 | 'requiredGender' => $this->requiredGender | |
e94d7556 | 75 | )))); |
320f4a6d MW |
76 | $this->objectAction->executeAction(); |
77 | $this->saved(); | |
78 | ||
79 | // reset values if non-custom value was choosen | |
80 | if ($this->cssClassName != 'custom') $this->customCssClassName = ''; | |
81 | ||
82 | // show success | |
83 | WCF::getTPL()->assign(array( | |
84 | 'success' => true | |
85 | )); | |
86 | } | |
87 | ||
88 | /** | |
0ad90fc3 | 89 | * @see \wcf\page\IPage::readData() |
320f4a6d MW |
90 | */ |
91 | public function readData() { | |
92 | parent::readData(); | |
93 | ||
94 | if (empty($_POST)) { | |
a37b39b6 | 95 | I18nHandler::getInstance()->setOptions('rankTitle', 1, $this->rank->rankTitle, 'wcf.user.rank.userRank\d+'); |
320f4a6d MW |
96 | $this->rankTitle = $this->rank->rankTitle; |
97 | $this->cssClassName = $this->rank->cssClassName; | |
98 | if (!in_array($this->cssClassName, $this->availableCssClassNames)) { | |
99 | $this->customCssClassName = $this->cssClassName; | |
100 | $this->cssClassName = 'custom'; | |
101 | } | |
102 | $this->groupID = $this->rank->groupID; | |
103 | $this->requiredPoints = $this->rank->requiredPoints; | |
104 | $this->requiredGender = $this->rank->requiredGender; | |
105 | $this->repeatImage = $this->rank->repeatImage; | |
106 | $this->rankImage = $this->rank->rankImage; | |
107 | } | |
108 | } | |
109 | ||
110 | /** | |
0ad90fc3 | 111 | * @see \wcf\page\IPage::assignVariables() |
320f4a6d MW |
112 | */ |
113 | public function assignVariables() { | |
114 | parent::assignVariables(); | |
115 | ||
116 | I18nHandler::getInstance()->assignVariables(!empty($_POST)); | |
117 | ||
118 | WCF::getTPL()->assign(array( | |
119 | 'rankID' => $this->rankID, | |
120 | 'rank' => $this->rank, | |
121 | 'action' => 'edit' | |
122 | )); | |
123 | } | |
124 | } |