Class: Decidim::Consultation

Inherits:
ApplicationRecord show all
Includes:
Decidim::Consultations::PublicableResults, FilterableResource, HasUploadValidations, Loggable, Participable, ParticipatorySpaceResourceable, Publicable, Randomable, Resourceable, Searchable, Traceable, TranslatableResource
Defined in:
decidim-consultations/app/models/decidim/consultation.rb

Overview

The data store for a Consultation in the Decidim::Consultations component.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasUploadValidations

#attached_uploader, #maximum_avatar_size, #maximum_upload_size

Methods included from Searchable

searchable_resources, searchable_resources_of_type_comment, searchable_resources_of_type_component, searchable_resources_of_type_participant, searchable_resources_of_type_participatory_space

Methods included from Decidim::Consultations::PublicableResults

#publish_results!, #results_published?, #unpublish_results!

Methods included from Publicable

#publish!, #published?, #unpublish!

Class Method Details

.ransackable_scopes(_auth_object = nil) ⇒ Object


116
117
118
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 116

def self.ransackable_scopes(_auth_object = nil)
  [:with_any_date]
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

75
76
77
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 75

def active?
  start_voting_date <= Time.now.utc && end_voting_date >= Time.now.utc
end

#closed?Boolean

Returns:

  • (Boolean)

108
109
110
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 108

def closed?
  !active?
end

#finished?Boolean

Returns:

  • (Boolean)

79
80
81
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 79

def finished?
  end_voting_date < Time.now.utc
end

#highlighted_questionsObject


83
84
85
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 83

def highlighted_questions
  questions.published.where(decidim_scope_id: decidim_highlighted_scope_id)
end

#questions_by_scopeObject


87
88
89
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 87

def questions_by_scope
  questions.published.group_by(&:scope)
end

#scopeObject

This method exists with the only purpose of getting rid of whats seems to be an issue in the new scope picker: This engine is a bit special: consultations and questions are a kind of nested participatory spaces. When a new question is created the consultation is the participatory space. Since seems that the scope picker is asking to the current participatory space for its scope this method is necessary to exist an return nil in order to be able to browse the scope hierarchy


104
105
106
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 104

def scope
  nil
end

#to_paramObject


67
68
69
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 67

def to_param
  slug
end

#total_participantsObject


95
96
97
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 95

def total_participants
  @total_participants ||= questions.published.joins(:votes).select(:decidim_author_id).distinct.count
end

#total_votesObject


91
92
93
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 91

def total_votes
  @total_votes ||= questions.published.sum(:votes_count)
end

#upcoming?Boolean

Returns:

  • (Boolean)

71
72
73
# File 'decidim-consultations/app/models/decidim/consultation.rb', line 71

def upcoming?
  start_voting_date > Time.now.utc
end