Class: Decidim::Consultations::QuestionStatsPresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
decidim-consultations/app/presenters/decidim/consultations/question_stats_presenter.rb

Overview

A presenter to render statistics in the homepage.

Instance Method Summary collapse

Instance Method Details

#assistants_countObject


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'decidim-consultations/app/presenters/decidim/consultations/question_stats_presenter.rb', line 33

def assistants_count
  Rails.cache.fetch(
    "question/#{question.id}/assistants_count",
    expires_in: Decidim::Consultations.stats_cache_expiration_time
  ) do
    result = 0
    Decidim::Meetings::Meeting.where(component: meetings_component).each do |meeting|
      result += meeting.attendees_count || 0
    end

    result
  end
end

#comments_countObject


15
16
17
18
19
20
21
22
# File 'decidim-consultations/app/presenters/decidim/consultations/question_stats_presenter.rb', line 15

def comments_count
  Rails.cache.fetch(
    "question/#{question.id}/comments_count",
    expires_in: Decidim::Consultations.stats_cache_expiration_time
  ) do
    question.comments_count
  end
end

#meetings_countObject


24
25
26
27
28
29
30
31
# File 'decidim-consultations/app/presenters/decidim/consultations/question_stats_presenter.rb', line 24

def meetings_count
  Rails.cache.fetch(
    "question/#{question.id}/meetings_count",
    expires_in: Decidim::Consultations.stats_cache_expiration_time
  ) do
    Decidim::Meetings::Meeting.where(component: meetings_component).count
  end
end

#questionObject


7
8
9
# File 'decidim-consultations/app/presenters/decidim/consultations/question_stats_presenter.rb', line 7

def question
  __getobj__.fetch(:question)
end

#supports_countObject


11
12
13
# File 'decidim-consultations/app/presenters/decidim/consultations/question_stats_presenter.rb', line 11

def supports_count
  question.votes_count
end