Sha256: 5247435e032dd87b384829126e4f1e2bfe7366b67a47e3352fefdb117214eba2

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    # A presenter to render statistics in the homepage.
    class ConferenceStatsPresenter < Decidim::StatsPresenter
      include IconHelper

      def conference
        __getobj__.fetch(:conference)
      end

      # Public: Render a collection of primary stats.
      def highlighted
        highlighted_stats = component_stats(priority: StatsRegistry::HIGH_PRIORITY)
        highlighted_stats.concat(component_stats(priority: StatsRegistry::MEDIUM_PRIORITY))
        highlighted_stats.concat(comments_stats(:conferences))
        highlighted_stats = highlighted_stats.reject(&:empty?)
        highlighted_stats = highlighted_stats.reject { |_manifest, _name, data| data.zero? }
        grouped_highlighted_stats = highlighted_stats.group_by(&:first)

        statistics(grouped_highlighted_stats)
      end

      private

      def component_stats(conditions)
        Decidim.component_manifests.map do |component_manifest|
          component_manifest.stats
                            .filter(conditions)
                            .with_context(published_components)
                            .map { |name, data| [component_manifest.name, name, data] }.flatten
        end
      end

      def published_components
        @published_components ||= Component.where(participatory_space: conference).published
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-conferences-0.27.9 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.8 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.7 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.6 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.5 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.4 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.3 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.2 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.1 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.0 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.0.rc2 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.27.0.rc1 app/presenters/decidim/conferences/conference_stats_presenter.rb