Add UserTrophy edit form
authorJoshua Rüsweg <josh@bastelstu.be>
Sat, 15 Jul 2017 19:49:40 +0000 (21:49 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Sat, 15 Jul 2017 19:49:40 +0000 (21:49 +0200)
See #2315

wcfsetup/install/files/acp/templates/userTrophyAdd.tpl
wcfsetup/install/files/lib/acp/form/UserTrophyEditForm.class.php [new file with mode: 0644]

index 139d7a464dc325ab9abafbafbcf213e09eb5d3d3..ea5762ee5b701f6ab1c5e77c9780b7fdc995370b 100644 (file)
                <dl{if $errorField == 'user'} class="formError"{/if}>
                        <dt><label for="user">{lang}wcf.acp.trophy.userTrophy.user{/lang}</label></dt>
                        <dd>
-                               <input id="user" name="user" type="text" value="{$user}"{if $action == 'edit'} disabled{/if}>
-                               {if $errorField == 'user'}
-                                       <small class="innerError">
-                                               {if $errorType|is_array}
-                                                       {foreach from=$errorType item='errorData'}
-                                                               {lang}wcf.acp.trophy.userTrophy.user.error.{@$errorData.type}{/lang}
-                                                       {/foreach}
-                                               {elseif $errorType == 'empty'}
-                                                       {lang}wcf.global.form.error.empty{/lang}
-                                               {/if}
-                                       </small>
+                               {if $action == 'edit'}
+                                       <a href="{link controller='UserEdit' id=$userTrophy->userID}{/link}">{$userTrophy->getUserProfile()->getUsername()}</a>
+                               {else}
+                                       <input id="user" name="user" type="text" value="{$user}"{if $action == 'edit'} disabled{/if}>
+                                       {if $errorField == 'user'}
+                                               <small class="innerError">
+                                                       {if $errorType|is_array}
+                                                               {foreach from=$errorType item='errorData'}
+                                                                       {lang}wcf.acp.trophy.userTrophy.user.error.{@$errorData.type}{/lang}
+                                                               {/foreach}
+                                                       {elseif $errorType == 'empty'}
+                                                               {lang}wcf.global.form.error.empty{/lang}
+                                                       {/if}
+                                               </small>
+                                       {/if}
+                                       <small>{lang}wcf.acp.trophy.userTrophy.user.description{/lang}</small>
                                {/if}
-                               <small>{lang}wcf.acp.trophy.userTrophy.user.description{/lang}</small>
                        </dd>
                </dl>
 
                <dl{if $errorField == 'trophyID'} class="formError"{/if}>
                        <dt><label for="trophyID">{lang}wcf.acp.trophy{/lang}</label></dt>
                        <dd>
-                               <select name="trophyID" id="trophyID"{if $action == 'edit'} disabled{/if}>
-                                       <option value="0">{lang}wcf.global.noSelection{/lang}</option>
-
-                                       {foreach from=$trophyCategories item=category}
-                                               <optgroup label="{$category->getTitle()}">
-                                                       {foreach from=$category->getTrophies(true) item=trophy}
-                                                               <option value="{@$trophy->trophyID}"{if $trophy->trophyID == $trophyID} selected{/if}{if $trophy->awardAutomatically} disabled{/if}>{$trophy->getTitle()}</option>
-                                                       {/foreach}
-                                               </optgroup>
-                                       {/foreach}
-                               </select>
-                               {if $errorField == 'trophyID'}
-                                       <small class="innerError">
-                                               {if $errorType == 'empty'}
-                                                       {lang}wcf.global.form.error.empty{/lang}
-                                               {elseif $errorType == 'awardAutomatically'}
-                                                       {lang}wcf.acp.trophy.userTrophy.trophy.error.awardAutomatically{/lang}
-                                               {/if}
-                                       </small>
+                               {if $action == 'edit'}
+                                       <a href="{link controller='TrophyEdit' id=$userTrophy->trophyID}{/link}">{$userTrophy->getTrophy()->getTitle()}</a>
+                               {else}
+                                       <select name="trophyID" id="trophyID"{if $action == 'edit'} disabled{/if}>
+                                               <option value="0">{lang}wcf.global.noSelection{/lang}</option>
+       
+                                               {foreach from=$trophyCategories item=category}
+                                                       <optgroup label="{$category->getTitle()}">
+                                                               {foreach from=$category->getTrophies(true) item=trophy}
+                                                                       <option value="{@$trophy->trophyID}"{if $trophy->trophyID == $trophyID} selected{/if}{if $trophy->awardAutomatically} disabled{/if}>{$trophy->getTitle()}</option>
+                                                               {/foreach}
+                                                       </optgroup>
+                                               {/foreach}
+                                       </select>
+                                       {if $errorField == 'trophyID'}
+                                               <small class="innerError">
+                                                       {if $errorType == 'empty'}
+                                                               {lang}wcf.global.form.error.empty{/lang}
+                                                       {elseif $errorType == 'awardAutomatically'}
+                                                               {lang}wcf.acp.trophy.userTrophy.trophy.error.awardAutomatically{/lang}
+                                                       {/if}
+                                               </small>
+                                       {/if}
+                                       <small>{lang}wcf.acp.trophy.userTrophy.description{/lang}</small>
                                {/if}
-                               <small>{lang}wcf.acp.trophy.userTrophy.description{/lang}</small>
                        </dd>
                </dl>
 
diff --git a/wcfsetup/install/files/lib/acp/form/UserTrophyEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserTrophyEditForm.class.php
new file mode 100644 (file)
index 0000000..3afaecf
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+namespace wcf\acp\form;
+use wcf\data\user\trophy\UserTrophy;
+use wcf\data\user\trophy\UserTrophyAction;
+use wcf\system\exception\IllegalLinkException;
+use wcf\system\language\I18nHandler;
+use wcf\system\WCF;
+
+/**
+ * Represents the user trophy edit form.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\Acp\Form
+ * @since      3.1
+ */
+class UserTrophyEditForm extends UserTrophyAddForm {
+       /**
+        * @inheritDoc
+        */
+       public $activeMenuItem = 'wcf.acp.menu.link.trophy';
+       
+       /**
+        * @inheritDoc
+        */
+       public $action = 'edit';
+       
+       /**
+        * user trophy id
+        * @var int
+        */
+       public $userTrophyID = 0;
+       
+       /**
+        * user trophy object
+        * @var UserTrophy
+        */
+       public $userTrophy;
+       
+       /**
+        * @inheritDoc
+        */
+       public function readParameters() {
+               if (!empty($_REQUEST['id'])) $this->userTrophyID = intval($_REQUEST['id']);
+               $this->userTrophy = new UserTrophy($this->userTrophyID);
+               
+               if (!$this->userTrophy->userTrophyID) {
+                       throw new IllegalLinkException();
+               }
+               
+               if ($this->userTrophy->getTrophy()->awardAutomatically) {
+                       throw new IllegalLinkException(); 
+               }
+               
+               parent::readParameters();
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function readData() {
+               // the user can't change these values
+               $this->trophyID = $this->userTrophy->trophyID;
+               $this->trophy = $this->userTrophy->getTrophy(); 
+               $this->userIDs = [$this->userTrophy->userID];
+               $this->user = $this->userTrophy->getUserProfile()->getUsername();
+               
+               if (empty($_POST)) {
+                       $this->readDataI18n($this->userTrophy);
+                       
+                       $this->useCustomDescription = $this->userTrophy->useCustomDescription;
+               }
+               
+               parent::readData();
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function save() {
+               AbstractAcpForm::save();
+               
+               $this->beforeSaveI18n($this->userTrophy);
+               
+               $this->objectAction = new UserTrophyAction([$this->userTrophy], 'update', [
+                       'data' => array_merge($this->additionalFields, [
+                               'useCustomDescription' => $this->useCustomDescription, 
+                               'description' => $this->description
+                       ])      
+               ]);
+               $this->objectAction->executeAction(); 
+               
+               $this->saved();
+               
+               // show success message
+               WCF::getTPL()->assign('success', true);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function assignVariables() {
+               parent::assignVariables();
+               
+               I18nHandler::getInstance()->assignVariables(!empty($_POST));
+               
+               WCF::getTPL()->assign([
+                       'userTrophy' => $this->userTrophy
+               ]);
+       }
+}