Add last replied topic to the forums listing.

This commit is contained in:
flash 2018-05-21 21:08:40 +02:00
parent feb1ecf530
commit 14424687d6
5 changed files with 175 additions and 27 deletions

View file

@ -11,7 +11,8 @@
&__entry { &__entry {
display: flex; display: flex;
align-items: center; align-items: stretch;
min-height: 50px;
&:not(:last-child) { &:not(:last-child) {
border-bottom: 1px solid #9475b2; border-bottom: 1px solid #9475b2;
@ -22,23 +23,30 @@
&__icon { &__icon {
flex-shrink: 0; flex-shrink: 0;
flex-grow: 0; flex-grow: 0;
align-self: flex-start; align-self: center;
} }
&__info { &__info {
flex-grow: 1; flex-grow: 1;
flex-shrink: 1; flex-shrink: 1;
padding-left: 6px; padding-left: 4px;
display: inline-flex;
flex-direction: column;
justify-content: center;
} }
&__title { &__title {
font-size: 1.2em; font-size: 1.2em;
line-height: 1.5em; line-height: 1.5em;
color: #306; color: #306;
text-decoration: none;
&:hover { &__link {
text-decoration: underline; color: inherit;
text-decoration: none;
&:hover {
text-decoration: underline;
}
} }
} }
@ -59,8 +67,9 @@
&__stats { &__stats {
text-align: center; text-align: center;
flex-grow: 0; justify-content: center;
flex-shrink: 0; min-width: 100px;
flex-direction: column;
@media (max-width: @mio-forum-listing-mobile) { @media (max-width: @mio-forum-listing-mobile) {
display: none; display: none;
@ -78,15 +87,70 @@
} }
&__activity { &__activity {
flex-grow: 0; min-width: 270px;
flex-shrink: 0; align-items: center;
text-align: right;
margin: 0 10px;
width: 220px;
@media (max-width: @mio-forum-listing-mobile) { @media (max-width: @mio-forum-listing-mobile) {
display: none; display: none;
} }
&__title {
line-height: 1.4em;
margin-bottom: 2px;
&__link {
color: inherit;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
&--unread {
font-weight: 700;
}
}
&__info {
font-size: .9em;
line-height: 1.2em;
}
&__user {
font-weight: 700;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
&__avatar {
display: block;
text-decoration: none;
color: inherit;
width: 44px;
height: 44px;
margin-right: 3px;
flex-grow: 0;
flex-shrink: 0;
}
&__none,
&__details {
margin-left: 5px;
flex-grow: 1;
flex-shrink: 1;
}
}
&__stats,
&__activity {
display: flex;
flex-shrink: 0;
flex-grow: 0;
border-left: 1px solid #9475b2;
} }
} }
} }

View file

@ -61,7 +61,6 @@
line-height: 1.2em; line-height: 1.2em;
&__name { &__name {
color: inherit;
font-weight: 700; font-weight: 700;
text-decoration: none; text-decoration: none;
@ -74,7 +73,6 @@
&__stat { &__stat {
line-height: 1.2em; line-height: 1.2em;
min-width: 70px;
&--posts { &--posts {
font-size: 1.3em; font-size: 1.3em;
@ -90,6 +88,7 @@
&__stats { &__stats {
text-align: center; text-align: center;
padding-left: 1px; padding-left: 1px;
min-width: 70px;
} }
&__activity { &__activity {

View file

@ -92,7 +92,13 @@ if ($forum['forum_type'] == 0) {
$getSubforums = $db->prepare(' $getSubforums = $db->prepare('
SELECT SELECT
`forum_id`, `forum_name`, `forum_description`, `forum_type`, `forum_link`, f.`forum_id`, f.`forum_name`, f.`forum_description`, f.`forum_type`, f.`forum_link`,
t.`topic_id` as `recent_topic_id`, p.`post_id` as `recent_post_id`,
t.`topic_title` as `recent_topic_title`,
p.`post_created` as `recent_post_created`,
u.`user_id` as `recent_post_user_id`,
u.`username` as `recent_post_username`,
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `recent_post_user_colour`,
( (
SELECT COUNT(t.`topic_id`) SELECT COUNT(t.`topic_id`)
FROM `msz_forum_topics` as t FROM `msz_forum_topics` as t
@ -104,6 +110,27 @@ $getSubforums = $db->prepare('
WHERE p.`forum_id` = f.`forum_id` WHERE p.`forum_id` = f.`forum_id`
) as `forum_post_count` ) as `forum_post_count`
FROM `msz_forum_categories` as f FROM `msz_forum_categories` as f
LEFT JOIN `msz_forum_topics` as t
ON t.`topic_id` = (
SELECT `topic_id`
FROM `msz_forum_topics`
WHERE `forum_id` = f.`forum_id`
AND `topic_deleted` IS NULL
ORDER BY `topic_bumped` DESC
LIMIT 1
)
LEFT JOIN `msz_forum_posts` as p
ON p.`post_id` = (
SELECT `post_id`
FROM `msz_forum_posts`
WHERE `topic_id` = t.`topic_id`
ORDER BY `post_id` DESC
LIMIT 1
)
LEFT JOIN `msz_users` as u
ON u.`user_id` = p.`user_id`
LEFT JOIN `msz_roles` as r
ON r.`role_id` = u.`display_role`
WHERE `forum_parent` = :forum_id WHERE `forum_parent` = :forum_id
AND `forum_hidden` = false AND `forum_hidden` = false
'); ');

View file

@ -17,7 +17,6 @@ $categories = $db->query('
WHERE f.`forum_parent` = 0 WHERE f.`forum_parent` = 0
AND f.`forum_type` = 1 AND f.`forum_type` = 1
AND f.`forum_hidden` = false AND f.`forum_hidden` = false
GROUP BY f.`forum_id`
ORDER BY f.`forum_order` ORDER BY f.`forum_order`
')->fetchAll(); ')->fetchAll();
@ -33,17 +32,44 @@ $categories = array_merge([
$getSubCategories = $db->prepare(' $getSubCategories = $db->prepare('
SELECT SELECT
f.`forum_id`, f.`forum_name`, f.`forum_description`, f.`forum_type`, f.`forum_link`, f.`forum_id`, f.`forum_name`, f.`forum_description`, f.`forum_type`, f.`forum_link`,
t.`topic_id` as `recent_topic_id`, p.`post_id` as `recent_post_id`,
t.`topic_title` as `recent_topic_title`,
p.`post_created` as `recent_post_created`,
u.`user_id` as `recent_post_user_id`,
u.`username` as `recent_post_username`,
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `recent_post_user_colour`,
( (
SELECT COUNT(t.`topic_id`) SELECT COUNT(`topic_id`)
FROM `msz_forum_topics` as t FROM `msz_forum_topics`
WHERE t.`forum_id` = f.`forum_id` WHERE `forum_id` = f.`forum_id`
) as `forum_topic_count`, ) as `forum_topic_count`,
( (
SELECT COUNT(p.`post_id`) SELECT COUNT(`post_id`)
FROM `msz_forum_posts` as p FROM `msz_forum_posts`
WHERE p.`forum_id` = f.`forum_id` WHERE `forum_id` = f.`forum_id`
) as `forum_post_count` ) as `forum_post_count`
FROM `msz_forum_categories` as f FROM `msz_forum_categories` as f
LEFT JOIN `msz_forum_topics` as t
ON t.`topic_id` = (
SELECT `topic_id`
FROM `msz_forum_topics`
WHERE `forum_id` = f.`forum_id`
AND `topic_deleted` IS NULL
ORDER BY `topic_bumped` DESC
LIMIT 1
)
LEFT JOIN `msz_forum_posts` as p
ON p.`post_id` = (
SELECT `post_id`
FROM `msz_forum_posts`
WHERE `topic_id` = t.`topic_id`
ORDER BY `post_id` DESC
LIMIT 1
)
LEFT JOIN `msz_users` as u
ON u.`user_id` = p.`user_id`
LEFT JOIN `msz_roles` as r
ON r.`role_id` = u.`display_role`
WHERE f.`forum_parent` = :forum_id WHERE f.`forum_parent` = :forum_id
AND f.`forum_hidden` = false AND f.`forum_hidden` = false
AND ((f.`forum_parent` = 0 AND f.`forum_type` != 1) OR f.`forum_parent` != 0) AND ((f.`forum_parent` = 0 AND f.`forum_type` != 1) OR f.`forum_parent` != 0)

View file

@ -46,10 +46,14 @@
<img src="{{ forum_icon|format(forum_type, forum_read) }}" alt="read" class="forum__listing__entry__icon"> <img src="{{ forum_icon|format(forum_type, forum_read) }}" alt="read" class="forum__listing__entry__icon">
<div class="forum__listing__entry__info"> <div class="forum__listing__entry__info">
<a href="/forum/forum.php?f={{ forum.forum_id }}" class="forum__listing__entry__title">{{ forum.forum_name }}</a> <div class="forum__listing__entry__title">
<a href="/forum/forum.php?f={{ forum.forum_id }}" class="forum__listing__entry__title__link">{{ forum.forum_name }}</a>
</div>
<div class="forum__listing__entry__description"> <div class="forum__listing__entry__description">
{{ forum.forum_description|nl2br }} {{ forum.forum_description|nl2br }}
</div> </div>
{% if forum.forum_subforums is defined and forum.forum_subforums|length > 0 %} {% if forum.forum_subforums is defined and forum.forum_subforums|length > 0 %}
<div class="forum__listing__entry__subforums"> <div class="forum__listing__entry__subforums">
{% for subforum in forum.forum_subforums %} {% for subforum in forum.forum_subforums %}
@ -65,9 +69,37 @@
</div> </div>
<div class="forum__listing__entry__activity"> <div class="forum__listing__entry__activity">
<div class="forum__listing__entry__activity__none"> {% if forum.recent_topic_id is null %}
There are no posts in this forum yet. <div class="forum__listing__entry__activity__none">
</div> There are no posts in this forum yet.
</div>
{% else %}
<div class="forum__listing__entry__activity__details">
<div class="forum__listing__entry__activity__title">
<a class="forum__listing__entry__activity__title__link"
href="/forum/topic.php?p={{ forum.recent_post_id }}#p{{ forum.recent_post_id }}">
{{ forum.recent_topic_title|slice(0, 30) ~ (forum.recent_topic_title|length > 30 ? '...' : '') }}
</a>
</div>
<div class="forum__listing__entry__activity__info">
{% if forum.recent_post_user_id is not null %}
by <a
href="/profile.php?u={{ forum.recent_post_user_id }}"
style="color:{{ forum.recent_post_user_colour|colour_get_css }}"
class="forum__listing__entry__activity__user">{{ forum.recent_post_username }}</a>,
{% endif %}
{{ forum.recent_post_created }}
</div>
</div>
{% if forum.recent_post_user_id is not null %}
<a
href="/profile.php?u={{ forum.recent_post_user_id }}"
class="avatar forum__listing__entry__activity__avatar"
style="background-image:url('/profile.php?u={{ forum.recent_post_user_id }}&amp;m=avatar')">
</a>
{% endif %}
{% endif %}
</div> </div>
</div> </div>
{% endmacro %} {% endmacro %}