Class: Effective::LearndashEnrollment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/learndash_enrollment.rb

Constant Summary collapse

PROGRESS_STATUSES =
['not-started', 'in-progress', 'completed']

Instance Method Summary collapse

Instance Method Details

#assign_api_attributes(data = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/effective/learndash_enrollment.rb', line 66

def assign_api_attributes(data = nil)
  data ||= EffectiveLearndash.api.find_enrollment(self) || EffectiveLearndash.api.create_enrollment(self)

  assign_attributes(
    last_synced_at: Time.zone.now,
    progress_status: data[:progress_status],
    last_step: data[:last_step],
    steps_completed: data[:steps_completed],
    steps_total: data[:steps_total],
    date_started: Time.use_zone('UTC') { Time.zone.parse(data[:date_started]) },
    date_completed: (Time.use_zone('UTC') { Time.zone.parse(data[:date_completed]) } if data[:date_completed].present?)
  )
end

#completed? ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/effective/learndash_enrollment.rb', line 57

def completed?
  progress_status == 'completed'
end

#in_progress? ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/effective/learndash_enrollment.rb', line 53

def in_progress?
  progress_status == 'in-progress'
end

#not_started? ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/effective/learndash_enrollment.rb', line 49

def not_started?
  progress_status == 'not-started'
end

#refresh! ⇒ Object



61
62
63
64
# File 'app/models/effective/learndash_enrollment.rb', line 61

def refresh!
  assign_api_attributes
  save!
end

#to_s ⇒ Object



45
46
47
# File 'app/models/effective/learndash_enrollment.rb', line 45

def to_s
  persisted? ? "#{learndash_user} #{learndash_course}" : 'learndash enrollment'
end