<permissions>admin.trophy.canAwardTrophy</permissions>
<options>module_trophy</options>
</acpmenuitem>
+ <acpmenuitem name="wcf.acp.menu.link.userTrophy.add">
+ <controller>wcf\acp\form\UserTrophyAddForm</controller>
+ <parent>wcf.acp.menu.link.userTrophy.list</parent>
+ <permissions>admin.trophy.canAwardTrophy</permissions>
+ <options>module_trophy</options>
+ <icon>fa-plus</icon>
+ </acpmenuitem>
<!-- /trophy -->
<!-- /user -->
--- /dev/null
+{include file='header' pageTitle='wcf.acp.menu.link.userTrophy.'|concat:$action}
+
+<script data-relocate="true">
+ require(['WoltLabSuite/Core/Ui/ItemList/User'], function(UiItemListUser) {
+ UiItemListUser.init('user', {
+ maxItems: 25
+ });
+
+ elBySel('input[name=useCustomDescription]').addEventListener('click', function () {
+ if (elBySel('input[name=useCustomDescription]').checked) {
+ elById('userTrophyDescriptionDL').style.display = 'block';
+ } else {
+ elById('userTrophyDescriptionDL').style.display = 'none';
+ }
+ });
+ });
+</script>
+
+<header class="contentHeader">
+ <div class="contentHeaderTitle">
+ <h1 class="contentTitle">{lang}wcf.acp.menu.link.userTrophy.{$action}{/lang}</h1>
+ </div>
+
+ <nav class="contentHeaderNavigation">
+ <ul>
+ <li><a href="{link controller='UserTrophyList'}{/link}" class="button"><span class="icon icon16 fa-list"></span> <span>{lang}wcf.acp.menu.link.userTrophy.list{/lang}</span></a></li>
+
+ {event name='contentHeaderNavigation'}
+ </ul>
+ </nav>
+</header>
+
+{include file='formError'}
+
+{if $success|isset}
+ <p class="success">{lang}wcf.global.success.{$action}{/lang}</p>
+{/if}
+
+<form method="post" action="{if $action == 'add'}{link controller='UserTrophyAdd'}{/link}{else}{link controller='UserTrophyEdit' id=$userTrophy->getObjectID()}{/link}{/if}">
+ <div class="section">
+ <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 == 'empty'}
+ {lang}wcf.global.form.error.empty{/lang}
+ {/if}
+ </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}
+ <option value="0" disabled>{$category->getTitle()}</option>
+ {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}
+ {/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>
+ </dd>
+ </dl>
+
+ <dl>
+ <dt></dt>
+ <dd>
+ <label><input type="checkbox" name="useCustomDescription" value="1"{if $useCustomDescription} checked{/if}> {lang}wcf.acp.trophy.userTrophy.useCustomDescription{/lang}</label>
+ </dd>
+ </dl>
+
+
+ <dl id="userTrophyDescriptionDL"{if $errorField == 'description'} class="formError"{/if}{if !$useCustomDescription} style="display: none;"{/if}>
+ <dt><label for="description">{lang}wcf.acp.trophy.description{/lang}</label></dt>
+ <dd>
+ <textarea id="description" name="description" cols="40" rows="10">{$i18nPlainValues[description]}</textarea>
+ {if $errorField == 'description'}
+ <small class="innerError">
+ {if $errorType == 'empty'}
+ {lang}wcf.global.form.error.empty{/lang}
+ {elseif $errorType == 'multilingual'}
+ {lang}wcf.global.form.error.multilingual{/lang}
+ {/if}
+ </small>
+ {/if}
+ </dd>
+ </dl>
+ {include file='multipleLanguageInputJavascript' elementIdentifier='description' forceSelection=false}
+
+ {event name='dataFields'}
+ </div>
+
+ {event name='sections'}
+
+ <div class="formSubmit">
+ <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
+ {@SECURITY_TOKEN_INPUT_TAG}
+ </div>
+</form>
+
+{include file='footer'}
'description' => $this->description,
'categoryID' => $this->categoryID,
'type' => $this->type,
- 'isDisabled' => $this->isDisabled
+ 'isDisabled' => $this->isDisabled,
+ 'awardAutomatically' => $this->awardAutomatically
]),
'tmpHash' => $this->tmpHash
]);
$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 = [];
--- /dev/null
+<?php
+namespace wcf\acp\form;
+use wcf\data\trophy\category\TrophyCategoryCache;
+use wcf\data\trophy\Trophy;
+use wcf\data\user\trophy\UserTrophyAction;
+use wcf\data\user\UserList;
+use wcf\system\exception\UserInputException;
+use wcf\system\language\I18nHandler;
+use wcf\system\language\I18nValue;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
+
+/**
+ * User trophy add 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 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
+ ]);
+ }
+}
<item name="wcf.acp.menu.link.trophy.add"><![CDATA[Trophäe hinzufügen]]></item>
<item name="wcf.acp.menu.link.trophy.edit"><![CDATA[Trophäe bearbeiten]]></item>
<item name="wcf.acp.menu.link.userTrophy.list"><![CDATA[Vergebene Trophäen]]></item>
+ <item name="wcf.acp.menu.link.userTrophy.add"><![CDATA[Trophäe vergeben]]></item>
<item name="wcf.acp.menu.link.userTrophy.edit"><![CDATA[Vergebene Trophäe bearbeiten]]></item>
<item name="wcf.acp.menu.link.devtools"><![CDATA[Entwickler-Werkzeuge]]></item>
<item name="wcf.acp.menu.link.devtools.project.list"><![CDATA[Projekte auflisten]]></item>
<item name="wcf.acp.trophy.conditions.description"><![CDATA[Der aktive Benutzer muss die folgenden Bedingungen erfüllen, damit der die Trophäe vergeben wird.]]></item>
<item name="wcf.acp.trophy.conditions.error.noConditions"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} keine Bedingungen ausgewählt.]]></item>
<item name="wcf.acp.trophy.delete.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} die Trophäe <span class="confirmationObject">{$trophy->getTitle()}</span> wirklich löschen?]]></item>
+ <item name="wcf.acp.trophy.userTrophy.user"><![CDATA[Benutzer]]></item>
+ <item name="wcf.acp.trophy.userTrophy.user.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Gebe{else}Geben Sie{/if} hier die Benutzer an, welche die Trophäe erhalten sollen.]]></item>
+ <item name="wcf.acp.trophy.userTrophy.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Gebe{else}Geben Sie{/if} hier die Trophäe an, welche an die Benutzer vergeben werden soll. {if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} keine automatisch vergebene Trophäen manuell vergeben.]]></item>
+ <item name="wcf.acp.trophy.userTrophy.useCustomDescription"><![CDATA[Benutzerdefinierte Trophäen-Beschreibung aktivieren]]></item>
<item name="wcf.acp.trophy.userTrophy.delete.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} die Trophäe <span class="confirmationObject">{$userTrophy->getTrophy()->getTitle()}</span> von <span class="confirmationObject">{$userTrophy->getUserProfile()->username}</span> wirklich löschen?]]></item>
</category>
<item name="wcf.acp.menu.link.trophy.add"><![CDATA[Add Trophy]]></item>
<item name="wcf.acp.menu.link.trophy.edit"><![CDATA[Edit Trophy]]></item>
<item name="wcf.acp.menu.link.userTrophy.list"><![CDATA[Assigned Trophies]]></item>
+ <item name="wcf.acp.menu.link.userTrophy.add"><![CDATA[Assign Trophy]]></item>
<item name="wcf.acp.menu.link.userTrophy.edit"><![CDATA[Edit assigned Trophy]]></item>
</category>
<item name="wcf.acp.trophy.conditions.description"><![CDATA[The users need to fulfill the following conditions to automatically be awarded with the trophy.]]></item>
<item name="wcf.acp.trophy.conditions.error.noConditions"><![CDATA[You have not provided any conditions yet.]]></item>
<item name="wcf.acp.trophy.delete.confirmMessage"><![CDATA[Do you really want to delete the trophy <span class="confirmationObject">{$trophy->getTitle()}</span>?]]></item>
+ <item name="wcf.acp.trophy.userTrophy.user"><![CDATA[User]]></item>
+ <item name="wcf.acp.trophy.userTrophy.user.description"><![CDATA[Enter the names of the users who should be awarded the trophy.]]></item>
+ <item name="wcf.acp.trophy.userTrophy.description"><![CDATA[Select the trophy who should be awarded to the users. You cannot select automatically awarded trophies.]]></item>
+ <item name="wcf.acp.trophy.userTrophy.useCustomDescription"><![CDATA[Use custom trophy description]]></item>
<item name="wcf.acp.trophy.userTrophy.delete.confirmMessage"><![CDATA[Do you really want to delete the trophy <span class="confirmationObject">{$userTrophy->getTrophy()->getTitle()}</span> from <span class="confirmationObject">{$userTrophy->getUserProfile()->username}</span>?]]></item>
</category>
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)
);