Class: Decidim::Sortitions::Admin::ParticipatorySpaceProposals

Inherits:
Query
  • Object
show all
Defined in:
app/queries/decidim/sortitions/admin/participatory_space_proposals.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sortition) ⇒ ParticipatorySpaceProposals

Initializes the class.

sortition - a sortition to select proposals



15
16
17
18
19
# File 'app/queries/decidim/sortitions/admin/participatory_space_proposals.rb', line 15

def initialize(sortition)
  @sortition = sortition
  @category = sortition.category
  @request_timestamp = sortition.request_timestamp
end

Class Method Details

.for(sortition) ⇒ Object

Sugar syntax. Retrieve all proposals for the given sortition.



8
9
10
# File 'app/queries/decidim/sortitions/admin/participatory_space_proposals.rb', line 8

def self.for(sortition)
  new(sortition).query
end

Instance Method Details

#queryObject

Given a participatory process retrieves its proposals

Returns an ActiveRecord::Relation.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/queries/decidim/sortitions/admin/participatory_space_proposals.rb', line 24

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