Class: Course::Condition::Assessment

Inherits:
ApplicationRecord show all
Includes:
ActiveSupport::NumberHelper, DuplicationStateTrackingConcern
Defined in:
app/models/course/condition/assessment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DuplicationStateTrackingConcern

#clear_duplication_flag, #duplicating?, #set_duplication_flag

Class Method Details

.dependent_classObject

Class that the condition depends on.


51
52
53
# File 'app/models/course/condition/assessment.rb', line 51

def self.dependent_class
  Course::Assessment.name
end

.on_dependent_status_change(submission) ⇒ Object


55
56
57
58
59
60
61
# File 'app/models/course/condition/assessment.rb', line 55

def self.on_dependent_status_change(submission)
  return unless submission.saved_changes.key?(:workflow_state)

  submission.execute_after_commit do
    evaluate_conditional_for(submission.course_user) if submission.current_state >= :submitted
  end
end

Instance Method Details

#initialize_duplicate(duplicator, other) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/course/condition/assessment.rb', line 63

def initialize_duplicate(duplicator, other)
  self.assessment = duplicator.duplicate(other.assessment)
  self.conditional_type = other.conditional_type
  self.conditional = duplicator.duplicate(other.conditional)

  if duplicator.mode == :course
    self.course = duplicator.duplicate(other.course)
  elsif duplicator.mode == :object
    self.course = duplicator.options[:destination_course]
  end

  set_duplication_flag
end

#satisfied_by?(course_user) ⇒ Boolean

Returns:

  • (Boolean)

36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/course/condition/assessment.rb', line 36

def satisfied_by?(course_user)
  # Unpublished assessments are considered not satisfied.
  return false unless assessment.published?

  user = course_user.user

  if minimum_grade_percentage
    minimum_grade = assessment.maximum_grade * minimum_grade_percentage / 100.0
    published_submissions_with_minimum_grade(user, minimum_grade).exists?
  else
    (user).exists?
  end
end

#titleObject


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/course/condition/assessment.rb', line 22

def title
  if minimum_grade_percentage
    minimum_grade_percentage_display = number_to_percentage(minimum_grade_percentage,
                                                            precision: 2,
                                                            strip_insignificant_zeros: true)
    self.class.human_attribute_name('title.minimum_score',
                                    assessment_title: assessment.title,
                                    minimum_grade_percentage: minimum_grade_percentage_display)
  else
    self.class.human_attribute_name('title.complete',
                                    assessment_title: assessment.title)
  end
end