effective_learndash 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6ad48916b87f1ca03d045781ddacfc02686179ebe59d61c952f71bcfd453b2b
4
- data.tar.gz: 844ec61521d4b99f35d0e4f98318ea4e78890d386883cd26521eaefb856a28f3
3
+ metadata.gz: 6eb2371d420ae282aecca6fe59883224b3102dd09d202f56be75180765b65ff3
4
+ data.tar.gz: 9e95e8974c3756bc92b844c8545e8ab10b68dd3e2bc7e8c08755b28c99db886f
5
5
  SHA512:
6
- metadata.gz: 14bea235c4f8b191060272b153faa4a82a697b69c27d6b692c788cd9f7dcfc9a36da9f428b06bf732f7ce041048eb4d35006e525054f4b3f36063f4c7c2a6c0b
7
- data.tar.gz: 559a17a64a6418df74835211a26b03f7634d21820b096bfe95c82681ca307778b576ddf76e59084f15006495eeea070fdd165f9831d7a57df4fae218f79fc97f
6
+ metadata.gz: a3b8229756fc75a69b03f0934a4eb7f8da253fc17cf37b6cf19d126d1999f3e145f2a10a74d3db4eb16f5752d8b324c18a9031827fb273b3249f0dc146236945
7
+ data.tar.gz: 101dd24f148d4356471482ac13ec54dab698e2690c368a10bf98e0672a6c3899623f2eff7ea6a5d026143c17f62d5ad5aea667eb94284c40bdf43c2aabf00769
@@ -14,9 +14,9 @@ module Admin
14
14
  time_ago_in_words(enrollment.last_synced_at) + ' ago'
15
15
  end
16
16
 
17
- col :owner
18
- col :learndash_course
17
+ col :owner, visible: attributes[:learndash_user_id].blank?
19
18
  col :learndash_user
19
+ col :learndash_course
20
20
 
21
21
  col :progress_status
22
22
 
@@ -1,11 +1,5 @@
1
- # Dashboard Courses
2
- class EffectiveLearndashCoursesDatatable < Effective::Datatable
3
- filters do
4
- # Registerable should be first here, so when displayed as a simple datatable on the dashboard they only see registerable courses
5
- scope :registerable
6
- scope :all
7
- end
8
-
1
+ # Dashboard Available Courses
2
+ class EffectiveLearndashAvailableCoursesDatatable < Effective::Datatable
9
3
  datatable do
10
4
  order :title
11
5
  col :id, visible: false
@@ -24,7 +18,10 @@ class EffectiveLearndashCoursesDatatable < Effective::Datatable
24
18
  end
25
19
 
26
20
  collection do
27
- Effective::LearndashCourse.deep.learndash_courses(user: current_user)
21
+ enrolled = Effective::LearndashEnrollment.where(learndash_user: current_user.learndash_user).select(:learndash_course_id)
22
+ courses = Effective::LearndashCourse.deep.registerable.learndash_courses(user: current_user)
23
+
24
+ courses.where.not(id: enrolled)
28
25
  end
29
26
 
30
27
  end
@@ -43,6 +43,22 @@ module EffectiveLearndashOwner
43
43
  learndash_users.first
44
44
  end
45
45
 
46
+ def in_progress_learndash_enrollments
47
+ learndash_enrollments.reject(&:completed?).sort_by(&:created_at)
48
+ end
49
+
50
+ def completed_learndash_enrollments
51
+ learndash_enrollments.select(&:completed?).sort_by(&:date_completed)
52
+ end
53
+
54
+ def completed_learndash_courses
55
+ learndash_enrollments.select(&:completed?).map(&:course).sort_by(&:id)
56
+ end
57
+
58
+ def learndash_enrolled_courses
59
+ learndash_enrollments.map { |enrollment| enrollment.learndash_course }
60
+ end
61
+
46
62
  # Find or create
47
63
  def create_learndash_user
48
64
  learndash_user || learndash_users.create!(owner: self)
@@ -67,11 +83,48 @@ module EffectiveLearndashOwner
67
83
  return false if enrollment.blank?
68
84
 
69
85
  # Return completed right away if previously marked completed
70
- return true if enrollment.completed?
71
-
72
- # Check the API
73
- enrollment.refresh!
74
86
  enrollment.completed?
