From 9f9b602e75e688203eb49115a35e5ae7b6938cb2 Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 16 Oct 2018 23:38:17 +0200 Subject: [PATCH] Prep for category accent colours. --- ..._10_16_211910_add_forum_accent_colours.php | 20 +++++++++++++++++++ src/Forum/forum.php | 8 +++++--- templates/forum/index.twig | 2 +- templates/forum/macros.twig | 4 ++-- 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 database/2018_10_16_211910_add_forum_accent_colours.php diff --git a/database/2018_10_16_211910_add_forum_accent_colours.php b/database/2018_10_16_211910_add_forum_accent_colours.php new file mode 100644 index 00000000..706c2888 --- /dev/null +++ b/database/2018_10_16_211910_add_forum_accent_colours.php @@ -0,0 +1,20 @@ +exec(" + ALTER TABLE `msz_forum_categories` + ADD COLUMN `forum_colour` INT UNSIGNED NULL DEFAULT NULL AFTER `forum_description`; + "); +} + +function migrate_down(PDO $conn): void +{ + $conn->exec(' + ALTER TABLE `msz_forum_categories` + DROP COLUMN `forum_colour`; + '); +} diff --git a/src/Forum/forum.php b/src/Forum/forum.php index ffc71518..e0a8aae5 100644 --- a/src/Forum/forum.php +++ b/src/Forum/forum.php @@ -45,6 +45,7 @@ define('MSZ_FORUM_ROOT_DATA', [ // should be compatible with the data fetched in 'forum_name' => 'Forums', 'forum_children' => 0, 'forum_type' => MSZ_FORUM_TYPE_CATEGORY, + 'forum_colour' => null, ]); function forum_may_have_children(int $forumType): bool @@ -61,7 +62,8 @@ function forum_fetch(int $forumId): array { $getForum = db_prepare(' SELECT - `forum_id`, `forum_name`, `forum_type`, `forum_link`, `forum_link_clicks`, `forum_parent`, + `forum_id`, `forum_name`, `forum_type`, `forum_link`, + `forum_link_clicks`, `forum_parent`, `forum_colour`, ( SELECT COUNT(`topic_id`) FROM `msz_forum_topics` @@ -87,7 +89,7 @@ function forum_get_root_categories(int $userId): array $getCategories = db_prepare(" SELECT - f.`forum_id`, f.`forum_name`, f.`forum_type`, + f.`forum_id`, f.`forum_name`, f.`forum_type`, f.`forum_colour`, ( SELECT COUNT(`forum_id`) FROM `msz_forum_categories` as sf @@ -239,7 +241,7 @@ define( SELECT :user_id as `target_user_id`, f.`forum_id`, f.`forum_name`, f.`forum_description`, f.`forum_type`, - f.`forum_link`, f.`forum_link_clicks`, f.`forum_archived`, + f.`forum_link`, f.`forum_link_clicks`, f.`forum_archived`, f.`forum_colour`, t.`topic_id` as `recent_topic_id`, p.`post_id` as `recent_post_id`, t.`topic_title` as `recent_topic_title`, t.`topic_bumped` as `recent_topic_bumped`, p.`post_created` as `recent_post_created`, diff --git a/templates/forum/index.twig b/templates/forum/index.twig index f4d43ae5..bdd74960 100644 --- a/templates/forum/index.twig +++ b/templates/forum/index.twig @@ -8,7 +8,7 @@ {% if not forum_empty %} {% for category in forum_categories %} {% if category.forum_children > 0 %} - {{ forum_category_listing(category.forum_subforums, category.forum_name) }} + {{ forum_category_listing(category.forum_subforums, category.forum_name, category.forum_colour) }} {% endif %} {% endfor %} diff --git a/templates/forum/macros.twig b/templates/forum/macros.twig index a63547e5..0e225c58 100644 --- a/templates/forum/macros.twig +++ b/templates/forum/macros.twig @@ -1,7 +1,7 @@ -{% macro forum_category_listing(forums, title) %} +{% macro forum_category_listing(forums, title, colour) %} {% from _self import forum_category_entry %} -
+
{{ title }}
{% if forums|length > 0 %}