From f5c39edf3f6cf313224f5015a11a7194e59a0235 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Thu, 28 Jun 2018 18:39:22 +0200 Subject: [PATCH] Add trait to determine the count of reactionTypeIDs for a specific user notification event See #2508 --- .../TReactionUserNotificationEvent.class.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/user/notification/event/TReactionUserNotificationEvent.class.php diff --git a/wcfsetup/install/files/lib/system/user/notification/event/TReactionUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/TReactionUserNotificationEvent.class.php new file mode 100644 index 0000000000..6842467802 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/notification/event/TReactionUserNotificationEvent.class.php @@ -0,0 +1,77 @@ + + * @package WoltLabSuite\Core\System\User\Notification\Event + * @since 3.2 + */ +trait TReactionUserNotificationEvent { + /** + * Cached reactions + * @var int[] + */ + private $cachedReactions; + + /** + * Returns the count of reactionTypeIDs for the specific user notification object. + * + * @return int[] + */ + protected final function getReactionsForAuthors(): array { + if ($this->cachedReactions !== null) { + return $this->cachedReactions; + } + + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('like_table.userID IN (?)', [array_keys($this->getAuthors())]); + $conditionBuilder->add('like_table_join.likeID = ?', [$this->getUserNotificationObject()->getObjectID()]); + + $sql = "SELECT like_table.reactionTypeID, COUNT(like_table.reactionTypeID) as count + FROM wcf".WCF_N."_like like_table + LEFT JOIN wcf".WCF_N."_like like_table_join + ON like_table_join.objectTypeID = like_table.objectTypeID AND like_table_join.objectID = like_table.objectID + ".$conditionBuilder." + GROUP BY like_table.reactionTypeID"; + + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + + $this->cachedReactions = $statement->fetchMap('reactionTypeID', 'count'); + + return $this->cachedReactions; + } + + /** + * Returns the author for this notification event. + * + * @return UserProfile + */ + abstract public function getAuthor(); + + /** + * Returns a list of authors for stacked notifications sorted by time. + * + * @return UserProfile[] + */ + abstract public function getAuthors(); + + /** + * Returns the underlying user notification object. + * + * @return IUserNotificationObject + */ + abstract public function getUserNotificationObject(); +} -- 2.20.1