Sha256: 2ed65b9594a1dfe8b5a88d469700a6ace771f87c6952e988dd3196f4aeaf4af6
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 KB
Contents
# frozen_string_literal: true module Decidim module Forms # The data store for a Questionnaire in the Decidim::Forms component. class Questionnaire < Forms::ApplicationRecord include Decidim::Templates::Templatable if defined? Decidim::Templates::Templatable include Decidim::Publicable include Decidim::TranslatableResource translatable_fields :title, :description, :tos belongs_to :questionnaire_for, polymorphic: true has_many :questions, -> { order(:position) }, class_name: "Question", foreign_key: "decidim_questionnaire_id", dependent: :destroy has_many :answers, class_name: "Answer", foreign_key: "decidim_questionnaire_id", dependent: :destroy # Public: returns whether the questionnaire questions can be modified or not. def questions_editable? has_component = questionnaire_for.respond_to? :component (has_component && !questionnaire_for.component.published?) || answers.empty? end # Public: returns whether the questionnaire is answered by the user or not. def answered_by?(user) query = user.is_a?(String) ? { session_token: user } : { user: user } answers.where(query).any? if questions.present? end def pristine? created_at.to_i == updated_at.to_i && questions.empty? end end end end
Version data entries
3 entries across 3 versions & 1 rubygems