Class: Decidim::Initiatives::InitiativeStatsPresenter

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

Overview

A presenter to render statistics in the homepage.

Instance Method Summary collapse

Instance Method Details

#assistants_countObject


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'decidim-initiatives/app/presenters/decidim/initiatives/initiative_stats_presenter.rb', line 29

def assistants_count
  Rails.cache.fetch(
    "initiative/#{initiative.id}/assistants_count",
    expires_in: Decidim::Initiatives.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


11
12
13
14
15
16
17
18
# File 'decidim-initiatives/app/presenters/decidim/initiatives/initiative_stats_presenter.rb', line 11

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

#initiativeObject


7
8
9
# File 'decidim-initiatives/app/presenters/decidim/initiatives/initiative_stats_presenter.rb', line 7

def initiative
  __getobj__.fetch(:initiative)
end

#meetings_countObject


20
21
22
23
24
25
26
27
# File 'decidim-initiatives/app/presenters/decidim/initiatives/initiative_stats_presenter.rb', line 20

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