Class: Decidim::Forms::Answer

Inherits:
ApplicationRecord show all
Includes:
DownloadYourData, HasAttachments, NewsletterParticipant
Defined in:
app/models/decidim/forms/answer.rb

Overview

The data store for an Answer in the Decidim::Forms

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.export_serializerObject



31
32
33
# File 'app/models/decidim/forms/answer.rb', line 31

def self.export_serializer
  Decidim::Forms::DownloadYourDataUserAnswersSerializer
end

.newsletter_participant_ids(component) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'app/models/decidim/forms/answer.rb', line 35

def self.newsletter_participant_ids(component)
  surveys = Decidim::Surveys::Survey.joins(:component, :questionnaire).where(component:)
  questionnaires = Decidim::Forms::Questionnaire.includes(:questionnaire_for)
                                                .where(questionnaire_for_type: Decidim::Surveys::Survey.name, questionnaire_for_id: surveys.pluck(:id))

  answers = Decidim::Forms::Answer.joins(:questionnaire)
                                  .where(questionnaire: questionnaires)

  answers.pluck(:decidim_user_id).flatten.compact.uniq
end

.user_collection(user) ⇒ Object



27
28
29
# File 'app/models/decidim/forms/answer.rb', line 27

def self.user_collection(user)
  where(decidim_user_id: user.id)
end

Instance Method Details

#organizationObject



46
47
48
49
# File 'app/models/decidim/forms/answer.rb', line 46

def organization
  user.organization if user.present?
  questionnaire&.questionnaire_for.try(:organization)
end