From: Joshua Rüsweg Date: Wed, 12 Jul 2017 12:42:12 +0000 (+0200) Subject: Add user trophy add form X-Git-Tag: 3.1.0_Alpha_1~283^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d8b47ff15252824885d515dcc2b17ee7693a69b1;p=GitHub%2FWoltLab%2FWCF.git Add user trophy add form See #2315 --- diff --git a/com.woltlab.wcf/acpMenu.xml b/com.woltlab.wcf/acpMenu.xml index 4986bd498f..75536171dc 100644 --- a/com.woltlab.wcf/acpMenu.xml +++ b/com.woltlab.wcf/acpMenu.xml @@ -352,6 +352,13 @@ admin.trophy.canAwardTrophy module_trophy + + wcf\acp\form\UserTrophyAddForm + wcf.acp.menu.link.userTrophy.list + admin.trophy.canAwardTrophy + module_trophy + fa-plus + diff --git a/wcfsetup/install/files/acp/templates/userTrophyAdd.tpl b/wcfsetup/install/files/acp/templates/userTrophyAdd.tpl new file mode 100644 index 0000000000..a821015805 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/userTrophyAdd.tpl @@ -0,0 +1,118 @@ +{include file='header' pageTitle='wcf.acp.menu.link.userTrophy.'|concat:$action} + + + +
+
+

{lang}wcf.acp.menu.link.userTrophy.{$action}{/lang}

+
+ + +
+ +{include file='formError'} + +{if $success|isset} +

{lang}wcf.global.success.{$action}{/lang}

