Added most active forum category and topic to profiles.

This commit is contained in:
flash 2023-02-10 09:04:15 +00:00
parent b9b80e17d0
commit d423c53cde
5 changed files with 162 additions and 1 deletions

View file

@ -0,0 +1,24 @@
.profile__forum-activity__content {
margin: 5px;
}
.profile__forum-activity__topic {
margin-top: 5px;
}
.profile__forum-activity__leader {
font-size: .9em;
margin: 0 5px;
}
.profile__forum-activity .forum__category__icon {
width: 30px;
height: 30px;
font-size: 1.5em;
line-height: 1.5em;
flex: 0 0 30px;
}
.profile__forum-activity .forum__category {
background-color: rgba(17, 17, 17, .6);
}

View file

@ -353,10 +353,20 @@ switch($profileMode) {
$template = 'profile.index';
$warnings = $profileUser->getProfileWarnings($currentUser);
$activeCategoryStats = $viewingAsGuest ? null : forum_get_user_most_active_category_info($profileUser->getId());
$activeCategoryInfo = empty($activeCategoryStats->forum_id) ? null : forum_get($activeCategoryStats->forum_id);
$activeTopicStats = $viewingAsGuest ? null : forum_get_user_most_active_topic_info($profileUser->getId());
$activeTopicInfo = empty($activeTopicStats->topic_id) ? null : forum_topic_get($activeTopicStats->topic_id);
Template::set([
'profile_warnings' => $warnings,
'profile_warnings_view_private' => $canManageWarnings,
'profile_warnings_can_manage' => $canManageWarnings,
'profile_active_category_stats' => $activeCategoryStats,
'profile_active_category_info' => $activeCategoryInfo,
'profile_active_topic_stats' => $activeTopicStats,
'profile_active_topic_info' => $activeTopicInfo,
]);
break;
}

View file

@ -526,3 +526,18 @@ function forum_count_synchronise(int $forumId = MSZ_FORUM_ROOT, bool $save = tru
return compact('topics', 'posts');
}
function forum_get_user_most_active_category_info(int $userId): ?object {
if($userId < 1)
return null;
global $cfg;
$getActiveForum = \Misuzu\DB::prepare(sprintf(
'SELECT forum_id, COUNT(*) AS post_count FROM msz_forum_posts WHERE user_id = :user AND post_deleted IS NULL AND forum_id NOT IN (%s) GROUP BY forum_id ORDER BY post_count DESC LIMIT 1',
implode(',', $cfg->getValue('forum_leader.unranked.forum', \Misuzu\Config\IConfig::T_ARR))
));
$getActiveForum->bind('user', $userId);
return $getActiveForum->fetchObject();
}

View file

@ -652,3 +652,18 @@ function forum_topic_nuke(int $topicId): bool {
$nukeTopic->bind('topic', $topicId);
return $nukeTopic->execute();
}
function forum_get_user_most_active_topic_info(int $userId): ?object {
if($userId < 1)
return null;
global $cfg;
$getActiveForum = \Misuzu\DB::prepare(sprintf(
'SELECT topic_id, COUNT(*) AS post_count FROM msz_forum_posts WHERE user_id = :user AND post_deleted IS NULL AND forum_id NOT IN (%s) GROUP BY topic_id ORDER BY post_count DESC LIMIT 1',
implode(',', $cfg->getValue('forum_leader.unranked.forum', \Misuzu\Config\IConfig::T_ARR))
));
$getActiveForum->bind('user', $userId);
return $getActiveForum->fetchObject();
}

View file

