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 Attribute Summary collapse

Instance Method Summary collapse

Methods included from Publicable

#publish!, #published?, #unpublish!

Instance Attribute Details

#questionnaire_template_idObject

Returns the value of attribute questionnaire_template_id.


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

def questionnaire_template_id
  @questionnaire_template_id
end

Instance Method Details

#answered_by?(user) ⇒ Boolean

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

Returns:

  • (Boolean)

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

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)

33
34
35
# File 'decidim-forms/app/models/decidim/forms/questionnaire.rb', line 33

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)

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

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