Module: EffectiveLearndashOwner

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/effective_learndash_owner.rb

Overview

EffectiveLearndashOwner

Mark your user model with effective_learndash_owner to get all the includes

Defined Under Namespace

Modules: Base, ClassMethods

Instance Method Summary collapse

Instance Method Details

#create_learndash_enrollment(course:) ⇒ Object

Find or create



57
58
59
60
# File 'app/models/concerns/effective_learndash_owner.rb', line 57

def create_learndash_enrollment(course:)
  raise('expected a persisted learndash_user') unless learndash_user&.persisted?
  learndash_user.create_enrollment(course: course)
end

#create_learndash_userObject

Find or create



47
48
49
# File 'app/models/concerns/effective_learndash_owner.rb', line 47

def create_learndash_user
  learndash_user || learndash_users.create!(owner: self)
end

#learndash_completed?(course:) ⇒ Boolean

Find or sync and check completed?

Returns:

  • (Boolean)


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

def learndash_completed?(course:)
  enrollment = learndash_enrollment(course: course)

  # We haven't been enrolled
  return false if enrollment.blank?

  # Return completed right away if previously marked completed
  return true if enrollment.completed?

  # Check the API
  enrollment.refresh!
  enrollment.completed?
end

#learndash_enrollment(course:) ⇒ Object

Find



52
53
54
# File 'app/models/concerns/effective_learndash_owner.rb', line 52

def learndash_enrollment(course:)
  learndash_user&.enrollment(course: course)
end

#learndash_userObject

Find



42
43
44
# File 'app/models/concerns/effective_learndash_owner.rb', line 42

def learndash_user
  learndash_users.first
end