Sha256: 72aacdaa677d80a7bc48027fb41d535b618982de93b519463d3ce7f366d8b7fc

Contents?: true

Size: 1.46 KB

Versions: 30

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    # A presenter to render statistics in the homepage.
    class QuestionStatsPresenter < Rectify::Presenter
      attribute :question, Decidim::Consultations::Question

      def supports_count
        question.votes_count
      end

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

      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

      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

      private

      def meetings_component
        @meetings_component ||= Decidim::Component.find_by(participatory_space: question, manifest_name: "meetings")
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
decidim-consultations-0.22.0 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.21.0 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.20.1 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.20.0 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.19.1 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.18.1 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.19.0 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.17.2 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.18.0 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.17.1 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.16.1 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.17.0 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.16.0 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.15.2 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.15.1 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.15.0 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.14.4 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.14.3 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.14.2 app/presenters/decidim/consultations/question_stats_presenter.rb
decidim-consultations-0.14.1 app/presenters/decidim/consultations/question_stats_presenter.rb