@ -81,7 +81,8 @@
{% set show_profile_fields = profile_is_editing ? perms.edit_profile : profile_fields|length > 0 %}
{% set show_background_settings = profile_is_editing and perms.edit_background %}
{% set show_birthdate = profile_is_editing and perms.edit_birthdate %}
{% set show_sidebar = show_profile_fields or show_background_settings %}
{% set show_active_forum_info = not profile_is_editing and (profile_active_category_info.forum_id|default(0) > 0 or profile_active_topic_info.topic_id|default(0) > 0) %}
{% set show_sidebar = show_profile_fields or show_background_settings or show_birthdate or show_active_forum_info %}
{% if show_sidebar %}
<div class="profile__content__side">
@ -136,6 +137,102 @@
</div>
</div>
{% endif %}
{% if show_active_forum_info %}
<div class="container profile__container profile__forum-activity">
{{ container_title('Forum Activity') }}
<div class="profile__forum-activity__content">
{% if profile_active_category_info is not empty %}
<div class="profile__forum-activity__category">
{% set forum = profile_active_category_info %}
{% if forum.forum_icon is defined and forum.forum_icon is not empty %}
{% set forum_icon = forum.forum_icon %}
{% elseif forum.forum_archived is defined and forum.forum_archived %}
{% set forum_icon = 'fas fa-archive fa-fw' %}
{% elseif forum.forum_type is defined and forum.forum_type != constant('MSZ_FORUM_TYPE_DISCUSSION') %}
{% if forum.forum_type == constant('MSZ_FORUM_TYPE_LINK') %}
{% set forum_icon = 'fas fa-link fa-fw' %}
{% elseif forum.forum_type == constant('MSZ_FORUM_TYPE_CATEGORY') %}
{% set forum_icon = 'fas fa-folder fa-fw' %}
{% endif %}
{% else %}
{% set forum_icon = 'fas fa-comments fa-fw' %}
{% endif %}
<div class="profile__forum-activity__leader">
Most active category
</div>
<div class="forum__category">
<a href="{{ url('forum-category', {'forum': forum.forum_id}) }}" class="forum__category__link"></a>
<div class="forum__category__container">
<div class="forum__category__icon">
<span class="{{ forum_icon }}"></span>
</div>
<div class="forum__category__details">
<div class="forum__category__title">
{{ forum.forum_name }}
</div>
<div class="forum__category__description">
{{ profile_active_category_stats.post_count|number_format }} post{{ profile_active_category_stats.post_count == 1 ? '' : 's' }}
/ {{ ((profile_active_category_stats.post_count / profile_stats.forum_post_count) * 100)|number_format(2) }}% of total posts
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% if profile_active_topic_info is not empty %}
<div class="profile__forum-activity__topic">
{% set topic = profile_active_topic_info %}
{% if topic.topic_deleted is defined and topic.topic_deleted is not null %}
{% set topic_icon = 'fas fa-trash-alt' %}
{% elseif topic.topic_type is defined and topic.topic_type != constant('MSZ_TOPIC_TYPE_DISCUSSION') %}
{% if topic.topic_type == constant('MSZ_TOPIC_TYPE_ANNOUNCEMENT') or topic.topic_type == constant('MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT') %}
{% set topic_icon = 'fas fa-bullhorn' %}
{% elseif topic.topic_type == constant('MSZ_TOPIC_TYPE_STICKY') %}
{% set topic_icon = 'fas fa-thumbtack' %}
{% endif %}
{% elseif topic.topic_locked is defined and topic.topic_locked is not null %}
{% set topic_icon = 'fas fa-lock' %}
{% else %}
{% set topic_icon = 'fas fa-comment' %}
{% endif %}
<div class="profile__forum-activity__leader">
Most active topic
</div>
<div class="forum__topic{% if topic.topic_locked is not null %} forum__topic--locked{% endif %}">
<a href="{{ url('forum-topic', {'topic': topic.topic_id}) }}" class="forum__topic__link"></a>
<div class="forum__topic__container">
<div class="forum__topic__icon">
<i class="{{ topic_icon }} fa-fw"></i>
</div>
<div class="forum__topic__details">
<div class="forum__topic__title">
<span class="forum__topic__title__inner">
{{ topic.topic_title }}
</span>
</div>
<div class="forum__topic__info">
{{ profile_active_topic_stats.post_count|number_format }} post{{ profile_active_topic_stats.post_count == 1 ? '' : 's' }}
/ {{ ((profile_active_topic_stats.post_count / profile_stats.forum_post_count) * 100)|number_format(2) }}% of total posts
</div>
</div>
</div>
</div>
</div>
{% endif %}
</div>
</div>
{% endif %}
{% if show_birthdate %}
<div class="container profile__container profile__birthdate">
{{ container_title('Birthdate') }}