Sha256: 2011394bcdc993037fb60fbcb24f144d70d9a501e167812ceb38b0c4432154f5

Contents?: true

Size: 833 Bytes

Versions: 17

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Surveys
    # The data store for a Survey in the Decidim::Surveys component.
    class Survey < Surveys::ApplicationRecord
      include Decidim::HasComponent

      component_manifest_name "surveys"

      has_many :questions, -> { order(:position) }, class_name: "SurveyQuestion", foreign_key: "decidim_survey_id", dependent: :destroy
      has_many :answers, class_name: "SurveyAnswer", foreign_key: "decidim_survey_id", dependent: :destroy

      # Public: returns whether the survey questions can be modified or not.
      def questions_editable?
        answers.empty?
      end

      # Public: returns whether the survey is answered by the user or not.
      def answered_by?(user)
        answers.where(user: user).count == questions.length
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
decidim-surveys-0.15.2 app/models/decidim/surveys/survey.rb
decidim-surveys-0.15.1 app/models/decidim/surveys/survey.rb
decidim-surveys-0.15.0 app/models/decidim/surveys/survey.rb
decidim-surveys-0.14.4 app/models/decidim/surveys/survey.rb
decidim-surveys-0.14.3 app/models/decidim/surveys/survey.rb
decidim-surveys-0.14.2 app/models/decidim/surveys/survey.rb
decidim-surveys-0.14.1 app/models/decidim/surveys/survey.rb
decidim-surveys-0.13.1 app/models/decidim/surveys/survey.rb
decidim-surveys-0.12.2 app/models/decidim/surveys/survey.rb
decidim-surveys-0.13.0 app/models/decidim/surveys/survey.rb
decidim-surveys-0.12.1 app/models/decidim/surveys/survey.rb
decidim-surveys-0.13.0.pre1 app/models/decidim/surveys/survey.rb
decidim-surveys-0.12.0 app/models/decidim/surveys/survey.rb
decidim-surveys-0.11.2 app/models/decidim/surveys/survey.rb
decidim-surveys-0.12.0.pre app/models/decidim/surveys/survey.rb
decidim-surveys-0.11.1 app/models/decidim/surveys/survey.rb
decidim-surveys-0.11.0.pre1 app/models/decidim/surveys/survey.rb