Sha256: a52bd7cb6502eb31623fb59259b9a0381c9c9b7ea6e704c8d05c279d748a6f9d

Contents?: true

Size: 1.69 KB

Versions: 19

Compression:

Stored size: 1.69 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 particpiatory process retrieves its proposals
        #
        # Returns an ActiveRecord::Relation.
        def query
          if category.nil?
            return Decidim::Proposals::Proposal
                   .except_withdrawn
                   .published
                   .except_rejected
                   .not_hidden
                   .where("decidim_proposals_proposals.created_at < ?", request_timestamp)
                   .where(component: sortition.decidim_proposals_component)
                   .order(id: :asc)
          end

          # categorization -> category
          Decidim::Proposals::Proposal
            .joins(:categorization)
            .except_withdrawn
            .published
            .except_rejected
            .not_hidden
            .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

19 entries across 19 versions & 1 rubygems

Version Path
decidim-sortitions-0.28.4 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.9 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.28.3 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.8 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.28.2 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.7 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.28.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.6 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.28.0 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.5 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.28.0.rc5 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.28.0.rc4 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.4 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.3 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.2 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.0 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.0.rc2 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb
decidim-sortitions-0.27.0.rc1 app/queries/decidim/sortitions/admin/participatory_space_proposals.rb