effective_learndash 0.3.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d25f8c1921377617abd4004f3adbb82d9e38589462c259a37e547ab2ec27798
4
- data.tar.gz: 90e18a4a91c097e933bc8488a2f93df434c804f4f66ad8d5520f9861bf80053f
3
+ metadata.gz: 6eb2371d420ae282aecca6fe59883224b3102dd09d202f56be75180765b65ff3
4
+ data.tar.gz: 9e95e8974c3756bc92b844c8545e8ab10b68dd3e2bc7e8c08755b28c99db886f
5
5
  SHA512:
6
- metadata.gz: d2a6e4788833e47dba46b14a0055f54f7d183261e81f6e74672cd408406109f691a2b80f9f25f4576f05d9adc437ea3af50abd583d501b3092a429a52cad23da
7
- data.tar.gz: e6fce4b599ff82a65b53859a95668462a97b7ba6509e81b00268d735802163c0cd271bc85fc9ae0c276425e1ab4a98ab07f3724cee4fe2f7162c42de4b648a1b
6
+ metadata.gz: a3b8229756fc75a69b03f0934a4eb7f8da253fc17cf37b6cf19d126d1999f3e145f2a10a74d3db4eb16f5752d8b324c18a9031827fb273b3249f0dc146236945
7
+ data.tar.gz: 101dd24f148d4356471482ac13ec54dab698e2690c368a10bf98e0672a6c3899623f2eff7ea6a5d026143c17f62d5ad5aea667eb94284c40bdf43c2aabf00769
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2022 Code and Effect Inc.
1
+ Copyright 2023 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -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,4 +1,4 @@
1
- class CreateEffectiveLearndash < ActiveRecord::Migration[6.1]
1
+ class CreateEffectiveLearndash < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :learndash_users do |t|
4
4
  t.integer :owner_id
@@ -1,3 +1,3 @@
1
1
  module EffectiveLearndash
2
- VERSION = '0.3.3'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -20,7 +20,7 @@ module EffectiveLearndash
20
20
  end
21
21
 
22
22
  def create_migration_file
23
- migration_template ('../' * 3) + 'db/migrate/01_create_effective_learndash.rb.erb', 'db/migrate/create_effective_learndash.rb'
23
+ migration_template ('../' * 3) + 'db/migrate/101_create_effective_learndash.rb', 'db/migrate/create_effective_learndash.rb'
24
24
  end
25
25
 
26
26
  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.3.3
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-03-28 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
@@ -229,7 +229,7 @@ files:
229
229
  - app/views/effective/learndash_courses/show.html.haml
230
230
  - config/effective_learndash.rb
231
231
  - config/routes.rb
232
- - db/migrate/01_create_effective_learndash.rb.erb
232
+ - db/migrate/101_create_effective_learndash.rb
233
233
  - db/seeds.rb
234
234
  - lib/effective_learndash.rb
235
235
  - lib/effective_learndash/engine.rb
@@ -256,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
256
  - !ruby/object:Gem::Version
257
257
  version: '0'
258
258
  requirements: []
259
- rubygems_version: 3.1.2
259
+ rubygems_version: 3.3.7
260
260
  signing_key:
261
261
  specification_version: 4
262
262
  summary: Create Wordpress users and read LearnDash course progress