Sha256: 5c0a84c89aa92fe53f64c7929edd14de55e3d57d8a09a337487831655611b67b

Contents?: true

Size: 942 Bytes

Versions: 12

Compression:

Stored size: 942 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This query finds the published components for all public participatory
  # spaces in the given organization. Can filter by manifest name.
  class PublicComponents < Decidim::Query
    def self.for(organization, manifest_name: nil)
      new(organization, manifest_name: manifest_name).query
    end

    def initialize(organization, manifest_name: nil)
      @organization = organization
      @manifest_name = manifest_name
    end

    def query
      results = Decidim::Component.where(participatory_space: public_spaces).published
      results = results.where(manifest_name: manifest_name) if manifest_name.present?
      results
    end

    private

    attr_reader :organization, :manifest_name

    def public_spaces
      Decidim.participatory_space_manifests.flat_map do |manifest|
        manifest.participatory_spaces.call(organization).public_spaces
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/queries/decidim/public_components.rb
decidim-core-0.27.8 app/queries/decidim/public_components.rb
decidim-core-0.27.7 app/queries/decidim/public_components.rb
decidim-core-0.27.6 app/queries/decidim/public_components.rb
decidim-core-0.27.5 app/queries/decidim/public_components.rb
decidim-core-0.27.4 app/queries/decidim/public_components.rb
decidim-core-0.27.3 app/queries/decidim/public_components.rb
decidim-core-0.27.2 app/queries/decidim/public_components.rb
decidim-core-0.27.1 app/queries/decidim/public_components.rb
decidim-core-0.27.0 app/queries/decidim/public_components.rb
decidim-core-0.27.0.rc2 app/queries/decidim/public_components.rb
decidim-core-0.27.0.rc1 app/queries/decidim/public_components.rb