Added a warning if the user wanted to award a trophy and there were no suitable trophies
authorJoshua Rüsweg <josh@bastelstu.be>
Mon, 2 Apr 2018 15:25:08 +0000 (17:25 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Mon, 2 Apr 2018 15:25:08 +0000 (17:25 +0200)
wcfsetup/install/files/acp/templates/userTrophyAdd.tpl
wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 8ffdfccd27fa458e455dc950251bef6693369aeb..38c6b1e7db63196786f111e6a03df2d8ce267d96 100644 (file)
        <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>
-                               {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 $hasSuitableTrophy}
+       <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>
+                                       {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>
-                               {/if}
-                       </dd>
-               </dl>
-               
-               <dl{if $errorField == 'trophyID'} class="formError"{/if}>
-                       <dt><label for="trophyID">{lang}wcf.acp.trophy{/lang}</label></dt>
-                       <dd>
-                               {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'}
+                               </dd>
+                       </dl>
+                       
+                       <dl{if $errorField == 'trophyID'} class="formError"{/if}>
+                               <dt><label for="trophyID">{lang}wcf.acp.trophy{/lang}</label></dt>
+                               <dd>
+                                       {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}
+                               </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>
+                                       <input id="description" name="description" type="text" value="{$i18nPlainValues[description]}">
+                                       {if $errorField == 'description'}
                                                <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}
+                                                       {elseif $errorType == 'multilingual'}
+                                                               {lang}wcf.global.form.error.multilingual{/lang}
                                                        {/if}
                                                </small>
                                        {/if}
-                                       <small>{lang}wcf.acp.trophy.userTrophy.description{/lang}</small>
-                               {/if}
-                       </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>
-                               <input id="description" name="description" type="text" value="{$i18nPlainValues[description]}">
-                               {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'}
+                               </dd>
+                       </dl>
+                       {include file='multipleLanguageInputJavascript' elementIdentifier='description' forceSelection=false}
+                       
+                       {event name='dataFields'}
+               </div>
        
-       <div class="formSubmit">
-               <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
-               {@SECURITY_TOKEN_INPUT_TAG}
-       </div>
-</form>
+               {event name='sections'}
+               
+               <div class="formSubmit">
+                       <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
+                       {@SECURITY_TOKEN_INPUT_TAG}
+               </div>
+       </form>
+{else}
+       <p class="error">{lang}wcf.acp.trophy.error.noSuitableTrophies{/lang}</p>
+{/if}
 
 {include file='footer'}
index 4c8bdb52a71c86c7baa49bd2ab9cc38693bbef76..85c405779bb36753e0bf7a40182815af7940b7cc 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\acp\form;
 use wcf\data\trophy\category\TrophyCategoryCache;
 use wcf\data\trophy\Trophy;
+use wcf\data\trophy\TrophyCache;
 use wcf\data\user\trophy\UserTrophyAction;
 use wcf\data\user\trophy\UserTrophyEditor;
 use wcf\data\user\UserProfile;
@@ -198,7 +199,23 @@ class UserTrophyAddForm extends AbstractAcpForm {
                        'trophyID' => $this->trophyID,
                        'user' => $this->user,
                        'trophyCategories' => TrophyCategoryCache::getInstance()->getCategories(),
-                       'useCustomDescription' => $this->useCustomDescription
+                       'useCustomDescription' => $this->useCustomDescription, 
+                       'hasSuitableTrophy' => $this->hasSuitableTrophy()
                ]);
        }
+       
+       /**
+        * Returns true if trophies exist that are not automatically awarded. 
+        * 
+        * @return bool
+        */
+       private function hasSuitableTrophy() {
+               foreach (TrophyCache::getInstance()->getTrophies() as $trophy) {
+                       if (!$trophy->awardAutomatically) {
+                               return true;
+                       }
+               }
+               
+               return false;
+       }
 }
index 1112eee47a72d1c5a1e837860adf32145974d9ad..f84ccecbcb29cf6868d9ff7483fb199722f021ef 100644 (file)
@@ -3812,6 +3812,7 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <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>
                <item name="wcf.acp.trophy.error.noCategories"><![CDATA[Bevor Sie eine Trophäe hinzufügen können, müssen Sie eine <a href="{link controller='TrophyCategoryAdd'}{/link}">Kategorie hinzufügen</a>.]]></item>
+               <item name="wcf.acp.trophy.error.noSuitableTrophies"><![CDATA[Bevor {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} eine Trophäe vergeben {if LANGUAGE_USE_INFORMAL_VARIANT}kannst, musst du{else}können, müssen Sie{/if} eine <a href="{link controller='TrophyAdd'}{/link}">Trophäe hinzufügen</a>, welche nicht automatisch durch das System vergeben wird.]]></item>
        </category>
        
        <category name="wcf.user.usersOnline">
index 041752f99f34c42f663e7ddb8f321ab3e8e4a14d..7fa33f95b385f7721bd37311c2aefbdf5ebf43f8 100644 (file)
@@ -3804,6 +3804,7 @@ Open the link below to access the user profile:
                <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>
                <item name="wcf.acp.trophy.error.noCategories"><![CDATA[Please <a href="{link controller='TrophyCategoryAdd'}{/link}">add a category</a> before creating trophies.]]></item>
+               <item name="wcf.acp.trophy.error.noSuitableTrophies"><![CDATA[Please <a href="{link controller='TrophyAdd'}{/link}">add a trophy</a> that is not automatically awarded before you award trophies.]]></item>
        </category>
        
        <category name="wcf.user.usersOnline">