Class: Decidim::Consultation

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Decidim::Consultations::PublicableResults, Loggable, Participable, ParticipatorySpaceResourceable, Publicable, Randomable, Resourceable, Traceable
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)


52
53
54
# File 'app/models/decidim/consultation.rb', line 52

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

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  !active?
end

#finished?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/decidim/consultation.rb', line 56

def finished?
  end_voting_date < Time.now.utc
end

#highlighted_questionsObject



60
61
62
# File 'app/models/decidim/consultation.rb', line 60

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

#questions_by_scopeObject



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

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



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

def scope
  nil
end

#to_paramObject



44
45
46
# File 'app/models/decidim/consultation.rb', line 44

def to_param
  slug
end

#total_participantsObject



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

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

#total_votesObject



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

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

#upcoming?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/decidim/consultation.rb', line 48

def upcoming?
  start_voting_date > Time.now.utc
end