Sha256: e53929bbe4a53719d76e86160c43f6b75c0a8d63075e5fd0da31466d4486a03d

Contents?: true

Size: 1.36 KB

Versions: 19

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

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

      # 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

19 entries across 19 versions & 1 rubygems

Version Path
decidim-conferences-0.26.10 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.9 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.8 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.7 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.5 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.4 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.3 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.2 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.1 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.0 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.0.rc2 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.26.0.rc1 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.25.2 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.25.1 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.25.0 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.25.0.rc4 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.25.0.rc3 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.25.0.rc2 app/presenters/decidim/conferences/conference_stats_presenter.rb
decidim-conferences-0.25.0.rc1 app/presenters/decidim/conferences/conference_stats_presenter.rb