Sha256: 7e46daee2e21ff6c38718bc584cacdc61be0b7d444e55e51f1e57570accf4f17

Contents?: true

Size: 1.5 KB

Versions: 26

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Decidim
  module Sortitions
    module Admin
      class ParticipatorySpaceProposals < Rectify::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 particpiatory process retrieves its proposals
        #
        # Returns an ActiveRecord::Relation.
        def query
          if category.nil?
            return Decidim::Proposals::Proposal
                   .except_withdrawn
                   .where("created_at < ?", request_timestamp)
                   .where(component: sortition.decidim_proposals_component)
                   .order(id: :asc)
          end

          # categorization -> category
          Decidim::Proposals::Proposal
            .joins(:categorization)
            .except_withdrawn
            .where(component: sortition.decidim_proposals_component)
            .where("decidim_proposals_proposals.created_at < ?", request_timestamp)
            .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

26 entries across 26 versions & 1 rubygems

Version Path
decidim-sortitions-0.19.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.18.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.19.0 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.17.2 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.18.0 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.17.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.16.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.17.0 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.16.0 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.15.2 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.15.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.15.0 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.14.4 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.14.3 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.14.2 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.14.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.13.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.12.2 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.13.0 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.12.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb