Class: Decidim::Consultation

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

Overview

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

Instance Method Summary collapse

Methods included from Decidim::Consultations::PublicableResults

#publish_results!, #results_published?, #unpublish_results!

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/decidim/consultation.rb', line 72

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

#closed?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/models/decidim/consultation.rb', line 105

def closed?
  !active?
end

#finished?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/models/decidim/consultation.rb', line 76

def finished?
  end_voting_date < Time.now.utc
end

#highlighted_questionsObject



80
81
82
# File 'app/models/decidim/consultation.rb', line 80

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

#questions_by_scopeObject



84
85
86
# File 'app/models/decidim/consultation.rb', line 84

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



101
102
103
# File 'app/models/decidim/consultation.rb', line 101

def scope
  nil
end

#to_paramObject



64
65
66
# File 'app/models/decidim/consultation.rb', line 64

def to_param
  slug
end

#total_participantsObject



92
93
94
# File 'app/models/decidim/consultation.rb', line 92

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

#total_votesObject



88
89
90
# File 'app/models/decidim/consultation.rb', line 88

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

#upcoming?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'app/models/decidim/consultation.rb', line 68

def upcoming?
  start_voting_date > Time.now.utc
end