Class: Effective::LearndashEnrollment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::LearndashEnrollment
- Defined in:
- app/models/effective/learndash_enrollment.rb
Constant Summary collapse
- PROGRESS_STATUSES =
['not-started', 'in-progress', 'completed']
Instance Method Summary collapse
- #assign_api_attributes(data = nil) ⇒ Object
- #completed? ⇒ Boolean
- #in_progress? ⇒ Boolean
- #not_started? ⇒ Boolean
- #refresh!(force: false) ⇒ Object
-
#reportable_scopes ⇒ Object
effective_reports.
- #to_s ⇒ Object
Instance Method Details
#assign_api_attributes(data = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/effective/learndash_enrollment.rb', line 77 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
64 65 66 |
# File 'app/models/effective/learndash_enrollment.rb', line 64 def completed? progress_status == 'completed' end |
#in_progress? ⇒ Boolean
60 61 62 |
# File 'app/models/effective/learndash_enrollment.rb', line 60 def in_progress? progress_status == 'in-progress' end |
#not_started? ⇒ Boolean
56 57 58 |
# File 'app/models/effective/learndash_enrollment.rb', line 56 def not_started? progress_status == 'not-started' end |
#refresh!(force: false) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'app/models/effective/learndash_enrollment.rb', line 68 def refresh!(force: false) unless force return if last_synced_at.present? && (Time.zone.now - last_synced_at) < 5 end assign_api_attributes save! end |
#reportable_scopes ⇒ Object
effective_reports
37 38 39 |
# File 'app/models/effective/learndash_enrollment.rb', line 37 def reportable_scopes { completed: nil, in_progress: nil, not_started: nil } end |
#to_s ⇒ Object
52 53 54 |
# File 'app/models/effective/learndash_enrollment.rb', line 52 def to_s persisted? ? "#{learndash_user} #{learndash_course}" : 'learndash enrollment' end |