Add recent activity for trophies
authorJoshua Rüsweg <josh@bastelstu.be>
Sat, 29 Jul 2017 15:04:43 +0000 (17:04 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Sat, 29 Jul 2017 15:04:43 +0000 (17:04 +0200)
See #2315

com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/data/user/trophy/UserTrophyAction.class.php
wcfsetup/install/files/lib/form/SettingsForm.class.php
wcfsetup/install/files/lib/system/user/activity/event/TrophyReceivedUserActivityEvent.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 60d8105459fbc73e8246e82020fff86d636eeaf1..881a6586c1c32892c44ae5a5358f0652332d1e19 100644 (file)
                        <classname>wcf\system\user\notification\object\type\UserTrophyNotificationObjectType</classname>
                        <category>com.woltlab.wcf.user</category>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.userTrophy.recentActivityEvent.trophyReceived</name>
+                       <definitionname>com.woltlab.wcf.user.recentActivityEvent</definitionname>
+                       <classname>wcf\system\user\activity\event\TrophyReceivedUserActivityEvent</classname>
+               </type>
                <!-- /trophy -->
                
                <!-- deprecated -->
index 2d901014999f5304ee8063ff478a047174c3a6df..f4dcf49c6cfdacd2b39a5c0444e45742e7e42946 100644 (file)
@@ -6,6 +6,7 @@ use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
+use wcf\system\user\activity\event\UserActivityEventHandler;
 use wcf\system\user\notification\object\UserTrophyNotificationObject;
 use wcf\system\user\notification\UserNotificationHandler;
 use wcf\system\user\storage\UserStorageHandler;
@@ -46,6 +47,8 @@ class UserTrophyAction extends AbstractDatabaseObjectAction {
                        ]
                ]))->executeAction();
                
+               UserActivityEventHandler::getInstance()->fireEvent('com.woltlab.wcf.userTrophy.recentActivityEvent.trophyReceived', $returnValues->getObjectID(), null, $returnValues->userID);
+               
                UserNotificationHandler::getInstance()->fireEvent('received', 'com.woltlab.wcf.userTrophy.notification', new UserTrophyNotificationObject($returnValues), [
                        $returnValues->userID
                ]);
index b3d4a6e2a454ae789d69e40c15fdfb8b3310efa4..d46ae46dca131178234f998c488a50905dfe1ca4 100644 (file)
@@ -192,7 +192,7 @@ class SettingsForm extends AbstractForm {
                                if (!in_array($trophyID, array_map(function ($trophy) {
                                        return $trophy->trophyID; 
                                }, $this->availableTrophies))) {
-                                       throw new UserInputException('specialTrophies' , 'invalid');
+                                       throw new UserInputException('specialTrophies', 'invalid');
                                }
                        }
                }
