Skip to content

Commit

Permalink
Check if members module is enabled (#3532)
Browse files Browse the repository at this point in the history
  • Loading branch information
partydragen authored Jul 29, 2024
1 parent 771d21d commit 5715774
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions modules/Forum/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,32 @@ public function __construct(Language $language, Language $forum_language, Pages
EventHandler::registerListener('renderPostEdit', 'ContentHook::purify');
EventHandler::registerListener('renderPostEdit', 'ContentHook::replaceAnchors', 15);

MemberListManager::getInstance()->registerListProvider(new MostPostsMemberListProvider($forum_language));
MemberListManager::getInstance()->registerListProvider(new HighestForumReactionScoresMemberListProvider($forum_language));

MemberListManager::getInstance()->registerMemberMetadataProvider(function (User $member) use ($forum_language) {
return [
$forum_language->get('forum', 'posts_title') =>
DB::getInstance()->query(
'SELECT COUNT(post_content) AS `count` FROM nl2_posts WHERE post_creator = ?',
[$member->data()->id]
)->first()->count,
];
});

MemberListManager::getInstance()->registerMemberMetadataProvider(function (User $member) use ($forum_language) {
return [
$forum_language->get('forum', 'reaction_score') =>
DB::getInstance()->query(
'SELECT COUNT(fr.user_received) AS `count` FROM nl2_forums_reactions fr JOIN nl2_reactions r ON r.id = fr.reaction_id WHERE r.type = 2 AND fr.user_received = ?',
[$member->data()->id]
)->first()->count,
];
});

ReactionContextsManager::getInstance()->provideContext(new ForumPostReactionContext($forum_language));
if (Util::isModuleEnabled('Members')) {
MemberListManager::getInstance()->registerListProvider(new MostPostsMemberListProvider($forum_language));
MemberListManager::getInstance()->registerListProvider(new HighestForumReactionScoresMemberListProvider($forum_language));

MemberListManager::getInstance()->registerMemberMetadataProvider(function (User $member) use ($forum_language) {
return [
$forum_language->get('forum', 'posts_title') =>
DB::getInstance()->query(
'SELECT COUNT(post_content) AS `count` FROM nl2_posts WHERE post_creator = ?',
[$member->data()->id]
)->first()->count,
];
});

MemberListManager::getInstance()->registerMemberMetadataProvider(function (User $member) use ($forum_language) {
return [
$forum_language->get('forum', 'reaction_score') =>
DB::getInstance()->query(
'SELECT COUNT(fr.user_received) AS `count` FROM nl2_forums_reactions fr JOIN nl2_reactions r ON r.id = fr.reaction_id WHERE r.type = 2 AND fr.user_received = ?',
[$member->data()->id]
)->first()->count,
];
});

ReactionContextsManager::getInstance()->provideContext(new ForumPostReactionContext($forum_language));
}
}

public function onInstall() {
Expand Down

0 comments on commit 5715774

Please sign in to comment.