Sha256: cdb518c8d4a4a34a19823c8e597c5c74aafd9e5cc1f25e94edde4508cfe29c2c

Contents?: true

Size: 1.1 KB

Versions: 31

Compression:

Stored size: 1.1 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: question, closure: model)
        end

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

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-elections-0.27.9 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.8 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.7 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.6 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.26.10 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.26.9 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.5 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.26.8 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.4 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.3 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.26.7 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.26.5 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.2 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.1 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.26.4 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.0 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.26.3 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.0.rc2 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.27.0.rc1 app/forms/decidim/votings/closure_result_form.rb
decidim-elections-0.26.2 app/forms/decidim/votings/closure_result_form.rb