87
+
88
+ # DO NOT check API
89
+ end
90
+
91
+ def learndash_enroll!(courses:)
92
+ courses = Array(courses)
93
+
94
+ # Find or create the user
95
+ create_learndash_user
96
+ raise('expected a persisted learndash user') unless learndash_user&.persisted?
97
+
98
+ courses.each do |course|
99
+ # Find or Enroll in the course
100
+ create_learndash_enrollment(course: course)
101
+ raise('expected a persisted learndash enrollment') unless learndash_enrollment(course: course)&.persisted?
102
+ end
103
+
104
+ # This syncs the learndash enrollment locally
105
+ learndash_enrollments.select { |enrollment| courses.include?(enrollment.learndash_course) }.each do |enrollment|
106
+ enrollment.refresh! unless enrollment.completed?
107
+ end
108
+
109
+ save!
110
+
111
+ after_learndash_enroll() if respond_to?(:after_learndash_enroll)
112
+
113
+ true
114
+ end
115
+
116
+ def learndash_refresh!(force: false)
117
+ raise('expected a previously persisted learndash user') if learndash_user.blank?
118
+
119
+ learndash_enrollments.each do |enrollment|
120
+ enrollment.refresh!(force: force) unless (force || enrollment.completed?)
121
+ end
122
+
123
+ save!
124
+
125
+ after_learndash_refresh() if respond_to?(:after_learndash_refresh)
126
+
127
+ true
75
128
  end
76
129
 
77
130
  end
@@ -8,7 +8,9 @@ module Effective
8
8
 
9
9
  log_changes(to: :learndash_course, except: [:last_synced_at]) if respond_to?(:log_changes)
10
10
 
11
- PROGRESS_STATUSES = ['not-started', 'in-progress', 'completed']
11
+ # Only admin can mark finished
12
+ # Finished is treated as an admin override for completed?
13
+ PROGRESS_STATUSES = ['not-started', 'in-progress', 'completed', 'finished']
12
14
 
13
15
  effective_resource do
14
16
  last_synced_at :string
@@ -26,7 +28,7 @@ module Effective
26
28
  timestamps
27
29
  end
28
30
 
29
- scope :completed, -> { where(progress_status: 'completed') }
31
+ scope :completed, -> { where(progress_status: ['completed', 'finished']) }
30
32
  scope :in_progress, -> { where(progress_status: 'in-progress') }
31
33
  scope :not_started, -> { where(progress_status: 'not-started') }
32
34
 
@@ -61,8 +63,35 @@ module Effective
61
63
  progress_status == 'in-progress'
62
64
  end
63
65
 
66
+ # Admin override to completed
67
+ def finished?
68
+ progress_status == 'finished'
69
+ end
70
+
71
+ # Checked to see if the course is done throughout
64
72
  def completed?
65
- progress_status == 'completed'
73
+ progress_status == 'completed' || finished?
74
+ end
75
+
76
+ def completed_on
77
+ date_completed || (created_at if finished?)
78
+ end
79
+
80
+ def mark_as_finished!
81
+ update!(progress_status: 'finished')
82
+ end
83
+
84
+ # Guess old status
85
+ def unfinish!
86
+ if date_completed.present?
87
+ assign_attributes(progress_status: 'completed')
88
+ elsif date_started.present?
89
+ assign_attributes(progress_status: 'in-progress')
90
+ else
91
+ assign_attributes(progress_status: 'not-started')
92
+ end
93
+
94
+ save!
66
95
  end
67
96
 
68
97
  def refresh!(force: false)
@@ -79,13 +108,16 @@ module Effective
79
108
 
80
109
  assign_attributes(
81
110
  last_synced_at: Time.zone.now,
82
- progress_status: data[:progress_status],
83
111
  last_step: data[:last_step],
84
112
  steps_completed: data[:steps_completed],
85
113
  steps_total: data[:steps_total],
86
114
  date_started: Time.use_zone('UTC') { Time.zone.parse(data[:date_started]) },
87
115
  date_completed: (Time.use_zone('UTC') { Time.zone.parse(data[:date_completed]) } if data[:date_completed].present?)
88
116
  )
