Class: Decidim::Forms::Answer

Inherits:
ApplicationRecord show all
Includes:
DataPortability, HasAttachments, NewsletterParticipant
Defined in:
decidim-forms/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

Methods included from HasAttachments

#attachment_context

Class Method Details

.export_serializerObject


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

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

.newsletter_participant_ids(component) ⇒ Object


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

def self.newsletter_participant_ids(component)
  surveys = Decidim::Surveys::Survey.joins(:component, :questionnaire).where(component: 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


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

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

Instance Method Details

#organizationObject


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

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