@memberjunction/actions-bizapps-lms 2.55.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.
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +12 -0
- package/dist/base/base-lms.action.d.ts +77 -0
- package/dist/base/base-lms.action.d.ts.map +1 -0
- package/dist/base/base-lms.action.js +176 -0
- package/dist/base/base-lms.action.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts +125 -0
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-courses.action.js +436 -0
- package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +95 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.js +280 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +151 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.js +417 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-users.action.d.ts +53 -0
- package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-users.action.js +272 -0
- package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/index.d.ts +5 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/index.js +22 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -0
- package/dist/providers/learnworlds/index.d.ts +3 -0
- package/dist/providers/learnworlds/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/index.js +21 -0
- package/dist/providers/learnworlds/index.js.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts +52 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.js +186 -0
- package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -0
- package/package.json +40 -0
- package/src/base/base-lms.action.ts +197 -0
- package/src/index.ts +5 -0
- package/src/providers/learnworlds/actions/get-courses.action.ts +592 -0
- package/src/providers/learnworlds/actions/get-user-details.action.ts +381 -0
- package/src/providers/learnworlds/actions/get-user-progress.action.ts +625 -0
- package/src/providers/learnworlds/actions/get-users.action.ts +319 -0
- package/src/providers/learnworlds/actions/index.ts +5 -0
- package/src/providers/learnworlds/index.ts +5 -0
- package/src/providers/learnworlds/learnworlds-base.action.ts +221 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
2
|
+
import { LearnWorldsBaseAction } from '../learnworlds-base.action';
|
|
3
|
+
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Interface for user progress in a course
|
|
7
|
+
*/
|
|
8
|
+
export interface CourseProgress {
|
|
9
|
+
courseId: string;
|
|
10
|
+
courseTitle: string;
|
|
11
|
+
enrollmentId: string;
|
|
12
|
+
enrolledAt: Date;
|
|
13
|
+
lastAccessedAt?: Date;
|
|
14
|
+
|
|
15
|
+
// Progress metrics
|
|
16
|
+
progressPercentage: number;
|
|
17
|
+
completedUnits: number;
|
|
18
|
+
totalUnits: number;
|
|
19
|
+
completedLessons: number;
|
|
20
|
+
totalLessons: number;
|
|
21
|
+
|
|
22
|
+
// Time metrics
|
|
23
|
+
totalTimeSpent: number;
|
|
24
|
+
averageSessionTime: number;
|
|
25
|
+
estimatedTimeToComplete?: number;
|
|
26
|
+
|
|
27
|
+
// Performance metrics
|
|
28
|
+
quizScoreAverage?: number;
|
|
29
|
+
assignmentsCompleted?: number;
|
|
30
|
+
assignmentsTotal?: number;
|
|
31
|
+
currentGrade?: number;
|
|
32
|
+
|
|
33
|
+
// Status
|
|
34
|
+
status: 'not_started' | 'in_progress' | 'completed' | 'expired';
|
|
35
|
+
completedAt?: Date;
|
|
36
|
+
expiresAt?: Date;
|
|
37
|
+
certificateEarned: boolean;
|
|
38
|
+
certificateUrl?: string;
|
|
39
|
+
|
|
40
|
+
// Unit-level progress
|
|
41
|
+
unitProgress?: UnitProgress[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Interface for progress within a course unit/module
|
|
46
|
+
*/
|
|
47
|
+
export interface UnitProgress {
|
|
48
|
+
unitId: string;
|
|
49
|
+
unitTitle: string;
|
|
50
|
+
unitType: 'section' | 'chapter' | 'module';
|
|
51
|
+
order: number;
|
|
52
|
+
|
|
53
|
+
// Progress
|
|
54
|
+
progressPercentage: number;
|
|
55
|
+
completedLessons: number;
|
|
56
|
+
totalLessons: number;
|
|
57
|
+
timeSpent: number;
|
|
58
|
+
|
|
59
|
+
// Status
|
|
60
|
+
status: 'not_started' | 'in_progress' | 'completed';
|
|
61
|
+
startedAt?: Date;
|
|
62
|
+
completedAt?: Date;
|
|
63
|
+
|
|
64
|
+
// Lesson details
|
|
65
|
+
lessons?: LessonProgress[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Interface for individual lesson progress
|
|
70
|
+
*/
|
|
71
|
+
export interface LessonProgress {
|
|
72
|
+
lessonId: string;
|
|
73
|
+
lessonTitle: string;
|
|
74
|
+
lessonType: 'video' | 'text' | 'quiz' | 'assignment' | 'scorm' | 'interactive';
|
|
75
|
+
order: number;
|
|
76
|
+
|
|
77
|
+
// Progress
|
|
78
|
+
completed: boolean;
|
|
79
|
+
progressPercentage: number;
|
|
80
|
+
timeSpent: number;
|
|
81
|
+
|
|
82
|
+
// Timestamps
|
|
83
|
+
startedAt?: Date;
|
|
84
|
+
completedAt?: Date;
|
|
85
|
+
lastAccessedAt?: Date;
|
|
86
|
+
|
|
87
|
+
// Additional data for specific types
|
|
88
|
+
videoWatchTime?: number;
|
|
89
|
+
videoTotalTime?: number;
|
|
90
|
+
quizScore?: number;
|
|
91
|
+
quizMaxScore?: number;
|
|
92
|
+
quizAttempts?: number;
|
|
93
|
+
assignmentSubmitted?: boolean;
|
|
94
|
+
assignmentGrade?: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Interface for overall user learning progress
|
|
99
|
+
*/
|
|
100
|
+
export interface UserLearningProgress {
|
|
101
|
+
userId: string;
|
|
102
|
+
userEmail: string;
|
|
103
|
+
totalCourses: number;
|
|
104
|
+
coursesCompleted: number;
|
|
105
|
+
coursesInProgress: number;
|
|
106
|
+
coursesNotStarted: number;
|
|
107
|
+
overallProgressPercentage: number;
|
|
108
|
+
totalTimeSpent: number;
|
|
109
|
+
totalCertificatesEarned: number;
|
|
110
|
+
averageQuizScore?: number;
|
|
111
|
+
courses: CourseProgress[];
|
|
112
|
+
|
|
113
|
+
// Analytics
|
|
114
|
+
learningStreak?: number;
|
|
115
|
+
lastLearningDate?: Date;
|
|
116
|
+
mostActiveDay?: string;
|
|
117
|
+
preferredLearningTime?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Action to retrieve detailed progress information for a LearnWorlds user
|
|
122
|
+
*/
|
|
123
|
+
@RegisterClass(LearnWorldsBaseAction, 'GetLearnWorldsUserProgressAction')
|
|
124
|
+
export class GetLearnWorldsUserProgressAction extends LearnWorldsBaseAction {
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Description of the action
|
|
128
|
+
*/
|
|
129
|
+
public get Description(): string {
|
|
130
|
+
return 'Retrieves comprehensive learning progress for a user in LearnWorlds, including course completion, time spent, and detailed unit/lesson progress';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Main execution method
|
|
135
|
+
*/
|
|
136
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
137
|
+
try {
|
|
138
|
+
const contextUser = params.ContextUser;
|
|
139
|
+
if (!contextUser) {
|
|
140
|
+
return {
|
|
141
|
+
Success: false,
|
|
142
|
+
ResultCode: 'ERROR',
|
|
143
|
+
Message: 'Context user is required for LearnWorlds API calls'
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Store params for base class methods
|
|
148
|
+
this.params = params.Params;
|
|
149
|
+
|
|
150
|
+
// Get user ID
|
|
151
|
+
const userId = this.getParamValue(params.Params, 'UserID');
|
|
152
|
+
if (!userId) {
|
|
153
|
+
return {
|
|
154
|
+
Success: false,
|
|
155
|
+
ResultCode: 'ERROR',
|
|
156
|
+
Message: 'UserID parameter is required'
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Optional course ID for specific course progress
|
|
161
|
+
const courseId = this.getParamValue(params.Params, 'CourseID');
|
|
162
|
+
const includeUnitDetails = this.getParamValue(params.Params, 'IncludeUnitDetails') ?? false;
|
|
163
|
+
const includeLessonDetails = this.getParamValue(params.Params, 'IncludeLessonDetails') ?? false;
|
|
164
|
+
|
|
165
|
+
let userProgress: UserLearningProgress;
|
|
166
|
+
|
|
167
|
+
if (courseId) {
|
|
168
|
+
// Get progress for specific course
|
|
169
|
+
const courseProgress = await this.getCourseProgress(userId, courseId, includeUnitDetails, includeLessonDetails, contextUser);
|
|
170
|
+
|
|
171
|
+
// Create user progress object with single course
|
|
172
|
+
userProgress = {
|
|
173
|
+
userId,
|
|
174
|
+
userEmail: '', // Will be populated if we get user info
|
|
175
|
+
totalCourses: 1,
|
|
176
|
+
coursesCompleted: courseProgress.status === 'completed' ? 1 : 0,
|
|
177
|
+
coursesInProgress: courseProgress.status === 'in_progress' ? 1 : 0,
|
|
178
|
+
coursesNotStarted: courseProgress.status === 'not_started' ? 1 : 0,
|
|
179
|
+
overallProgressPercentage: courseProgress.progressPercentage,
|
|
180
|
+
totalTimeSpent: courseProgress.totalTimeSpent,
|
|
181
|
+
totalCertificatesEarned: courseProgress.certificateEarned ? 1 : 0,
|
|
182
|
+
courses: [courseProgress]
|
|
183
|
+
};
|
|
184
|
+
} else {
|
|
185
|
+
// Get progress for all courses
|
|
186
|
+
userProgress = await this.getAllCoursesProgress(userId, includeUnitDetails, includeLessonDetails, contextUser);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Try to get user email
|
|
190
|
+
try {
|
|
191
|
+
const userInfo = await this.makeLearnWorldsRequest<any>(
|
|
192
|
+
`users/${userId}`,
|
|
193
|
+
'GET',
|
|
194
|
+
undefined,
|
|
195
|
+
contextUser
|
|
196
|
+
);
|
|
197
|
+
userProgress.userEmail = userInfo.email || '';
|
|
198
|
+
} catch {
|
|
199
|
+
// Ignore if we can't get user info
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Calculate analytics
|
|
203
|
+
this.calculateLearningAnalytics(userProgress);
|
|
204
|
+
|
|
205
|
+
// Create output parameters
|
|
206
|
+
if (!params.Params.find(p => p.Name === 'UserProgress')) {
|
|
207
|
+
params.Params.push({
|
|
208
|
+
Name: 'UserProgress',
|
|
209
|
+
Type: 'Output',
|
|
210
|
+
Value: userProgress
|
|
211
|
+
});
|
|
212
|
+
} else {
|
|
213
|
+
params.Params.find(p => p.Name === 'UserProgress')!.Value = userProgress;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!params.Params.find(p => p.Name === 'Summary')) {
|
|
217
|
+
params.Params.push({
|
|
218
|
+
Name: 'Summary',
|
|
219
|
+
Type: 'Output',
|
|
220
|
+
Value: this.createProgressSummary(userProgress)
|
|
221
|
+
});
|
|
222
|
+
} else {
|
|
223
|
+
params.Params.find(p => p.Name === 'Summary')!.Value = this.createProgressSummary(userProgress);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
Success: true,
|
|
228
|
+
ResultCode: 'SUCCESS',
|
|
229
|
+
Message: courseId ?
|
|
230
|
+
`Successfully retrieved progress for course ${courseId}` :
|
|
231
|
+
`Successfully retrieved progress for ${userProgress.totalCourses} courses`
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
} catch (error) {
|
|
235
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
236
|
+
return {
|
|
237
|
+
Success: false,
|
|
238
|
+
ResultCode: 'ERROR',
|
|
239
|
+
Message: errorMessage
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Get progress for a specific course
|
|
246
|
+
*/
|
|
247
|
+
private async getCourseProgress(
|
|
248
|
+
userId: string,
|
|
249
|
+
courseId: string,
|
|
250
|
+
includeUnits: boolean,
|
|
251
|
+
includeLessons: boolean,
|
|
252
|
+
contextUser: any
|
|
253
|
+
): Promise<CourseProgress> {
|
|
254
|
+
// Get enrollment/progress data
|
|
255
|
+
const progressResponse = await this.makeLearnWorldsRequest<any>(
|
|
256
|
+
`users/${userId}/courses/${courseId}/progress`,
|
|
257
|
+
'GET',
|
|
258
|
+
undefined,
|
|
259
|
+
contextUser
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const progress = this.mapCourseProgress(progressResponse);
|
|
263
|
+
|
|
264
|
+
// Get unit-level details if requested
|
|
265
|
+
if (includeUnits) {
|
|
266
|
+
try {
|
|
267
|
+
const unitsResponse = await this.makeLearnWorldsRequest<{
|
|
268
|
+
data: any[]
|
|
269
|
+
}>(
|
|
270
|
+
`users/${userId}/courses/${courseId}/units`,
|
|
271
|
+
'GET',
|
|
272
|
+
undefined,
|
|
273
|
+
contextUser
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
if (unitsResponse.data) {
|
|
277
|
+
progress.unitProgress = await Promise.all(
|
|
278
|
+
unitsResponse.data.map(unit =>
|
|
279
|
+
this.mapUnitProgress(unit, userId, courseId, includeLessons, contextUser)
|
|
280
|
+
)
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
} catch {
|
|
284
|
+
// Units endpoint might not be available
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return progress;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Get progress for all user courses
|
|
293
|
+
*/
|
|
294
|
+
private async getAllCoursesProgress(
|
|
295
|
+
userId: string,
|
|
296
|
+
includeUnits: boolean,
|
|
297
|
+
includeLessons: boolean,
|
|
298
|
+
contextUser: any
|
|
299
|
+
): Promise<UserLearningProgress> {
|
|
300
|
+
// Get all enrollments
|
|
301
|
+
const enrollmentsResponse = await this.makeLearnWorldsRequest<{
|
|
302
|
+
data: any[]
|
|
303
|
+
}>(
|
|
304
|
+
`users/${userId}/enrollments`,
|
|
305
|
+
'GET',
|
|
306
|
+
undefined,
|
|
307
|
+
contextUser
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
const courseProgressPromises = enrollmentsResponse.data.map(enrollment =>
|
|
311
|
+
this.getCourseProgress(
|
|
312
|
+
userId,
|
|
313
|
+
enrollment.course_id || enrollment.course?.id,
|
|
314
|
+
includeUnits,
|
|
315
|
+
includeLessons,
|
|
316
|
+
contextUser
|
|
317
|
+
).catch(() => null) // Handle individual course failures gracefully
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const courseProgressResults = await Promise.all(courseProgressPromises);
|
|
321
|
+
const validCourses = courseProgressResults.filter(p => p !== null) as CourseProgress[];
|
|
322
|
+
|
|
323
|
+
// Calculate aggregated metrics
|
|
324
|
+
const completed = validCourses.filter(c => c.status === 'completed').length;
|
|
325
|
+
const inProgress = validCourses.filter(c => c.status === 'in_progress').length;
|
|
326
|
+
const notStarted = validCourses.filter(c => c.status === 'not_started').length;
|
|
327
|
+
const totalTime = validCourses.reduce((sum, c) => sum + c.totalTimeSpent, 0);
|
|
328
|
+
const totalCerts = validCourses.filter(c => c.certificateEarned).length;
|
|
329
|
+
|
|
330
|
+
// Calculate overall progress
|
|
331
|
+
let overallProgress = 0;
|
|
332
|
+
if (validCourses.length > 0) {
|
|
333
|
+
const totalProgress = validCourses.reduce((sum, c) => sum + c.progressPercentage, 0);
|
|
334
|
+
overallProgress = Math.round(totalProgress / validCourses.length);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Calculate average quiz score if available
|
|
338
|
+
const coursesWithQuizzes = validCourses.filter(c => c.quizScoreAverage !== undefined);
|
|
339
|
+
const avgQuizScore = coursesWithQuizzes.length > 0 ?
|
|
340
|
+
coursesWithQuizzes.reduce((sum, c) => sum + (c.quizScoreAverage || 0), 0) / coursesWithQuizzes.length :
|
|
341
|
+
undefined;
|
|
342
|
+
|
|
343
|
+
return {
|
|
344
|
+
userId,
|
|
345
|
+
userEmail: '',
|
|
346
|
+
totalCourses: validCourses.length,
|
|
347
|
+
coursesCompleted: completed,
|
|
348
|
+
coursesInProgress: inProgress,
|
|
349
|
+
coursesNotStarted: notStarted,
|
|
350
|
+
overallProgressPercentage: overallProgress,
|
|
351
|
+
totalTimeSpent: totalTime,
|
|
352
|
+
totalCertificatesEarned: totalCerts,
|
|
353
|
+
averageQuizScore: avgQuizScore,
|
|
354
|
+
courses: validCourses
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Map course progress data
|
|
360
|
+
*/
|
|
361
|
+
private mapCourseProgress(data: any): CourseProgress {
|
|
362
|
+
const progress = this.calculateProgress(data.progress || data);
|
|
363
|
+
const status = this.determineCourseStatus(data);
|
|
364
|
+
|
|
365
|
+
return {
|
|
366
|
+
courseId: data.course_id || data.course?.id,
|
|
367
|
+
courseTitle: data.course_title || data.course?.title || 'Unknown Course',
|
|
368
|
+
enrollmentId: data.enrollment_id || data.id,
|
|
369
|
+
enrolledAt: this.parseLearnWorldsDate(data.enrolled_at || data.created),
|
|
370
|
+
lastAccessedAt: data.last_accessed_at ? this.parseLearnWorldsDate(data.last_accessed_at) : undefined,
|
|
371
|
+
|
|
372
|
+
progressPercentage: progress.percentage,
|
|
373
|
+
completedUnits: progress.completedUnits,
|
|
374
|
+
totalUnits: progress.totalUnits,
|
|
375
|
+
completedLessons: data.completed_lessons || 0,
|
|
376
|
+
totalLessons: data.total_lessons || 0,
|
|
377
|
+
|
|
378
|
+
totalTimeSpent: progress.timeSpent,
|
|
379
|
+
averageSessionTime: data.average_session_time || 0,
|
|
380
|
+
estimatedTimeToComplete: this.calculateEstimatedTimeToComplete(data),
|
|
381
|
+
|
|
382
|
+
quizScoreAverage: data.quiz_score_average,
|
|
383
|
+
assignmentsCompleted: data.assignments_completed,
|
|
384
|
+
assignmentsTotal: data.assignments_total,
|
|
385
|
+
currentGrade: data.current_grade || data.grade,
|
|
386
|
+
|
|
387
|
+
status,
|
|
388
|
+
completedAt: data.completed_at ? this.parseLearnWorldsDate(data.completed_at) : undefined,
|
|
389
|
+
expiresAt: data.expires_at ? this.parseLearnWorldsDate(data.expires_at) : undefined,
|
|
390
|
+
certificateEarned: data.certificate_earned || false,
|
|
391
|
+
certificateUrl: data.certificate_url
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Map unit progress data
|
|
397
|
+
*/
|
|
398
|
+
private async mapUnitProgress(
|
|
399
|
+
unitData: any,
|
|
400
|
+
userId: string,
|
|
401
|
+
courseId: string,
|
|
402
|
+
includeLessons: boolean,
|
|
403
|
+
contextUser: any
|
|
404
|
+
): Promise<UnitProgress> {
|
|
405
|
+
const unitProgress: UnitProgress = {
|
|
406
|
+
unitId: unitData.id || unitData.unit_id,
|
|
407
|
+
unitTitle: unitData.title || unitData.name,
|
|
408
|
+
unitType: unitData.type || 'section',
|
|
409
|
+
order: unitData.order || unitData.position || 0,
|
|
410
|
+
|
|
411
|
+
progressPercentage: unitData.progress_percentage || 0,
|
|
412
|
+
completedLessons: unitData.completed_lessons || 0,
|
|
413
|
+
totalLessons: unitData.total_lessons || 0,
|
|
414
|
+
timeSpent: unitData.time_spent || 0,
|
|
415
|
+
|
|
416
|
+
status: this.determineUnitStatus(unitData),
|
|
417
|
+
startedAt: unitData.started_at ? this.parseLearnWorldsDate(unitData.started_at) : undefined,
|
|
418
|
+
completedAt: unitData.completed_at ? this.parseLearnWorldsDate(unitData.completed_at) : undefined
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// Get lesson details if requested
|
|
422
|
+
if (includeLessons && unitData.lessons) {
|
|
423
|
+
unitProgress.lessons = unitData.lessons.map((lesson: any) => this.mapLessonProgress(lesson));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return unitProgress;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Map lesson progress data
|
|
431
|
+
*/
|
|
432
|
+
private mapLessonProgress(lessonData: any): LessonProgress {
|
|
433
|
+
return {
|
|
434
|
+
lessonId: lessonData.id || lessonData.lesson_id,
|
|
435
|
+
lessonTitle: lessonData.title || lessonData.name,
|
|
436
|
+
lessonType: this.mapLessonType(lessonData.type),
|
|
437
|
+
order: lessonData.order || lessonData.position || 0,
|
|
438
|
+
|
|
439
|
+
completed: lessonData.completed || false,
|
|
440
|
+
progressPercentage: lessonData.progress_percentage || (lessonData.completed ? 100 : 0),
|
|
441
|
+
timeSpent: lessonData.time_spent || 0,
|
|
442
|
+
|
|
443
|
+
startedAt: lessonData.started_at ? this.parseLearnWorldsDate(lessonData.started_at) : undefined,
|
|
444
|
+
completedAt: lessonData.completed_at ? this.parseLearnWorldsDate(lessonData.completed_at) : undefined,
|
|
445
|
+
lastAccessedAt: lessonData.last_accessed_at ? this.parseLearnWorldsDate(lessonData.last_accessed_at) : undefined,
|
|
446
|
+
|
|
447
|
+
videoWatchTime: lessonData.video_watch_time,
|
|
448
|
+
videoTotalTime: lessonData.video_total_time,
|
|
449
|
+
quizScore: lessonData.quiz_score,
|
|
450
|
+
quizMaxScore: lessonData.quiz_max_score,
|
|
451
|
+
quizAttempts: lessonData.quiz_attempts,
|
|
452
|
+
assignmentSubmitted: lessonData.assignment_submitted,
|
|
453
|
+
assignmentGrade: lessonData.assignment_grade
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Determine course status from data
|
|
459
|
+
*/
|
|
460
|
+
private determineCourseStatus(data: any): 'not_started' | 'in_progress' | 'completed' | 'expired' {
|
|
461
|
+
if (data.expired || (data.expires_at && new Date(data.expires_at) < new Date())) {
|
|
462
|
+
return 'expired';
|
|
463
|
+
}
|
|
464
|
+
if (data.completed || data.progress_percentage === 100) {
|
|
465
|
+
return 'completed';
|
|
466
|
+
}
|
|
467
|
+
if (data.progress_percentage > 0 || data.started) {
|
|
468
|
+
return 'in_progress';
|
|
469
|
+
}
|
|
470
|
+
return 'not_started';
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Determine unit status
|
|
475
|
+
*/
|
|
476
|
+
private determineUnitStatus(data: any): 'not_started' | 'in_progress' | 'completed' {
|
|
477
|
+
if (data.completed || data.progress_percentage === 100) {
|
|
478
|
+
return 'completed';
|
|
479
|
+
}
|
|
480
|
+
if (data.progress_percentage > 0 || data.started) {
|
|
481
|
+
return 'in_progress';
|
|
482
|
+
}
|
|
483
|
+
return 'not_started';
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Map lesson type
|
|
488
|
+
*/
|
|
489
|
+
private mapLessonType(type: string): 'video' | 'text' | 'quiz' | 'assignment' | 'scorm' | 'interactive' {
|
|
490
|
+
const typeMap: Record<string, 'video' | 'text' | 'quiz' | 'assignment' | 'scorm' | 'interactive'> = {
|
|
491
|
+
'video': 'video',
|
|
492
|
+
'text': 'text',
|
|
493
|
+
'quiz': 'quiz',
|
|
494
|
+
'exam': 'quiz',
|
|
495
|
+
'assignment': 'assignment',
|
|
496
|
+
'scorm': 'scorm',
|
|
497
|
+
'interactive': 'interactive',
|
|
498
|
+
'multimedia': 'interactive'
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
return typeMap[type?.toLowerCase()] || 'text';
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Calculate estimated time to complete
|
|
506
|
+
*/
|
|
507
|
+
private calculateEstimatedTimeToComplete(data: any): number | undefined {
|
|
508
|
+
if (data.estimated_time_to_complete) {
|
|
509
|
+
return data.estimated_time_to_complete;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Estimate based on progress
|
|
513
|
+
if (data.total_time_spent && data.progress_percentage > 0 && data.progress_percentage < 100) {
|
|
514
|
+
const timePerPercent = data.total_time_spent / data.progress_percentage;
|
|
515
|
+
const remainingPercent = 100 - data.progress_percentage;
|
|
516
|
+
return Math.round(timePerPercent * remainingPercent);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return undefined;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Calculate learning analytics
|
|
524
|
+
*/
|
|
525
|
+
private calculateLearningAnalytics(progress: UserLearningProgress): void {
|
|
526
|
+
if (progress.courses.length === 0) return;
|
|
527
|
+
|
|
528
|
+
// Find last learning date
|
|
529
|
+
const lastDates = progress.courses
|
|
530
|
+
.map(c => c.lastAccessedAt)
|
|
531
|
+
.filter(d => d !== undefined) as Date[];
|
|
532
|
+
|
|
533
|
+
if (lastDates.length > 0) {
|
|
534
|
+
progress.lastLearningDate = new Date(Math.max(...lastDates.map(d => d.getTime())));
|
|
535
|
+
|
|
536
|
+
// Calculate learning streak (simplified - days since last activity)
|
|
537
|
+
const daysSinceLastActivity = Math.floor(
|
|
538
|
+
(new Date().getTime() - progress.lastLearningDate.getTime()) / (1000 * 60 * 60 * 24)
|
|
539
|
+
);
|
|
540
|
+
progress.learningStreak = daysSinceLastActivity <= 1 ? 1 : 0;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Create progress summary
|
|
546
|
+
*/
|
|
547
|
+
private createProgressSummary(progress: UserLearningProgress): any {
|
|
548
|
+
const activeCourses = progress.courses.filter(c => c.status === 'in_progress');
|
|
549
|
+
const recentActivity = progress.courses
|
|
550
|
+
.filter(c => c.lastAccessedAt)
|
|
551
|
+
.sort((a, b) => (b.lastAccessedAt?.getTime() || 0) - (a.lastAccessedAt?.getTime() || 0))
|
|
552
|
+
.slice(0, 5);
|
|
553
|
+
|
|
554
|
+
return {
|
|
555
|
+
overview: {
|
|
556
|
+
totalCourses: progress.totalCourses,
|
|
557
|
+
completedCourses: progress.coursesCompleted,
|
|
558
|
+
inProgressCourses: progress.coursesInProgress,
|
|
559
|
+
notStartedCourses: progress.coursesNotStarted,
|
|
560
|
+
overallProgress: `${progress.overallProgressPercentage}%`,
|
|
561
|
+
certificatesEarned: progress.totalCertificatesEarned,
|
|
562
|
+
totalLearningTime: this.formatDuration(progress.totalTimeSpent)
|
|
563
|
+
},
|
|
564
|
+
performance: {
|
|
565
|
+
averageQuizScore: progress.averageQuizScore ? `${Math.round(progress.averageQuizScore)}%` : 'N/A',
|
|
566
|
+
averageCourseProgress: `${progress.overallProgressPercentage}%`,
|
|
567
|
+
completionRate: progress.totalCourses > 0 ?
|
|
568
|
+
`${Math.round((progress.coursesCompleted / progress.totalCourses) * 100)}%` : '0%'
|
|
569
|
+
},
|
|
570
|
+
currentFocus: activeCourses.map(c => ({
|
|
571
|
+
courseTitle: c.courseTitle,
|
|
572
|
+
progress: `${c.progressPercentage}%`,
|
|
573
|
+
timeSpent: this.formatDuration(c.totalTimeSpent),
|
|
574
|
+
estimatedTimeToComplete: c.estimatedTimeToComplete ?
|
|
575
|
+
this.formatDuration(c.estimatedTimeToComplete) : 'N/A'
|
|
576
|
+
})),
|
|
577
|
+
recentActivity: recentActivity.map(c => ({
|
|
578
|
+
courseTitle: c.courseTitle,
|
|
579
|
+
lastAccessed: c.lastAccessedAt,
|
|
580
|
+
progress: `${c.progressPercentage}%`
|
|
581
|
+
})),
|
|
582
|
+
achievements: {
|
|
583
|
+
totalCertificates: progress.totalCertificatesEarned,
|
|
584
|
+
coursesWithCertificates: progress.courses
|
|
585
|
+
.filter(c => c.certificateEarned)
|
|
586
|
+
.map(c => ({
|
|
587
|
+
courseTitle: c.courseTitle,
|
|
588
|
+
completedAt: c.completedAt
|
|
589
|
+
}))
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Define the parameters for this action
|
|
596
|
+
*/
|
|
597
|
+
public get Params(): ActionParam[] {
|
|
598
|
+
const baseParams = this.getCommonLMSParams();
|
|
599
|
+
|
|
600
|
+
const specificParams: ActionParam[] = [
|
|
601
|
+
{
|
|
602
|
+
Name: 'UserID',
|
|
603
|
+
Type: 'Input',
|
|
604
|
+
Value: null
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
Name: 'CourseID',
|
|
608
|
+
Type: 'Input',
|
|
609
|
+
Value: null
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
Name: 'IncludeUnitDetails',
|
|
613
|
+
Type: 'Input',
|
|
614
|
+
Value: false
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
Name: 'IncludeLessonDetails',
|
|
618
|
+
Type: 'Input',
|
|
619
|
+
Value: false
|
|
620
|
+
}
|
|
621
|
+
];
|
|
622
|
+
|
|
623
|
+
return [...baseParams, ...specificParams];
|
|
624
|
+
}
|
|
625
|
+
}
|