117
+
118
+ assign_attributes(progress_status: data[:progress_status]) unless finished?
119
+
120
+ true
89
121
  end
90
122
 
91
123
  end
@@ -8,6 +8,7 @@
8
8
  %p Click the New button from the below table to enroll a user into this course.
9
9
  %p Enrolling a user here will enroll them on the LearnDash site.
10
10
  %p Alternately, if this course is available for registration, the enrollment will be created upon registration purchase.
11
+ %p Marking the course finished will allow them to proceed without completing the course on the Learndash LMS.
11
12
 
12
13
  - datatable = Admin::EffectiveLearndashEnrollmentsDatatable.new(learndash_course: learndash_course)
13
14
  = render_datatable(datatable, inline: true)
@@ -21,7 +21,10 @@
21
21
 
22
22
  %h3 LearnDash Course Enrollments
23
23
 
24
- %p Click the New button from the below table to manually enroll this user into a new course.
24
+ %p
25
+ Click the New button from the below table to manually enroll this user into a new course.
26
+ %br
27
+ %small.text-muted Marking the course finished will allow them to proceed without completing the course on the Learndash LMS.
25
28
 
26
29
  - datatable = Admin::EffectiveLearndashEnrollmentsDatatable.new(learndash_user: learndash_user)
27
30
  = render_datatable(datatable, inline: true)
@@ -1,12 +1,13 @@
1
1
  - learndash_user = current_user.try(:learndash_user)
2
- - authorized = learndash_user && EffectiveResources.authorized?(self, :show, learndash_user)
2
+ - authorized_user = learndash_user && EffectiveResources.authorized?(self, :show, learndash_user)
3
+ - authorized_registration = EffectiveResources.authorized?(self, :new, EffectiveLearndash.CourseRegistration)
3
4
 
4
5
  %h2 Courses
5
6
 
6
7
  - if learndash_user.blank?
7
8
  %p You do not have an account to access courses. When you are enrolled in a course, your account credentials will be displayed here.
8
9
 
9
- - if learndash_user.present? && authorized
10
+ - if learndash_user.present? && authorized_user
10
11
  - learndash_user.refresh!
11
12
 
12
13
  %p Your course account credentials are:
@@ -22,8 +23,15 @@
22
23
  %p= link_to('Sign in to your course account', EffectiveLearndash.learndash_url, target: '_blank', class: 'btn btn-primary')
23
24
 
24
25
  - if learndash_user.learndash_enrollments.present?
26
+ %p You are enrolled in the following courses:
25
27
  - datatable = EffectiveResources.best('EffectiveLearndashEnrollmentsDatatable').new(self)
26
28
  = render_datatable(datatable, simple: true)
27
29
 
28
30
  - else
29
31
  %p You are not enrolled in any courses.
32
+
33
+ - available = EffectiveResources.best('EffectiveLearndashAvailableCoursesDatatable').new(self)
34
+
35
+ - if available.present? && authorized_registration
36
+ %p The following courses are available for registration:
37
+ = render_datatable(available, simple: true)
data/config/routes.rb CHANGED
@@ -23,6 +23,8 @@ EffectiveLearndash::Engine.routes.draw do
23
23
 
24
24
  resources :learndash_enrollments, only: [:index, :new, :create, :update] do
25
25
  post :refresh, on: :member
26
+ post :mark_as_finished, on: :member
27
+ post :unfinish, on: :member
26
28
  end
27
29
 
28
30
  resources :learndash_courses, only: [:index, :edit, :update] do
@@ -1,3 +1,3 @@
1
1
  module EffectiveLearndash
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_learndash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-24 00:00:00.000000000 Z
11
+ date: 2023-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -191,7 +191,7 @@ files:
191
191
  - app/datatables/admin/effective_learndash_users_datatable.rb
192
192
  - app/datatables/effective_course_registrants_datatable.rb
193
193
  - app/datatables/effective_course_registrations_datatable.rb
194
- - app/datatables/effective_learndash_courses_datatable.rb
194
+ - app/datatables/effective_learndash_available_courses_datatable.rb
195
195
  - app/datatables/effective_learndash_enrollments_datatable.rb
196
196
  - app/helpers/effective_learndash_helper.rb
197
197
  - app/models/concerns/effective_learndash_course_registration.rb