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

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Query

#cached_query, #each, #eager?, #exists?, merge, #none?, #relation?, #|

Constructor Details

#initialize(sortition) ⇒ ParticipatorySpaceProposals

Initializes the class.

sortition - a sortition to select proposals


15
16
17
18
19
# File 'decidim-sortitions/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 'decidim-sortitions/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 particpiatory 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
41
42
43
44
45
46
47
# File 'decidim-sortitions/app/queries/decidim/sortitions/admin/participatory_space_proposals.rb', line 24

def query
  if category.nil?
    return Decidim::Proposals::Proposal
           .except_withdrawn
           .except_drafts
           .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
    .except_drafts
    .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