From 0d5dc8e7390f65e9b4b929b73eb7a55ae1b92f9b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Sat, 15 Jul 2017 21:49:40 +0200 Subject: [PATCH] Add UserTrophy edit form See #2315 --- .../files/acp/templates/userTrophyAdd.tpl | 72 ++++++----- .../lib/acp/form/UserTrophyEditForm.class.php | 112 ++++++++++++++++++ 2 files changed, 152 insertions(+), 32 deletions(-) create mode 100644 wcfsetup/install/files/lib/acp/form/UserTrophyEditForm.class.php diff --git a/wcfsetup/install/files/acp/templates/userTrophyAdd.tpl b/wcfsetup/install/files/acp/templates/userTrophyAdd.tpl index 139d7a464d..ea5762ee5b 100644 --- a/wcfsetup/install/files/acp/templates/userTrophyAdd.tpl +++ b/wcfsetup/install/files/acp/templates/userTrophyAdd.tpl @@ -41,46 +41,54 @@
- - {if $errorField == 'user'} - - {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} - + {if $action == 'edit'} + {$userTrophy->getUserProfile()->getUsername()} + {else} + + {if $errorField == 'user'} + + {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} + + {/if} + {lang}wcf.acp.trophy.userTrophy.user.description{/lang} {/if} - {lang}wcf.acp.trophy.userTrophy.user.description{/lang}
- - {if $errorField == 'trophyID'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {elseif $errorType == 'awardAutomatically'} - {lang}wcf.acp.trophy.userTrophy.trophy.error.awardAutomatically{/lang} - {/if} - + {if $action == 'edit'} + {$userTrophy->getTrophy()->getTitle()} + {else} + + {if $errorField == 'trophyID'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {elseif $errorType == 'awardAutomatically'} + {lang}wcf.acp.trophy.userTrophy.trophy.error.awardAutomatically{/lang} + {/if} + + {/if} + {lang}wcf.acp.trophy.userTrophy.description{/lang} {/if} - {lang}wcf.acp.trophy.userTrophy.description{/lang}
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 index 0000000000..3afaecf308 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/UserTrophyEditForm.class.php @@ -0,0 +1,112 @@ + + * @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 + ]); + } +} -- 2.20.1