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

com.woltlab.wcf/acpMenu.xml
wcfsetup/install/files/acp/templates/userTrophyList.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/acp/page/UserTrophyListPage.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/user/trophy/UserTrophyAction.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 13ba392f2e1054b9d21b85c21bc0d4ebc3657e65..4986bd498f2a30e61448543d258ad1f2c397acbc 100644 (file)
                                <options>module_trophy</options>
                                <icon>fa-plus</icon>
                        </acpmenuitem>
+                       <acpmenuitem name="wcf.acp.menu.link.userTrophy.list">
+                               <controller>wcf\acp\page\UserTrophyListPage</controller>
+                               <parent>wcf.acp.menu.link.trophy</parent>
+                               <permissions>admin.trophy.canAwardTrophy</permissions>
+                               <options>module_trophy</options>
+                       </acpmenuitem>
                        <!-- /trophy -->
                
                <!-- /user -->
diff --git a/wcfsetup/install/files/acp/templates/userTrophyList.tpl b/wcfsetup/install/files/acp/templates/userTrophyList.tpl
new file mode 100644 (file)
index 0000000..6fbfdfa
--- /dev/null
@@ -0,0 +1,132 @@
+{include file='header' pageTitle='wcf.acp.menu.link.userTrophy.list'}
+
+<script data-relocate="true">
+       //<![CDATA[
+       $(function() {
+               new WCF.Search.User('#username');
+               new WCF.Action.Delete('wcf\\data\\user\\trophy\\UserTrophyAction', '.userTrophyRow');
+       });
+       //]]>
+</script>
+
+<header class="contentHeader">
+       <div class="contentHeaderTitle">
+               <h1 class="contentTitle">{lang}wcf.acp.menu.link.userTrophy.list{/lang}</h1>
+       </div>
+
+       <nav class="contentHeaderNavigation">
+               <ul>
+                       <li><a href="{link controller='UserTrophyAdd'}{/link}" class="button"><span class="icon icon16 fa-plus"></span> <span>{lang}wcf.acp.menu.link.userTrophy.add{/lang}</span></a></li>
+                       
+                       {event name='contentHeaderNavigation'}
+               </ul>
+       </nav>
+</header>
+
+<form method="post" action="{link controller='UserTrophyList'}{/link}">
+       <section class="section">
+               <h2 class="sectionTitle">{lang}wcf.global.filter{/lang}</h2>
+
+               <div class="row rowColGap formGrid">
+                       <dl class="col-xs-12 col-md-6">
+                               <dt></dt>
+                               <dd>
+                                       <select name="trophyID" id="trophyID" class="long">
+                                               <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}>&nbsp;&nbsp;&nbsp;&nbsp;{$trophy->getTitle()}</option>
+                                                       {/foreach}
+                                               {/foreach}
+                                       </select>
+                               </dd>
+                       </dl>
+                       
+                       <dl class="col-xs-12 col-md-6">
+                               <dt></dt>
+                               <dd>
+                                       <input type="text" id="username" name="username" value="{$username}" placeholder="{lang}wcf.user.username{/lang}" class="long">
+                               </dd>
+                       </dl>
+                       
+                       {event name='filterFields'}
+               </div>
+               
+               <div class="formSubmit">
+                       <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
+
+                       {@SECURITY_TOKEN_INPUT_TAG}
+               </div>
+       </section>
+</form>
+
+{hascontent}
+       <div class="paginationTop">
+               {content}
+               {assign var='linkParameters' value=''}
+                       {if $trophyID}{capture append=linkParameters}&trophyID={@$trophyID|rawurlencode}{/capture}{/if}
+                       {if $username}{capture append=linkParameters}&username={@$username|rawurlencode}{/capture}{/if}
+                       
+               {pages print=true assign=pagesLinks controller='UserTrophyList' link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder$linkParameters"}
+               {/content}
+       </div>
+{/hascontent}
+
+{if $objects|count}
+       <div class="section tabularBox">
+
+               <table class="table">
+                       <thead>
+                       <tr>
+                               <th class="columnID columnUserTrophyID{if $sortField == 'userTrophyID'} active {@$sortOrder}{/if}" colspan="2"><a href="{link controller='UserTrophyList'}pageNo={@$pageNo}&sortField=userTrophyID&sortOrder={if $sortField == 'userTrophyID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{@$linkParameters}{/link}">{lang}wcf.global.objectID{/lang}</a></th>
+                               <th class="columnText columnUsername{if $sortField == 'userID'} active {@$sortOrder}{/if}"><a href="{link controller='UserTrophyList'}pageNo={@$pageNo}&sortField=userID&sortOrder={if $sortField == 'userID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{@$linkParameters}{/link}">{lang}wcf.user.username{/lang}</a></th>
+                               <th class="columnTitle columnTrophy{if $sortField == 'trophyID'} active {@$sortOrder}{/if}"><a href="{link controller='UserTrophyList'}pageNo={@$pageNo}&sortField=trophyID&sortOrder={if $sortField == 'trophyID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{@$linkParameters}{/link}">{lang}wcf.acp.trophy{/lang}</a></th>
+                               <th class="columnDate columnUserTrophyTime{if $sortField == 'time'} active {@$sortOrder}{/if}"><a href="{link controller='UserTrophyList'}pageNo={@$pageNo}&sortField=time&sortOrder={if $sortField == 'time' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{@$linkParameters}{/link}">{lang}wcf.global.date{/lang}</a></th>
+
+                               {event name='columnHeads'}
+                       </tr>
+                       </thead>
+
+                       <tbody>
+                       {foreach from=$objects item=userTrophy}
+                               <tr class="userTrophyRow">
+                                       <td class="columnIcon">
+                                               <a href="{link controller='UserTrophyEdit' id=$userTrophy->userTrophyID}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip"><span class="icon icon16 fa-pencil"></span></a>
+                                               <span class="icon icon16 fa-times pointer jsDeleteButton jsTooltip" data-confirm-message-html="{lang __encode="true"}wcf.acp.trophy.userTrophy.delete.confirmMessage{/lang}" data-object-id="{@$userTrophy->getObjectID()}" title="{lang}wcf.global.button.delete{/lang}"></span>
+                                       </td>
+                                       <td class="columnID columnUserTrophyID">{@$userTrophy->userTrophyID}</td>
+                                       <td class="columnText columnUsername"><a href="{link controller='UserEdit' id=$userTrophy->userID}{/link}" title="{lang}wcf.acp.user.edit{/lang}">{$userTrophy->getUserProfile()->username}</a></td>
+                                       <td class="columnTitle columnTrophy">{$userTrophy->getTrophy()->getTitle()}</td>
+                                       <td class="columnDate columnUserTrophyTime">{@$userTrophy->time|time}</td>
+
+                                       {event name='columns'}
+                               </tr>
+                       {/foreach}
+                       </tbody>
+               </table>
+
+       </div>
+
+
+       <footer class="contentFooter">
+               {hascontent}
+                       <div class="paginationBottom">
+                               {content}{@$pagesLinks}{/content}
+                       </div>
+               {/hascontent}
+
+               <nav class="contentFooterNavigation">
+                       <ul>
+                               <li><a href="{link controller='UserTrophyAdd'}{/link}" class="button"><span class="icon icon16 fa-plus"></span> <span>{lang}wcf.acp.menu.link.userTrophy.add{/lang}</span></a></li>
+
+                               {event name='contentHeaderNavigation'}
+                       </ul>
+               </nav>
+       </footer>
+{else}
+       <p class="info">{lang}wcf.global.noItems{/lang}</p>
+{/if}
+
+{include file='footer'}
diff --git a/wcfsetup/install/files/lib/acp/page/UserTrophyListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserTrophyListPage.class.php
new file mode 100644 (file)
index 0000000..e65d32c
--- /dev/null
@@ -0,0 +1,118 @@
+<?php
+namespace wcf\acp\page;
+use wcf\data\trophy\category\TrophyCategoryCache;
+use wcf\data\trophy\Trophy;
+use wcf\data\user\trophy\UserTrophyList;
+use wcf\page\SortablePage;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
+
+/**
+ * User trophy list page.
+ *
+ * @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\Page
+ * @since      3.1
+ */
+class UserTrophyListPage extends SortablePage {
+       /**
+        * @inheritDoc
+        */
+       public $activeMenuItem = 'wcf.acp.menu.link.userTrophy.list';
+       
+       /**
+        * @inheritDoc
+        */
+       public $neededModules = ['MODULE_TROPHY'];
+       
+       /**
+        * @inheritDoc
+        */
+       public $neededPermissions = ['admin.trophy.canAwardTrophy'];
+       
+       /**
+        * @inheritDoc
+        */
+       public $defaultSortField = 'time';
+       
+       /**
+        * @inheritDoc
+        */
+       public $defaultSortOrder = 'DESC';
+       
+       /**
+        * @inheritDoc
+        */
+       public $objectListClassName = UserTrophyList::class;
+       
+       /**
+        * @inheritDoc
+        */
+       public $validSortFields = ['userTrophyID', 'trophyID', 'userID', 'time'];
+       
+       /**
+        * The filter value for the username search.
+        * @var string
+        */
+       public $username = '';
+       
+       /**
+        * The filter value for the trophy id.
+        * @var integer
+        */
+       public $trophyID = 0;
+       
+       /**
+        * The trophy instance for the filter value.
+        * @var Trophy
+        */
+       public $trophy = null;
+       
+       /**
+        * @inheritdoc
+        */
+       public function readParameters() {
+               parent::readParameters();
+               
+               if (isset($_REQUEST['username'])) $this->username = StringUtil::trim($_REQUEST['username']);
+               if (isset($_REQUEST['trophyID'])) {
+                       $this->trophyID = intval($_REQUEST['trophyID']);
+                       $this->trophy = new Trophy($this->trophyID);
+                       
+                       if (!$this->trophy->getObjectID()) {
+                               $this->trophyID = 0;
+                       }
+               }
+       }
+       
+       /**
+        * @inheritdoc
+        */
+       protected function initObjectList() {
+               parent::initObjectList();
+               
+               if ($this->trophyID) {
+                       $this->objectList->getConditionBuilder()->add('user_trophy.trophyID = ?', [$this->trophyID]);
+               }
+               
+               if ($this->username) {
+                       $this->objectList->getConditionBuilder()->add('user_trophy.userID IN (SELECT userID FROM wcf' . WCF_N . '_user WHERE username LIKE ?)', ['%' . $this->username . '%']);
+               }
+       }
+       
+       /**
+        * @inheritdoc
+        */
+       public function assignVariables() {
+               parent::assignVariables();
+               
+               WCF::getTPL()->assign([
+                       'trophyID' => $this->trophyID,
+                       'username' => $this->username,
+                       'trophyCategories' => TrophyCategoryCache::getInstance()->getCategories(),
+               ]);
+               
+       }
+}
index c6fc1d0003338789e916ca6b04abf99071321d16..1a42571dce728a3ec13852e000145fc7e56a3db7 100644 (file)
@@ -50,7 +50,7 @@ class UserTrophyAction extends AbstractDatabaseObjectAction {
                foreach ($updateUserTrophies as $userID => $count) {
                        (new UserAction([$userID], 'update', [
                                'counters' => [
-                                       'trophies' => $count
+                                       'trophyPoints' => $count
                                ]
                        ]))->executeAction();
                }
index dfeadd24f352ece89f1db674e281f946f6785b05..f65cb9b606c29efb03da8b791c22407aa42a9ecb 100644 (file)
                <item name="wcf.acp.menu.link.trophy.list"><![CDATA[Trophäen]]></item>
                <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.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>
        </category>
@@ -3605,6 +3607,7 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
        </category>
        
        <category name="wcf.acp.trophy">
+               <item name="wcf.acp.trophy"><![CDATA[Trophäe]]></item>
                <item name="wcf.acp.trophy.description"><![CDATA[Beschreibung]]></item>
                <item name="wcf.acp.trophy.category"><![CDATA[Kategorie]]></item>
                <item name="wcf.acp.trophy.isDisabled"><![CDATA[Trophäe deaktivieren]]></item>
@@ -3624,6 +3627,7 @@ 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.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>
        
        <category name="wcf.user.usersOnline">
index 5d9b486b2aa0b75c5b3609dfb93ef6784bf3153c..92364c5c1dacdabd4161242a66cb4d263928b475 100644 (file)
                <item name="wcf.acp.menu.link.trophy.list"><![CDATA[Trophies]]></item>
                <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.edit"><![CDATA[Edit assigned Trophy]]></item>
        </category>
        
        <category name="wcf.acp.notice">
@@ -3569,6 +3571,7 @@ Open the link below to access the user profile:
        </category>
        
        <category name="wcf.acp.trophy">
+               <item name="wcf.acp.trophy"><![CDATA[Trophy]]></item>
                <item name="wcf.acp.trophy.description"><![CDATA[Description]]></item>
                <item name="wcf.acp.trophy.category"><![CDATA[Category]]></item>
                <item name="wcf.acp.trophy.isDisabled"><![CDATA[Disable Trophy]]></item>
@@ -3588,6 +3591,7 @@ 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.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>
        
        <category name="wcf.user.usersOnline">