Class: Decidim::Forms::Questionnaire

Inherits:
ApplicationRecord show all
Includes:
Publicable, Templates::Templatable, TranslatableResource
Defined in:
decidim-forms/app/models/decidim/forms/questionnaire.rb

Overview

The data store for a Questionnaire in the Decidim::Forms component.

Instance Method Summary collapse

Methods included from Publicable

#publish!, #published?, #unpublish!

Instance Method Details

#answered_by?(user) ⇒ Boolean

Public: returns whether the questionnaire is answered by the user or not.

Returns:

  • (Boolean)

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

def answered_by?(user)
  query = user.is_a?(String) ? { session_token: user } : { user: user }
  answers.where(query).any? if questions.present?
end

#pristine?Boolean

Returns:

  • (Boolean)

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

def pristine?
  created_at.to_i == updated_at.to_i && questions.empty?
end

#questions_editable?Boolean

Public: returns whether the questionnaire questions can be modified or not.

Returns:

  • (Boolean)

20
21
22
23
# File 'decidim-forms/app/models/decidim/forms/questionnaire.rb', line 20

def questions_editable?
  has_component = questionnaire_for.respond_to? :component
  (has_component && !questionnaire_for.component.published?) || answers.empty?
end