diff --git a/wcfsetup/install/files/lib/system/user/activity/event/TrophyReceivedUserActivityEvent.class.php b/wcfsetup/install/files/lib/system/user/activity/event/TrophyReceivedUserActivityEvent.class.php
new file mode 100644 (file)
index 0000000..db723f3
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+namespace wcf\system\user\activity\event;
+use wcf\data\user\trophy\UserTrophyList;
+use wcf\system\SingletonFactory;
+use wcf\system\WCF;
+
+/**
+ * User activity event implementation for receiving a trophy.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\User\Activity\Event
+ */
+class TrophyReceivedUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
+       /**
+        * @inheritDoc
+        */
+       public function prepare(array $events) {
+               if (!MODULE_TROPHY || !WCF::getSession()->getPermission('user.profile.trophy.canSeeTrophies')) return;
+               
+               $objectIDs = [];
+               foreach ($events as $event) {
+                       $objectIDs[] = $event->objectID;
+               }
+               
+               $trophyList = new UserTrophyList();
+               $trophyList->getConditionBuilder()->add("user_trophy.userTrophyID IN (?)", [$objectIDs]);
+               $trophyList->readObjects();
+               $trophies = $trophyList->getObjects();
+               
+               foreach ($events as $event) {
+                       if (isset($trophies[$event->objectID])) {
+                               if (!$trophies[$event->objectID]->canSee()) {
+                                       continue;
+                               }
+                               
+                               $event->setIsAccessible();
+                               
+                               $event->setTitle(WCF::getLanguage()->getDynamicVariable('wcf.user.trophy.recentActivity.received', ['userTrophy' => $trophies[$event->objectID]]));
+                               $event->setDescription($trophies[$event->objectID]->getDescription());
+                       }
+                       else {
+                               $event->setIsOrphaned();
+                       }
+               }
+       }
+}
index b8b727c227a91844be58e1728a454238c590bcfc..c2b50771b5102a16a2d8e10a6850baabae9d5664 100644 (file)
@@ -3670,6 +3670,7 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <item name="wcf.user.trophy.specialTrophies.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Wähle{else}Wählen Sie{/if} hier ihre besonderen Trophäen aus, welche im Profil und in der Nachrichten-Seitenleiste angezeigt werden.]]></item>
                <item name="wcf.user.trophy.specialTrophies.error.tooMuch"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} maximal {#$__wcf->session->getPermission('user.profile.trophy.maxUserSpecialTrophies')} Trophäen auswählen.]]></item>
                <item name="wcf.user.trophy.specialTrophies.error.invalid"><![CDATA[Die angegebenen Trophäen sind invalid.]]></item>
+               <item name="wcf.user.trophy.recentActivity.received"><![CDATA[Hat die Trophäe „<a href="{$userTrophy->getTrophy()->getLink()}">{$userTrophy->getTrophy()->getTitle()}</a>“ erhalten.]]></item>
        </category>
        
        <category name="wcf.acp.trophy">
@@ -3738,6 +3739,7 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <item name="wcf.user.recentActivity.com.woltlab.wcf.likeableArticle.recentActivityEvent"><![CDATA[Like (Artikel)]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.articleComment.recentActivityEvent"><![CDATA[Kommentar (Artikel)]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.articleComment.response.recentActivityEvent"><![CDATA[Antwort (Artikel)]]></item>
+               <item name="wcf.user.recentActivity.com.woltlab.wcf.userTrophy.recentActivityEvent.trophyReceived"><![CDATA[Trophäe]]></item>
                <item name="wcf.user.recentActivity.condition.excludedObjectType"><![CDATA[Ausgeschlossene Aktivitäten]]></item>
                <item name="wcf.user.recentActivity.scope.all"><![CDATA[Aktivitäten aller Benutzer]]></item>
                <item name="wcf.user.recentActivity.scope.followedUsers"><![CDATA[Aktivitäten von Benutzern, denen {if LANGUAGE_USE_INFORMAL_VARIANT}du folgst{else}Sie folgen{/if}]]></item>
index bfc9913dbee9a08a5852e790c6b963cb9e1f56c6..9722aa325206422e992ed5b7b491fe220eac52ab 100644 (file)
@@ -3661,6 +3661,7 @@ Open the link below to access the user profile:
                <item name="wcf.user.trophy.specialTrophies.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Wähle{else}Wählen Sie{/if} hier ihre besonderen Trophäen aus, welche im Profil und in der Nachrichten-Seitenleiste angezeigt werden.]]></item>
                <item name="wcf.user.trophy.specialTrophies.error.tooMuch"><![CDATA[You can choose a maximum of {#$__wcf->session->getPermission('user.profile.trophy.maxUserSpecialTrophies')} trophies.]]></item>
                <item name="wcf.user.trophy.specialTrophies.error.invalid"><![CDATA[The selected trophies are invalid.]]></item>
+               <item name="wcf.user.trophy.recentActivity.received"><![CDATA[Has received the trophy “<a href="{$userTrophy->getTrophy()->getLink()}">{$userTrophy->getTrophy()->getTitle()}</a>”.]]></item>
        </category>
        
        <category name="wcf.acp.trophy">
@@ -3729,6 +3730,7 @@ Open the link below to access the user profile:
                <item name="wcf.user.recentActivity.com.woltlab.wcf.likeableArticle.recentActivityEvent"><![CDATA[Like (Article)]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.articleComment.recentActivityEvent"><![CDATA[Comment (Article)]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.articleComment.response.recentActivityEvent"><![CDATA[Reply (Article)]]></item>
+               <item name="wcf.user.recentActivity.com.woltlab.wcf.userTrophy.recentActivityEvent.trophyReceived"><![CDATA[Trophy]]></item>
                <item name="wcf.user.recentActivity.condition.excludedObjectType"><![CDATA[Excluded Activities]]></item>
                <item name="wcf.user.recentActivity.scope.all"><![CDATA[All Activities]]></item>
                <item name="wcf.user.recentActivity.scope.followedUsers"><![CDATA[Filter by Followed Users]]></item>