Sha256: 80e41a9eaab102bd04aec2fc8912f3a0fc495302b7225c13f2b48c4f4f1398ca

Contents?: true

Size: 787 Bytes

Versions: 43

Compression:

Stored size: 787 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::HasFeature

      feature_manifest_name "surveys"

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

      # 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

43 entries across 43 versions & 2 rubygems

Version Path
decidim-surveys-0.7.4 app/models/decidim/surveys/survey.rb
decidim-surveys-0.7.3 app/models/decidim/surveys/survey.rb
decidim-surveys-0.7.2 app/models/decidim/surveys/survey.rb
decidim-surveys-0.7.1 app/models/decidim/surveys/survey.rb
decidim-surveys-0.7.0 app/models/decidim/surveys/survey.rb
decidim-surveys-0.6.8 app/models/decidim/surveys/survey.rb
decidim-0.6.8 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.6.7 app/models/decidim/surveys/survey.rb
decidim-0.6.7 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.6.6 app/models/decidim/surveys/survey.rb
decidim-0.6.6 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.6.5 app/models/decidim/surveys/survey.rb
decidim-0.6.5 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.6.4 app/models/decidim/surveys/survey.rb
decidim-0.6.4 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.6.3 app/models/decidim/surveys/survey.rb
decidim-0.6.3 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.6.2 app/models/decidim/surveys/survey.rb
decidim-0.6.2 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.6.1 app/models/decidim/surveys/survey.rb