Class: Decidim::Proposals::ProposalSerializer

Inherits:
Exporters::Serializer
  • Object
show all
Includes:
ApplicationHelper, ResourceHelper, TranslationsHelper, HtmlToPlainText
Defined in:
lib/decidim/proposals/proposal_serializer.rb

Overview

This class serializes a Proposal so can be exported to CSV, JSON or other formats.

Direct Known Subclasses

DownloadYourDataProposalSerializer

Instance Method Summary collapse

Constructor Details

#initialize(proposal) ⇒ ProposalSerializer

Public: Initializes the serializer with a proposal.



14
15
16
# File 'lib/decidim/proposals/proposal_serializer.rb', line 14

def initialize(proposal)
  @proposal = proposal
end

Instance Method Details

#serializeObject

Public: Exports a hash with the serialized data for this proposal.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/decidim/proposals/proposal_serializer.rb', line 19

def serialize
  {
    id: proposal.id,
    author: {
      **author_fields
    },
    taxonomies:,
    participatory_space: {
      id: proposal.participatory_space.id,
      url: Decidim::ResourceLocatorPresenter.new(proposal.participatory_space).url
    },
    component: { id: component.id },
    title: proposal.title,
    body: convert_to_plain_text(proposal.body),
    address: proposal.address,
    latitude: proposal.latitude,
    longitude: proposal.longitude,
    state: proposal.state.to_s,
    state_published_at: proposal.state_published_at,
    reference: proposal.reference,
    answer: ensure_translatable(proposal.answer),
    answered_at: proposal.answered_at,
    votes: (proposal.proposal_votes_count unless
    proposal.component.current_settings.votes_hidden?),
    likes: {
      total_count: proposal.likes.size,
      user_likes:
    },
    comments: proposal.comments_count,
    attachments: proposal.attachments.size,
    follows_count: proposal.follows_count,
    published_at: proposal.published_at,
    url:,
    meeting_urls: meetings,
    related_proposals:,
    is_amend: proposal.emendation?,
    original_proposal: {
      title: proposal&.amendable&.title,
      url: original_proposal_url
    },
    withdrawn: proposal.withdrawn?,
    withdrawn_at: proposal.withdrawn_at,
    created_at: proposal.created_at,
    updated_at: proposal.updated_at,
    created_in_meeting: proposal.created_in_meeting,
    coauthorships_count: proposal.coauthorships_count,
    cost: proposal.cost,
    cost_report: proposal.cost_report,
    execution_period: proposal.execution_period
  }
end