Sha256: 6d973f72241a9d69a6b38b5a41d6750495dcbc188e3620e8b712fa6f6129c87c

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    class ClosureResultForm < Decidim::Form
      attribute :id, Integer
      attribute :polling_station_id, Integer
      attribute :election_id, Integer

      attribute :ballot_results, BallotResultForm
      attribute :question_results, Array[QuestionResultForm]
      attribute :answer_results, Array[AnswerResultForm]

      validates :polling_station_id,
                :election_id,
                presence: true

      def map_model(model)
        self.id = model.id
        self.polling_station_id = model.polling_station.id
        self.election_id = model.election.id

        self.ballot_results = BallotResultForm.from_model(model)

        self.question_results = model.election.questions.flat_map do |question|
          QuestionResultForm.from_model(question:, closure: model)
        end

        self.answer_results = model.election.questions.flat_map do |question|
          question.answers.map do |answer|
            AnswerResultForm.from_model(answer:, closure: model)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.28.3 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.28.2 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.28.1 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.28.0 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.28.0.rc5 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.28.0.rc4 app/forms/decidim/votings/closure_result_form.rb