From 14424687d60e8ed842d2f6ebc2ad81a02e34b19f Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 21 May 2018 21:08:40 +0200 Subject: [PATCH] Add last replied topic to the forums listing. --- assets/less/mio/classes/forum/listing.less | 90 ++++++++++++++++++---- assets/less/mio/classes/forum/topics.less | 3 +- public/forum/forum.php | 29 ++++++- public/forum/index.php | 40 ++++++++-- views/mio/forum/macros.twig | 40 +++++++++- 5 files changed, 175 insertions(+), 27 deletions(-) diff --git a/assets/less/mio/classes/forum/listing.less b/assets/less/mio/classes/forum/listing.less index a8f6213d..aa005a27 100644 --- a/assets/less/mio/classes/forum/listing.less +++ b/assets/less/mio/classes/forum/listing.less @@ -11,7 +11,8 @@ &__entry { display: flex; - align-items: center; + align-items: stretch; + min-height: 50px; &:not(:last-child) { border-bottom: 1px solid #9475b2; @@ -22,23 +23,30 @@ &__icon { flex-shrink: 0; flex-grow: 0; - align-self: flex-start; + align-self: center; } &__info { flex-grow: 1; flex-shrink: 1; - padding-left: 6px; + padding-left: 4px; + display: inline-flex; + flex-direction: column; + justify-content: center; } &__title { font-size: 1.2em; line-height: 1.5em; color: #306; - text-decoration: none; - &:hover { - text-decoration: underline; + &__link { + color: inherit; + text-decoration: none; + + &:hover { + text-decoration: underline; + } } } @@ -59,8 +67,9 @@ &__stats { text-align: center; - flex-grow: 0; - flex-shrink: 0; + justify-content: center; + min-width: 100px; + flex-direction: column; @media (max-width: @mio-forum-listing-mobile) { display: none; @@ -78,15 +87,70 @@ } &__activity { - flex-grow: 0; - flex-shrink: 0; - text-align: right; - margin: 0 10px; - width: 220px; + min-width: 270px; + align-items: center; @media (max-width: @mio-forum-listing-mobile) { 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; } } } diff --git a/assets/less/mio/classes/forum/topics.less b/assets/less/mio/classes/forum/topics.less index 4354b657..a429836b 100644 --- a/assets/less/mio/classes/forum/topics.less +++ b/assets/less/mio/classes/forum/topics.less @@ -61,7 +61,6 @@ line-height: 1.2em; &__name { - color: inherit; font-weight: 700; text-decoration: none; @@ -74,7 +73,6 @@ &__stat { line-height: 1.2em; - min-width: 70px; &--posts { font-size: 1.3em; @@ -90,6 +88,7 @@ &__stats { text-align: center; padding-left: 1px; + min-width: 70px; } &__activity { diff --git a/public/forum/forum.php b/public/forum/forum.php index cdc95750..7c0e7b1b 100644 --- a/public/forum/forum.php +++ b/public/forum/forum.php @@ -92,7 +92,13 @@ if ($forum['forum_type'] == 0) { $getSubforums = $db->prepare(' 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`) FROM `msz_forum_topics` as t @@ -104,6 +110,27 @@ $getSubforums = $db->prepare(' WHERE p.`forum_id` = f.`forum_id` ) as `forum_post_count` 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 AND `forum_hidden` = false '); diff --git a/public/forum/index.php b/public/forum/index.php index 800b19cb..35b2babd 100644 --- a/public/forum/index.php +++ b/public/forum/index.php @@ -17,7 +17,6 @@ $categories = $db->query(' WHERE f.`forum_parent` = 0 AND f.`forum_type` = 1 AND f.`forum_hidden` = false - GROUP BY f.`forum_id` ORDER BY f.`forum_order` ')->fetchAll(); @@ -33,17 +32,44 @@ $categories = array_merge([ $getSubCategories = $db->prepare(' SELECT 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`) - FROM `msz_forum_topics` as t - WHERE t.`forum_id` = f.`forum_id` + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `forum_id` = f.`forum_id` ) as `forum_topic_count`, ( - SELECT COUNT(p.`post_id`) - FROM `msz_forum_posts` as p - WHERE p.`forum_id` = f.`forum_id` + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `forum_id` = f.`forum_id` ) as `forum_post_count` 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 AND f.`forum_hidden` = false AND ((f.`forum_parent` = 0 AND f.`forum_type` != 1) OR f.`forum_parent` != 0) diff --git a/views/mio/forum/macros.twig b/views/mio/forum/macros.twig index d04a09a4..98e2a763 100644 --- a/views/mio/forum/macros.twig +++ b/views/mio/forum/macros.twig @@ -46,10 +46,14 @@ read
- {{ forum.forum_name }} +
+ {{ forum.forum_name }} +
+
{{ forum.forum_description|nl2br }}
+ {% if forum.forum_subforums is defined and forum.forum_subforums|length > 0 %}
{% for subforum in forum.forum_subforums %} @@ -65,9 +69,37 @@
-
- There are no posts in this forum yet. -
+ {% if forum.recent_topic_id is null %} +
+ There are no posts in this forum yet. +
+ {% else %} +
+
+ + {{ forum.recent_topic_title|slice(0, 30) ~ (forum.recent_topic_title|length > 30 ? '...' : '') }} + +
+
+ {% if forum.recent_post_user_id is not null %} + by {{ forum.recent_post_username }}, + {% endif %} + {{ forum.recent_post_created }} +
+
+ + {% if forum.recent_post_user_id is not null %} + + + {% endif %} + {% endif %}
{% endmacro %}