Class: Decidim::Taxonomy

Inherits:
ApplicationRecord show all
Includes:
FilterableResource, Traceable, TranslatableResource
Defined in:
app/models/decidim/taxonomy.rb

Overview

Represents a hierarchical classification used to organize various entities within the system. Taxonomies are primarily used to categorize and manage different aspects of participatory spaces, such as proposals, assemblies, and other components, within an organization.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



59
60
61
# File 'app/models/decidim/taxonomy.rb', line 59

def self.log_presenter_class_for(_log)
  Decidim::AdminLog::TaxonomyPresenter
end

.ransackable_associations(_auth_object = nil) ⇒ Object



71
72
73
# File 'app/models/decidim/taxonomy.rb', line 71

def self.ransackable_associations(_auth_object = nil)
  %w(children)
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



67
68
69
# File 'app/models/decidim/taxonomy.rb', line 67

def self.ransackable_attributes(_auth_object = nil)
  %w(id name parent_id part_of)
end

.ransackable_scopes(_auth_object = nil) ⇒ Object



63
64
65
# File 'app/models/decidim/taxonomy.rb', line 63

def self.ransackable_scopes(_auth_object = nil)
  [:search_by_name, :part_of]
end

Instance Method Details

#all_children ⇒ Object



94
95
96
# File 'app/models/decidim/taxonomy.rb', line 94

def all_children
  @all_children ||= Decidim::Taxonomy.non_roots.part_of(id).reorder(Arel.sql("array_length(part_of, 1) ASC"), "parent_id ASC", "weight ASC")
end

#parent_ids ⇒ Object



83
84
85
# File 'app/models/decidim/taxonomy.rb', line 83

def parent_ids
  @parent_ids ||= part_of.excluding(id)
end

#presenter ⇒ Object



102
103
104
# File 'app/models/decidim/taxonomy.rb', line 102

def presenter
  Decidim::TaxonomyPresenter.new(self)
end

#removable? ⇒ Boolean

this might change in the future if we want to prevent the deletion of taxonomies with associated resources

Returns:

  • (Boolean)


90
91
92
# File 'app/models/decidim/taxonomy.rb', line 90

def removable?
  true
end

#reset_all_counters ⇒ Object



98
99
100
# File 'app/models/decidim/taxonomy.rb', line 98

def reset_all_counters
  Taxonomy.reset_counters(id, :children_count, :taxonomizations_count, :taxonomy_filters_count, :taxonomy_filter_items_count)
end

#root? ⇒ Boolean

Returns:

  • (Boolean)


87
# File 'app/models/decidim/taxonomy.rb', line 87

def root? = parent_id.nil?

#root_taxonomy ⇒ Object



79
80
81
# File 'app/models/decidim/taxonomy.rb', line 79

def root_taxonomy
  @root_taxonomy ||= root? ? self : parent.root_taxonomy
end

#translated_name ⇒ Object



75
76
77
# File 'app/models/decidim/taxonomy.rb', line 75

def translated_name
  Decidim::TaxonomyPresenter.new(self).translated_name
end