New site setting: `limit_suggested_to_category` - ensures suggested

topics belong to the same category as the current topic and doesn't mix
in other categories.
This commit is contained in:
Robin Ward 2014-06-03 17:48:18 -04:00
parent 091452e211
commit 5bedc56387
3 changed files with 11 additions and 2 deletions

View File

@ -765,6 +765,7 @@ en:
max_private_messages_per_day: "The maximum amount of private messages users can create per day"
suggested_topics: "Number of suggested topics shown at the bottom of a topic"
limit_suggested_to_category: "Only show topics from the current category in suggested topics"
clean_up_uploads: "Remove orphaned uploads to prevent illegal hosting. WARNING: you might want to make a backup of your /uploads directory before enabled this setting."
clean_orphan_uploads_grace_period_hours: "Grace period (in hours) before an orphan upload is removed."

View File

@ -34,6 +34,9 @@ basic:
suggested_topics:
client: true
default: 5
limit_suggested_to_category:
client: false
default: false
default_external_links_in_new_tab: false
track_external_right_clicks:
client: true

View File

@ -20,8 +20,13 @@ class SuggestedTopicsBuilder
# Only add results if we don't have those topic ids already
results = results.where('topics.id NOT IN (?)', @excluded_topic_ids)
.where(visible: true)
.to_a
.reject { |topic| @category_topic_ids.include?(topic.id) }
# If limit suggested to category is enabled, restrict to that category
if @category_id && SiteSetting.limit_suggested_to_category?
results = results.where(category_id: @category_id)
end
results = results.to_a.reject { |topic| @category_topic_ids.include?(topic.id) }
unless results.empty?
# Keep track of the ids we've added