Sha256: 29daf9e3fce6faa39797119258212310f6ea107f5821534e8f72de81891c4cb0

Contents?: true

Size: 1.3 KB

Versions: 13

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Decidim
  module Surveys
    class SurveyConfirmationMailer < ApplicationMailer
      include TranslatableAttributes
      helper Decidim::SanitizeHelper

      def confirmation(user, questionnaire, answers)
        return if answers.blank? || user.nil?

        with_user(user) do
          @user = user
          @questionnaire_title = translated_attribute(questionnaire.title)
          @participatory_space_title = translated_attribute(questionnaire.questionnaire_for.component.participatory_space.title)
          @organization = user.organization

          add_file_with_answers(answers)

          mail(to: "#{@user.name} <#{@user.email}>", subject: t(".subject", questionnaire_title: @questionnaire_title))
        end
      end

      private

      def add_file_with_answers(answers)
        export_name = t("decidim.surveys.survey_confirmation_mailer.export_name")
        serializer = Decidim::Forms::UserAnswersSerializer

        export_data = Decidim::Exporters::FormPDF.new(answers, serializer).export

        filename = export_data.filename(export_name)
        filename_without_extension = export_data.filename(export_name, extension: false)

        attachments["#{filename_without_extension}.zip"] = FileZipper.new(filename, export_data.read).zip
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-surveys-0.29.1 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.28.4 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.29.0 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.28.3 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.29.0.rc4 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.29.0.rc3 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.29.0.rc2 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.29.0.rc1 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.28.2 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.28.1 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.28.0 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.28.0.rc5 app/mailers/decidim/surveys/survey_confirmation_mailer.rb
decidim-surveys-0.28.0.rc4 app/mailers/decidim/surveys/survey_confirmation_mailer.rb