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



44
45
46
47
# File 'app/models/concerns/effective_learndash_owner.rb', line 44

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



34
35
36
# File 'app/models/concerns/effective_learndash_owner.rb', line 34

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

#learndash_completed?(course:) ⇒ Boolean

Find or sync and check completed?

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/concerns/effective_learndash_owner.rb', line 50

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



39
40
41
# File 'app/models/concerns/effective_learndash_owner.rb', line 39

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

#learndash_userObject

Find



29
30
31
# File 'app/models/concerns/effective_learndash_owner.rb', line 29

def learndash_user
  learndash_users.first
end