Sha256: 87e97f618d3645ea9c06f83b1ed2cc20349273e9163efb78f04008896cc858da
Contents?: true
Size: 1.64 KB
Versions: 7
Compression:
Stored size: 1.64 KB
Contents
# frozen_string_literal: true module Decidim module Votings # This class serializes a Voting so it can be exported to CSV, JSON or other # formats. class VotingSerializer < Decidim::Exporters::Serializer include Decidim::ApplicationHelper include Decidim::ResourceHelper include Decidim::TranslationsHelper # Public: Initializes the serializer with a voting. def initialize(voting) @voting = voting end # Public: Exports a hash with the serialized data for this voting. def serialize { participatory_space_id: voting.id, url: url, title: voting.title, description: voting.description, start_time: voting.start_time, end_time: voting.end_time, voting_type: translated_voting_type, scope: { id: voting.scope.try(:id), name: voting.scope.try(:name) }, banner_image_url: Decidim::Votings::VotingPresenter.new(voting).banner_image_url, introductory_image_url: Decidim::Votings::VotingPresenter.new(voting).introductory_image_url } end private attr_reader :voting alias resource voting def translated_voting_type translation_hash = {} voting.organization.available_locales.each do |locale| translation_hash[locale] = I18n.t(voting.voting_type, scope: "decidim.votings.admin.votings.form.voting_type") end translation_hash end def url Decidim::Votings::Engine.routes.url_helpers.voting_url(host: voting.organization.host, slug: voting.slug) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems