Ass user trophy received user notification
authorJoshua Rüsweg <josh@bastelstu.be>
Sat, 15 Jul 2017 20:58:41 +0000 (22:58 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Sat, 15 Jul 2017 20:58:41 +0000 (22:58 +0200)
See #2315

com.woltlab.wcf/userNotificationEvent.xml
wcfsetup/install/files/lib/data/user/trophy/UserTrophyAction.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserTrophyReceivedNotificationEvent.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/user/notification/object/UserTrophyNotificationObject.class.php
wcfsetup/install/files/lib/system/user/notification/object/type/UserTrophyNotificationObjectType.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 07d121f8d5900a0b3c26137c1c64cb41bea226cb..e702745230b788459599a34789dea537ff624f07 100644 (file)
                        <classname>wcf\system\user\notification\event\ExpiringPaidSubscriptionUserUserNotificationEvent</classname>
                        <options>module_paid_subscription</options>
                </event>
+               
+               <event>
+                       <name>received</name>
+                       <objecttype>com.woltlab.wcf.userTrophy.notification</objecttype>
+                       <classname>wcf\system\user\notification\event\UserTrophyReceivedNotificationEvent</classname>
+                       <preset>1</preset>
+                       <options>module_trophy</options>
+                       <permissions>user.profile.trophy.canSeeTrophies</permissions>
+               </event>
        </import>
 </data>
index 418b59314f3b205ff21b9b003dd78aa77dec9790..a10888ac33204caf7b3a91f74e2d6fa424761362 100644 (file)
@@ -3,6 +3,8 @@ namespace wcf\data\user\trophy;
 use wcf\data\user\UserAction;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\system\exception\PermissionDeniedException;
+use wcf\system\user\notification\object\UserTrophyNotificationObject;
+use wcf\system\user\notification\UserNotificationHandler;
 
 /**
  * Provides user trophy actions. 
@@ -31,6 +33,10 @@ class UserTrophyAction extends AbstractDatabaseObjectAction {
                        ]
                ]))->executeAction();
                
+               UserNotificationHandler::getInstance()->fireEvent('received', 'com.woltlab.wcf.userTrophy.notification', new UserTrophyNotificationObject($returnValues), [
+                       $returnValues->userID
+               ]);
+               
                return $returnValues; 
        }
        
diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserTrophyReceivedNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserTrophyReceivedNotificationEvent.class.php
new file mode 100644 (file)
index 0000000..14e7bfe
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+namespace wcf\system\user\notification\event;
+
+/**
+ * Notification event for receiving a user 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\Notification\Object\Type
+ */
+class UserTrophyReceivedNotificationEvent extends AbstractUserNotificationEvent {
+       /**
+        * @inheritDoc
+        */
+       public function getTitle() {
+               return $this->getLanguage()->get('wcf.user.notification.com.woltlab.wcf.userTrophy.notification.received');
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function getMessage() {
+               return $this->getLanguage()->getDynamicVariable('wcf.user.notification.trophy.received.message', [
+                       'userTrophy' => $this->userNotificationObject,
+                       'author' => $this->author
+               ]);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function supportsEmailNotification() {
+               return false;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function getLink() {
+               return $this->userNotificationObject->getTrophy()->getLink();
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function checkAccess() {
+               return $this->userNotificationObject->getDecoratedObject()->canSee();
+       }
+}
index 0451ea714a4317bb2f713fc49c74438150fb61e9..ae8d258bf3e9570f602749d84df2bb69f11b0e76 100644 (file)
@@ -4,7 +4,7 @@ use wcf\data\user\trophy\UserTrophy;
 use wcf\data\DatabaseObjectDecorator;
 
 /**
- * Represents a following user as a notification object.
+ * Represents a user trophy notification object.
  *
  * @author     Joshua Ruesweg
  * @copyright  2001-2017 WoltLab GmbH
@@ -16,26 +16,26 @@ use wcf\data\DatabaseObjectDecorator;
  */
 class UserTrophyNotificationObject extends DatabaseObjectDecorator implements IUserNotificationObject {
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        protected static $baseClass = UserTrophy::class;
        
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        public function getTitle() {
                return $this->getDecoratedObject()->getTrophy()->getTitle();
        }
        
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        public function getURL() {
                return $this->getDecoratedObject()->getTrophy()->getLink();
        }
        
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        public function getAuthorID() {
                return $this->getDecoratedObject()->userID;
index 580b5a878b6495bd05ac42d41e8abe4eb90b9ea0..9bc4feebe9cc6058937d060460041a685e4edc79 100644 (file)
@@ -14,17 +14,17 @@ use wcf\system\user\notification\object\UserTrophyNotificationObject;
  */
 class UserTrophyNotificationObjectType extends AbstractUserNotificationObjectType {
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        protected static $decoratorClassName = UserTrophyNotificationObject::class;
        
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        protected static $objectClassName = UserTrophy::class;
        
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        protected static $objectListClassName = UserTrophyList::class;
 }
index 36e9d835470ceb812c5c557b962a5079f1161d8c..cbd456bb887048282abfa7bf8a29a998b139db2a 100644 (file)
@@ -3884,6 +3884,8 @@ Benachrichtigungen auf <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language
                <item name="wcf.user.notification.com.woltlab.wcf.user.profileComment.like.notification.like"><![CDATA[Jemandem gefällt {if LANGUAGE_USE_INFORMAL_VARIANT}dein{else}Ihr{/if} Kommentar]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.user.profileComment.response.like.notification.like"><![CDATA[Jemandem gefällt {if LANGUAGE_USE_INFORMAL_VARIANT}deine{else}Ihre{/if} Antwort auf einen Kommentar]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.paidSubscription.user.expiring"><![CDATA[Eine {if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Mitgliedschaft läuft bald ab]]></item>
+               <item name="wcf.user.notification.com.woltlab.wcf.userTrophy.notification.received"><![CDATA[Trophäe erhalten]]></item>
+               <item name="wcf.user.notification.trophy.received.message"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} die Trophäe „<a href="{$userTrophy->getTrophy()->getLink()}">{$userTrophy->getTrophy()->getTitle()}</a>“ erhalten.]]></item>
                
                <item name="wcf.user.notification.com.woltlab.wcf.moderation"><![CDATA[Moderation]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.moderation.queue.notification.comment"><![CDATA[Neuer Kommentar in der Moderation]]></item>
index 39176eef21d7a410c93ad2494676d36c2dd982f3..cebdf6667fce51b006de1a26f32f915ed8b95e30 100644 (file)
@@ -3873,6 +3873,8 @@ your notifications on <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language}
                <item name="wcf.user.notification.com.woltlab.wcf.user.profileComment.like.notification.like"><![CDATA[Notify me when my comments are liked]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.user.profileComment.response.like.notification.like"><![CDATA[Notify me when replies to my comments are liked]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.paidSubscription.user.expiring"><![CDATA[Notify me before a subscription will expire]]></item>
+               <item name="wcf.user.notification.com.woltlab.wcf.userTrophy.notification.received"><![CDATA[Trophy received]]></item>
+               <item name="wcf.user.notification.trophy.received.message"><![CDATA[You got the trophy “<a href="{$userTrophy->getTrophy()->getLink()}">{$userTrophy->getTrophy()->getTitle()}</a>“.]]></item>
                
                <item name="wcf.user.notification.com.woltlab.wcf.moderation"><![CDATA[Moderation]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.moderation.queue.notification.comment"><![CDATA[Notify me when new comments are written in moderation]]></item>