Sha256: 98aaa8b163dcbfbc421554b6110c11ea54f9dcc9bc3befe90809ac4092c31f9b

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Decidim
  module Sortitions
    module Admin
      class ParticipatorySpaceProposals < Decidim::Query
        # Sugar syntax. Retrieve all proposals for the given sortition.
        def self.for(sortition)
          new(sortition).query
        end

        # Initializes the class.
        #
        # sortition - a sortition to select proposals
        def initialize(sortition)
          @sortition = sortition
          @category = sortition.category
          @request_timestamp = sortition.request_timestamp
        end

        # Given a participatory process retrieves its proposals
        #
        # Returns an ActiveRecord::Relation.
        def query
          proposals = Decidim::Proposals::Proposal
                      .not_withdrawn
                      .published
                      .not_hidden
                      .where("decidim_proposals_proposals.created_at < ?", request_timestamp)
                      .where(component: sortition.decidim_proposals_component)
          proposals = proposals.where.not(id: proposals.only_status(:rejected))

          return proposals.order(id: :asc) if category.nil?

          # categorization -> category
          proposals
            .joins(:categorization)
            .where(decidim_categorizations: { decidim_category_id: category.id })
            .order(id: :asc)
        end

        private

        attr_reader :sortition, :category, :request_timestamp
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-sortitions-0.29.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.29.0 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.29.0.rc4 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.29.0.rc3 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.29.0.rc2 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.29.0.rc1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb