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-0.6.1 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.6.0 app/models/decidim/surveys/survey.rb
decidim-0.6.0 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.5.1 app/models/decidim/surveys/survey.rb
decidim-0.5.1 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.5.0 app/models/decidim/surveys/survey.rb
decidim-0.5.0 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.4.4 app/models/decidim/surveys/survey.rb
decidim-0.4.4 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.4.3 app/models/decidim/surveys/survey.rb
decidim-surveys-0.4.2 app/models/decidim/surveys/survey.rb
decidim-surveys-0.4.1 app/models/decidim/surveys/survey.rb
decidim-0.4.3 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-0.4.2 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-0.4.1 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.4.0 app/models/decidim/surveys/survey.rb
decidim-0.4.0 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.3.2 app/models/decidim/surveys/survey.rb
decidim-0.3.2 decidim-surveys/app/models/decidim/surveys/survey.rb
decidim-surveys-0.3.1 app/models/decidim/surveys/survey.rb