Add user trophy add form
authorJoshua Rüsweg <josh@bastelstu.be>
Wed, 12 Jul 2017 12:42:12 +0000 (14:42 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Wed, 12 Jul 2017 12:42:12 +0000 (14:42 +0200)
See #2315

com.woltlab.wcf/acpMenu.xml
wcfsetup/install/files/acp/templates/userTrophyAdd.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/acp/form/TrophyAddForm.class.php
wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php
wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml
wcfsetup/setup/db/install.sql

index 4986bd498f2a30e61448543d258ad1f2c397acbc..75536171dceb930172a1b026d286e076955441e8 100644 (file)
                                <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 -->
diff --git a/wcfsetup/install/files/acp/templates/userTrophyAdd.tpl b/wcfsetup/install/files/acp/templates/userTrophyAdd.tpl
new file mode 100644 (file)
index 0000000..a821015
--- /dev/null
@@ -0,0 +1,118 @@
+{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}>&nbsp;&nbsp;&nbsp;&nbsp;{$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'}
index f0863c21ea3303673bb541f82e0152705382660c..8c41182f8c17955eb9552f4a7366c3ea7dde2dbf 100644 (file)
@@ -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
                ]);
index 2ec278765e88500b6012ccd305a959a0e4789096..18e36b4bda3461039ef4587cc0ea6f745fc8a430 100644 (file)
@@ -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 (file)
index 0000000..e9dfeb0
--- /dev/null
@@ -0,0 +1,180 @@
+<?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
+               ]);
+       }
+}
index f65cb9b606c29efb03da8b791c22407aa42a9ecb..c9e99f660b5fa2febcc9c16008670b0a148b18d7 100644 (file)
                <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>
@@ -3627,6 +3628,10 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <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>
        
index 92364c5c1dacdabd4161242a66cb4d263928b475..9924b1f8d9314d135eadded2034818c226f78f2e 100644 (file)
                <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>
        
@@ -3591,6 +3592,10 @@ Open the link below to access the user profile:
                <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>
        
index 12984db6bcfc94a01f3a2de866b7bc89e89526c1..ed324aff9d2eed434299e723e757b30637aa113a 100644 (file)
@@ -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)
 );