Class: CategoryList
- Inherits:
-
Object
- Object
- CategoryList
- Includes:
- ActiveModel::Serialization
- Defined in:
- app/models/category_list.rb
Constant Summary collapse
- CATEGORIES_PER_PAGE =
20
- SUBCATEGORIES_PER_CATEGORY =
5
- MAX_UNOPTIMIZED_CATEGORIES =
Maximum number of categories before the optimized category page style is enforced
1000
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#uncategorized ⇒ Object
Returns the value of attribute uncategorized.
Class Method Summary collapse
- .included_associations ⇒ Object
- .order_categories(categories) ⇒ Object
- .register_included_association(association) ⇒ Object
Instance Method Summary collapse
-
#initialize(guardian = nil, options = {}) ⇒ CategoryList
constructor
A new instance of CategoryList.
- #preload_key ⇒ Object
Constructor Details
#initialize(guardian = nil, options = {}) ⇒ CategoryList
Returns a new instance of CategoryList.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/category_list.rb', line 33 def initialize(guardian = nil, = {}) @guardian = guardian || Guardian.new @options = find_categories find_relevant_topics if [:include_topics] prune_empty find_user_data sort_unpinned trim_results demote_muted if preloaded_topic_custom_fields.present? displayable_topics = @categories.map(&:displayable_topics) displayable_topics.flatten! displayable_topics.compact! if displayable_topics.present? Topic.preload_custom_fields(displayable_topics, preloaded_topic_custom_fields) end end end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
15 16 17 |
# File 'app/models/category_list.rb', line 15 def categories @categories end |
#uncategorized ⇒ Object
Returns the value of attribute uncategorized.
15 16 17 |
# File 'app/models/category_list.rb', line 15 def uncategorized @uncategorized end |
Class Method Details
.included_associations ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/category_list.rb', line 22 def self.included_associations [ :uploaded_background, :uploaded_background_dark, :uploaded_logo, :uploaded_logo_dark, :topic_only_relative_url, subcategories: [:topic_only_relative_url], ].concat(@included_associations || []) end |
.order_categories(categories) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/category_list.rb', line 61 def self.order_categories(categories) if SiteSetting.fixed_category_positions categories.order(:position, :id) else categories .left_outer_joins(:featured_topics) .where("topics.category_id IS NULL OR topics.category_id IN (?)", categories.select(:id)) .group("categories.id") .order("max(topics.bumped_at) DESC NULLS LAST") .order("categories.id ASC") end end |
.register_included_association(association) ⇒ Object
17 18 19 20 |
# File 'app/models/category_list.rb', line 17 def self.register_included_association(association) @included_associations ||= [] @included_associations << association if !@included_associations.include?(association) end |
Instance Method Details
#preload_key ⇒ Object
57 58 59 |
# File 'app/models/category_list.rb', line 57 def preload_key "categories_list" end |