+{/if} + +
+
+ +
+
+ + {if $errorField == 'user'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {/if} + + {/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} + {lang}wcf.acp.trophy.userTrophy.description{/lang} +
+ + +
+
+
+ +
+
+ + + + {include file='multipleLanguageInputJavascript' elementIdentifier='description' forceSelection=false} + + {event name='dataFields'} +
+ + {event name='sections'} + +
+ + {@SECURITY_TOKEN_INPUT_TAG} +
+
+ +{include file='footer'} diff --git a/wcfsetup/install/files/lib/acp/form/TrophyAddForm.class.php b/wcfsetup/install/files/lib/acp/form/TrophyAddForm.class.php index f0863c21ea..8c41182f8c 100644 --- a/wcfsetup/install/files/lib/acp/form/TrophyAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/TrophyAddForm.class.php @@ -276,7 +276,8 @@ class TrophyAddForm extends AbstractAcpForm { 'description' => $this->description, 'categoryID' => $this->categoryID, 'type' => $this->type, - 'isDisabled' => $this->isDisabled + 'isDisabled' => $this->isDisabled, + 'awardAutomatically' => $this->awardAutomatically ]), 'tmpHash' => $this->tmpHash ]); diff --git a/wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php b/wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php index 2ec278765e..18e36b4bda 100644 --- a/wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php @@ -67,12 +67,17 @@ class TrophyEditForm extends TrophyAddForm { $this->categoryID = $this->trophy->categoryID; $this->type = $this->trophy->type; $this->isDisabled = $this->trophy->isDisabled; + $this->iconName = $this->trophy->iconName; + $this->iconColor = $this->trophy->iconColor; + $this->badgeColor = $this->trophy->badgeColor; + $this->awardAutomatically = $this->trophy->awardAutomatically; + + // reset badge values for non badge trophies if ($this->trophy->type != Trophy::TYPE_BADGE) { $this->iconName = 'trophy'; $this->iconColor = 'rgba(255, 255, 255, 1)'; $this->badgeColor = 'rgba(50, 92, 132, 1)'; } - $this->awardAutomatically = $this->trophy->awardAutomatically; $conditions = $this->trophy->getConditions(); $conditionsByObjectTypeID = []; diff --git a/wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php new file mode 100644 index 0000000000..e9dfeb0f87 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php @@ -0,0 +1,180 @@ + + * @package WoltLabSuite\Core\Acp\Form + * @since 3.1 + */ +class UserTrophyAddForm extends AbstractAcpForm { + /** + * @inheritDoc + */ + public $neededPermissions = ['admin.trophy.canAwardTrophy']; + + /** + * @inheritDoc + */ + public $neededModules = ['MODULE_TROPHY']; + + /** + * @inheritDoc + */ + public $activeMenuItem = 'wcf.acp.menu.link.userTrophy.add'; + + /** + * usernames (comma separated) + * @var string[] + */ + public $user = ''; + + /** + * List of user ids which earn the trophy. + * @var integer[] + */ + public $userIDs = []; + + /** + * `1` if the user trophy should have a custom description + * @var int + */ + public $useCustomDescription = 0; + + /** + * custom trophy description + * @var string + */ + public $description; + + /** + * @var integer + */ + public $trophyID = 0; + + /** + * Rewarded trophy instance. + * @var Trophy + */ + public $trophy = null; + + /** + * @inheritDoc + */ + public function readParameters() { + parent::readParameters(); + + $descriptionI18n = new I18nValue('description'); + $descriptionI18n->setLanguageItem('wcf.user.trophy.description', 'wcf.trophy', 'com.woltlab.wcf'); + $descriptionI18n->setFlags(I18nValue::ALLOW_EMPTY); + $this->registerI18nValue($descriptionI18n); + } + + /** + * @inheritDoc + */ + public function readFormParameters() { + parent::readFormParameters(); + + if (isset($_POST['user'])) $this->user = StringUtil::trim($_POST['user']); + if (isset($_POST['trophyID'])) $this->trophyID = intval($_POST['trophyID']); + if (isset($_POST['useCustomDescription'])) $this->useCustomDescription = 1; + + $this->trophy = new Trophy($this->trophyID); + + // read userIDs + $userAsArray = explode(',', $this->user); + + $userList = new UserList(); + $userList->getConditionBuilder()->add('user_table.username IN (?)', [$userAsArray]); + $userList->readObjects(); + + foreach ($userList as $user) { + $this->userIDs[] = $user->userID; + } + } + + /** + * @inheritDoc + */ + public function validate() { + parent::validate(); + + if ($this->useCustomDescription) { + if (!I18nHandler::getInstance()->validateValue('description')) { + throw new UserInputException('description'); + } + } + + if (empty($this->userIDs)) { + throw new UserInputException('user'); + } + + if (!$this->trophy->trophyID) { + throw new UserInputException('trophyID'); + } + + if ($this->trophy->awardAutomatically) { + throw new UserInputException('trophyID', 'awardAutomatically'); + } + } + + /** + * @inheritDoc + */ + public function save() { + parent::save(); + + foreach ($this->userIDs as $user) { + (new UserTrophyAction([], 'create', [ + 'data' => array_merge($this->additionalFields, [ + 'trophyID' => $this->trophy->trophyID, + 'userID' => $user, + 'description' => $this->useCustomDescription ? $this->description : '', + 'time' => TIME_NOW, + 'useCustomDescription' => $this->useCustomDescription + ]) + ]))->executeAction(); + } + + $this->reset(); + + } + + /** + * @inheritDoc + */ + public function reset() { + parent::reset(); + + $this->user = $this->userIDs = []; + $this->trophyID = ''; + $this->useCustomDescription = 0; + } + + /** + * @inheritDoc + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'trophyID' => $this->trophyID, + 'user' => $this->user, + 'trophyCategories' => TrophyCategoryCache::getInstance()->getCategories(), + 'useCustomDescription' => $this->useCustomDescription + ]); + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index f65cb9b606..c9e99f660b 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -874,6 +874,7 @@ + @@ -3627,6 +3628,10 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email} {$trophy->getTitle()} wirklich löschen?]]> + + + + {$userTrophy->getTrophy()->getTitle()} von {$userTrophy->getUserProfile()->username} wirklich löschen?]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 92364c5c1d..9924b1f8d9 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -839,6 +839,7 @@ + @@ -3591,6 +3592,10 @@ Open the link below to access the user profile: {$trophy->getTitle()}?]]> + + + + {$userTrophy->getTrophy()->getTitle()} from {$userTrophy->getUserProfile()->username}?]]> diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 12984db6bc..ed324aff9d 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -1335,7 +1335,7 @@ CREATE TABLE wcf1_trophy( iconColor VARCHAR(255), badgeColor VARCHAR(255), isDisabled TINYINT(1) NOT NULL DEFAULT 0, - awardAutomatically TINYINT(1) NOT NULL DEFAULT 1, + awardAutomatically TINYINT(1) NOT NULL DEFAULT 0, KEY(categoryID) );