@memberjunction/actions-bizapps-lms 2.55.0 → 2.57.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 +1 -1
- package/CHANGELOG.md +26 -0
- package/README.md +321 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/create-user.action.js +243 -0
- package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.js +208 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.js +301 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +36 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js +333 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +28 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.js +237 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +28 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js +368 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +228 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/index.d.ts +8 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/index.js +8 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.js +254 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -0
- package/package.json +6 -6
- package/src/providers/learnworlds/actions/create-user.action.ts +249 -0
- package/src/providers/learnworlds/actions/enroll-user.action.ts +233 -0
- package/src/providers/learnworlds/actions/get-certificates.action.ts +332 -0
- package/src/providers/learnworlds/actions/get-course-analytics.action.ts +359 -0
- package/src/providers/learnworlds/actions/get-course-details.action.ts +267 -0
- package/src/providers/learnworlds/actions/get-quiz-results.action.ts +399 -0
- package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +242 -0
- package/src/providers/learnworlds/actions/index.ts +9 -1
- package/src/providers/learnworlds/actions/update-user-progress.action.ts +277 -0
|
@@ -0,0 +1,399 @@
|
|
|
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
|
+
* Action to retrieve quiz/assessment results from LearnWorlds
|
|
7
|
+
*/
|
|
8
|
+
@RegisterClass(LearnWorldsBaseAction, 'GetQuizResultsAction')
|
|
9
|
+
export class GetQuizResultsAction extends LearnWorldsBaseAction {
|
|
10
|
+
/**
|
|
11
|
+
* Get quiz results for a user, course, or specific quiz
|
|
12
|
+
*/
|
|
13
|
+
public async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
14
|
+
const { Params, ContextUser } = params;
|
|
15
|
+
this.params = Params;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Extract and validate parameters
|
|
19
|
+
const userId = this.getParamValue(Params, 'UserID');
|
|
20
|
+
const courseId = this.getParamValue(Params, 'CourseID');
|
|
21
|
+
const quizId = this.getParamValue(Params, 'QuizID');
|
|
22
|
+
const includeQuestions = this.getParamValue(Params, 'IncludeQuestions') !== false;
|
|
23
|
+
const includeAnswers = this.getParamValue(Params, 'IncludeAnswers') !== false;
|
|
24
|
+
const passingOnly = this.getParamValue(Params, 'PassingOnly') === true;
|
|
25
|
+
const dateFrom = this.getParamValue(Params, 'DateFrom');
|
|
26
|
+
const dateTo = this.getParamValue(Params, 'DateTo');
|
|
27
|
+
const sortBy = this.getParamValue(Params, 'SortBy') || 'completed_at';
|
|
28
|
+
const sortOrder = this.getParamValue(Params, 'SortOrder') || 'desc';
|
|
29
|
+
const maxResults = this.getParamValue(Params, 'MaxResults') || 100;
|
|
30
|
+
|
|
31
|
+
// Require at least one identifier
|
|
32
|
+
if (!userId && !courseId && !quizId) {
|
|
33
|
+
return {
|
|
34
|
+
Success: false,
|
|
35
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
36
|
+
Message: 'At least one of UserID, CourseID, or QuizID is required',
|
|
37
|
+
Params
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// Build query parameters
|
|
43
|
+
const queryParams: any = {
|
|
44
|
+
limit: Math.min(maxResults, 100),
|
|
45
|
+
sort: sortBy,
|
|
46
|
+
order: sortOrder
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (passingOnly) {
|
|
50
|
+
queryParams.passed = true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (dateFrom) {
|
|
54
|
+
queryParams.completed_after = new Date(dateFrom).toISOString();
|
|
55
|
+
}
|
|
56
|
+
if (dateTo) {
|
|
57
|
+
queryParams.completed_before = new Date(dateTo).toISOString();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Determine endpoint based on parameters
|
|
61
|
+
let endpoint = '/quiz-results';
|
|
62
|
+
if (quizId) {
|
|
63
|
+
endpoint = `/quizzes/${quizId}/results`;
|
|
64
|
+
if (userId) {
|
|
65
|
+
queryParams.user_id = userId;
|
|
66
|
+
}
|
|
67
|
+
} else if (userId && courseId) {
|
|
68
|
+
endpoint = `/users/${userId}/courses/${courseId}/quiz-results`;
|
|
69
|
+
} else if (userId) {
|
|
70
|
+
endpoint = `/users/${userId}/quiz-results`;
|
|
71
|
+
} else if (courseId) {
|
|
72
|
+
endpoint = `/courses/${courseId}/quiz-results`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Build query string
|
|
76
|
+
const queryString = Object.keys(queryParams).length > 0
|
|
77
|
+
? '?' + new URLSearchParams(queryParams).toString()
|
|
78
|
+
: '';
|
|
79
|
+
|
|
80
|
+
// Get quiz results
|
|
81
|
+
const resultsResponse = await this.makeLearnWorldsRequest(
|
|
82
|
+
endpoint + queryString,
|
|
83
|
+
'GET',
|
|
84
|
+
null,
|
|
85
|
+
ContextUser
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (!resultsResponse.success) {
|
|
89
|
+
return {
|
|
90
|
+
Success: false,
|
|
91
|
+
ResultCode: 'API_ERROR',
|
|
92
|
+
Message: resultsResponse.message || 'Failed to retrieve quiz results',
|
|
93
|
+
Params
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const results = resultsResponse.data?.data || resultsResponse.data || [];
|
|
98
|
+
const formattedResults: any[] = [];
|
|
99
|
+
|
|
100
|
+
// Process each quiz result
|
|
101
|
+
for (const result of results) {
|
|
102
|
+
const formattedResult: any = {
|
|
103
|
+
id: result.id || result.result_id,
|
|
104
|
+
userId: result.user_id || userId,
|
|
105
|
+
courseId: result.course_id || courseId,
|
|
106
|
+
quizId: result.quiz_id || quizId,
|
|
107
|
+
attemptNumber: result.attempt_number || result.attempt || 1,
|
|
108
|
+
score: result.score || 0,
|
|
109
|
+
maxScore: result.max_score || result.total_points || 100,
|
|
110
|
+
percentage: result.percentage || ((result.score / (result.max_score || 100)) * 100),
|
|
111
|
+
passed: result.passed || result.is_passing || false,
|
|
112
|
+
passingScore: result.passing_score || result.passing_percentage || 70,
|
|
113
|
+
startedAt: result.started_at,
|
|
114
|
+
completedAt: result.completed_at || result.submitted_at,
|
|
115
|
+
duration: result.duration || result.time_spent,
|
|
116
|
+
durationText: this.formatDuration(result.duration || result.time_spent || 0)
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Add user info if available
|
|
120
|
+
if (result.user && !formattedResult.user) {
|
|
121
|
+
formattedResult.user = {
|
|
122
|
+
id: result.user.id,
|
|
123
|
+
email: result.user.email,
|
|
124
|
+
name: result.user.name || `${result.user.first_name || ''} ${result.user.last_name || ''}`.trim()
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Add quiz info if available
|
|
129
|
+
if (result.quiz) {
|
|
130
|
+
formattedResult.quiz = {
|
|
131
|
+
id: result.quiz.id,
|
|
132
|
+
title: result.quiz.title || result.quiz.name,
|
|
133
|
+
type: result.quiz.type || 'quiz',
|
|
134
|
+
questionCount: result.quiz.question_count || result.quiz.total_questions
|
|
135
|
+
};
|
|
136
|
+
} else if (!quizId && result.quiz_id) {
|
|
137
|
+
// Try to get quiz info
|
|
138
|
+
const quizResponse = await this.makeLearnWorldsRequest(
|
|
139
|
+
`/quizzes/${result.quiz_id}`,
|
|
140
|
+
'GET',
|
|
141
|
+
null,
|
|
142
|
+
ContextUser
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (quizResponse.success && quizResponse.data) {
|
|
146
|
+
const quiz = quizResponse.data;
|
|
147
|
+
formattedResult.quiz = {
|
|
148
|
+
id: quiz.id,
|
|
149
|
+
title: quiz.title || quiz.name,
|
|
150
|
+
type: quiz.type || 'quiz',
|
|
151
|
+
questionCount: quiz.question_count || quiz.total_questions
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Add questions and answers if requested
|
|
157
|
+
if (includeQuestions || includeAnswers) {
|
|
158
|
+
const detailsResponse = await this.makeLearnWorldsRequest(
|
|
159
|
+
`/quiz-results/${formattedResult.id}/details`,
|
|
160
|
+
'GET',
|
|
161
|
+
null,
|
|
162
|
+
ContextUser
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
if (detailsResponse.success && detailsResponse.data) {
|
|
166
|
+
const details = detailsResponse.data;
|
|
167
|
+
|
|
168
|
+
if (includeQuestions) {
|
|
169
|
+
formattedResult.questions = this.formatQuestions(details.questions || details.answers || []);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (includeAnswers) {
|
|
173
|
+
formattedResult.answers = this.formatAnswers(details.answers || details.questions || []);
|
|
174
|
+
|
|
175
|
+
// Calculate additional metrics
|
|
176
|
+
const answers = formattedResult.answers || [];
|
|
177
|
+
formattedResult.metrics = {
|
|
178
|
+
correctAnswers: answers.filter((a: any) => a.isCorrect).length,
|
|
179
|
+
incorrectAnswers: answers.filter((a: any) => !a.isCorrect).length,
|
|
180
|
+
totalQuestions: answers.length,
|
|
181
|
+
accuracyRate: answers.length > 0
|
|
182
|
+
? (answers.filter((a: any) => a.isCorrect).length / answers.length * 100).toFixed(1)
|
|
183
|
+
: 0
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
formattedResults.push(formattedResult);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Calculate summary statistics
|
|
193
|
+
const totalResults = formattedResults.length;
|
|
194
|
+
const passedResults = formattedResults.filter(r => r.passed).length;
|
|
195
|
+
const averageScore = totalResults > 0
|
|
196
|
+
? formattedResults.reduce((sum, r) => sum + r.percentage, 0) / totalResults
|
|
197
|
+
: 0;
|
|
198
|
+
const averageDuration = totalResults > 0
|
|
199
|
+
? formattedResults.reduce((sum, r) => sum + (r.duration || 0), 0) / totalResults
|
|
200
|
+
: 0;
|
|
201
|
+
|
|
202
|
+
// Group results by quiz if multiple quizzes
|
|
203
|
+
const resultsByQuiz: any = {};
|
|
204
|
+
if (!quizId) {
|
|
205
|
+
formattedResults.forEach(result => {
|
|
206
|
+
const quizTitle = result.quiz?.title || 'Unknown Quiz';
|
|
207
|
+
if (!resultsByQuiz[quizTitle]) {
|
|
208
|
+
resultsByQuiz[quizTitle] = {
|
|
209
|
+
results: [],
|
|
210
|
+
stats: {
|
|
211
|
+
attempts: 0,
|
|
212
|
+
averageScore: 0,
|
|
213
|
+
passRate: 0
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
resultsByQuiz[quizTitle].results.push(result);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// Calculate stats for each quiz
|
|
221
|
+
Object.keys(resultsByQuiz).forEach(quizTitle => {
|
|
222
|
+
const quizResults = resultsByQuiz[quizTitle].results;
|
|
223
|
+
resultsByQuiz[quizTitle].stats = {
|
|
224
|
+
attempts: quizResults.length,
|
|
225
|
+
averageScore: (quizResults.reduce((sum: number, r: any) => sum + r.percentage, 0) / quizResults.length).toFixed(1),
|
|
226
|
+
passRate: ((quizResults.filter((r: any) => r.passed).length / quizResults.length) * 100).toFixed(1)
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Create summary
|
|
232
|
+
const summary = {
|
|
233
|
+
totalResults: totalResults,
|
|
234
|
+
passedResults: passedResults,
|
|
235
|
+
failedResults: totalResults - passedResults,
|
|
236
|
+
passRate: totalResults > 0 ? ((passedResults / totalResults) * 100).toFixed(1) : 0,
|
|
237
|
+
averageScore: averageScore.toFixed(1),
|
|
238
|
+
averageDuration: averageDuration,
|
|
239
|
+
averageDurationText: this.formatDuration(Math.round(averageDuration)),
|
|
240
|
+
dateRange: {
|
|
241
|
+
from: dateFrom || 'all-time',
|
|
242
|
+
to: dateTo || 'current'
|
|
243
|
+
},
|
|
244
|
+
filterType: userId ? (courseId ? 'user-course' : 'user') : (courseId ? 'course' : 'all'),
|
|
245
|
+
quizBreakdown: !quizId ? resultsByQuiz : null
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// Update output parameters
|
|
249
|
+
const outputParams = [...Params];
|
|
250
|
+
const quizResultsParam = outputParams.find(p => p.Name === 'QuizResults');
|
|
251
|
+
if (quizResultsParam) {
|
|
252
|
+
quizResultsParam.Value = formattedResults;
|
|
253
|
+
}
|
|
254
|
+
const totalCountParam = outputParams.find(p => p.Name === 'TotalCount');
|
|
255
|
+
if (totalCountParam) {
|
|
256
|
+
totalCountParam.Value = totalResults;
|
|
257
|
+
}
|
|
258
|
+
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
259
|
+
if (summaryParam) {
|
|
260
|
+
summaryParam.Value = summary;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
Success: true,
|
|
265
|
+
ResultCode: 'SUCCESS',
|
|
266
|
+
Message: `Retrieved ${totalResults} quiz result(s)`,
|
|
267
|
+
Params: outputParams
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
} catch (error) {
|
|
271
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
272
|
+
return {
|
|
273
|
+
Success: false,
|
|
274
|
+
ResultCode: 'EXECUTION_ERROR',
|
|
275
|
+
Message: `Error retrieving quiz results: ${errorMessage}`,
|
|
276
|
+
Params
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Format quiz questions
|
|
283
|
+
*/
|
|
284
|
+
private formatQuestions(questions: any[]): any[] {
|
|
285
|
+
return questions.map((q, index) => ({
|
|
286
|
+
questionNumber: q.question_number || index + 1,
|
|
287
|
+
questionId: q.question_id || q.id,
|
|
288
|
+
questionText: q.question_text || q.question || q.text,
|
|
289
|
+
questionType: q.question_type || q.type || 'multiple-choice',
|
|
290
|
+
points: q.points || q.score || 1,
|
|
291
|
+
difficulty: q.difficulty || 'medium'
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Format user answers
|
|
297
|
+
*/
|
|
298
|
+
private formatAnswers(answers: any[]): any[] {
|
|
299
|
+
return answers.map((a, index) => ({
|
|
300
|
+
questionNumber: a.question_number || index + 1,
|
|
301
|
+
questionId: a.question_id,
|
|
302
|
+
userAnswer: a.user_answer || a.answer || a.selected_answer,
|
|
303
|
+
correctAnswer: a.correct_answer,
|
|
304
|
+
isCorrect: a.is_correct || a.correct || false,
|
|
305
|
+
pointsEarned: a.points_earned || (a.is_correct ? (a.points || 1) : 0),
|
|
306
|
+
pointsPossible: a.points_possible || a.points || 1,
|
|
307
|
+
feedback: a.feedback,
|
|
308
|
+
timeSpent: a.time_spent,
|
|
309
|
+
answeredAt: a.answered_at
|
|
310
|
+
}));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Define the parameters this action expects
|
|
315
|
+
*/
|
|
316
|
+
public get Params(): ActionParam[] {
|
|
317
|
+
const baseParams = this.getCommonLMSParams();
|
|
318
|
+
const specificParams: ActionParam[] = [
|
|
319
|
+
{
|
|
320
|
+
Name: 'UserID',
|
|
321
|
+
Type: 'Input',
|
|
322
|
+
Value: null
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
Name: 'CourseID',
|
|
326
|
+
Type: 'Input',
|
|
327
|
+
Value: null
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
Name: 'QuizID',
|
|
331
|
+
Type: 'Input',
|
|
332
|
+
Value: null
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
Name: 'IncludeQuestions',
|
|
336
|
+
Type: 'Input',
|
|
337
|
+
Value: true
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
Name: 'IncludeAnswers',
|
|
341
|
+
Type: 'Input',
|
|
342
|
+
Value: true
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
Name: 'PassingOnly',
|
|
346
|
+
Type: 'Input',
|
|
347
|
+
Value: false
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
Name: 'DateFrom',
|
|
351
|
+
Type: 'Input',
|
|
352
|
+
Value: null
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
Name: 'DateTo',
|
|
356
|
+
Type: 'Input',
|
|
357
|
+
Value: null
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
Name: 'SortBy',
|
|
361
|
+
Type: 'Input',
|
|
362
|
+
Value: 'completed_at'
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
Name: 'SortOrder',
|
|
366
|
+
Type: 'Input',
|
|
367
|
+
Value: 'desc'
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
Name: 'MaxResults',
|
|
371
|
+
Type: 'Input',
|
|
372
|
+
Value: 100
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
Name: 'QuizResults',
|
|
376
|
+
Type: 'Output',
|
|
377
|
+
Value: null
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
Name: 'TotalCount',
|
|
381
|
+
Type: 'Output',
|
|
382
|
+
Value: null
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
Name: 'Summary',
|
|
386
|
+
Type: 'Output',
|
|
387
|
+
Value: null
|
|
388
|
+
}
|
|
389
|
+
];
|
|
390
|
+
return [...baseParams, ...specificParams];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Metadata about this action
|
|
395
|
+
*/
|
|
396
|
+
public get Description(): string {
|
|
397
|
+
return 'Retrieves quiz and assessment results from LearnWorlds with detailed question/answer information';
|
|
398
|
+
}
|
|
399
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
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
|
+
* Action to retrieve all course enrollments for a specific user
|
|
7
|
+
*/
|
|
8
|
+
@RegisterClass(LearnWorldsBaseAction, 'GetUserEnrollmentsAction')
|
|
9
|
+
export class GetUserEnrollmentsAction extends LearnWorldsBaseAction {
|
|
10
|
+
/**
|
|
11
|
+
* Get all enrollments for a user
|
|
12
|
+
*/
|
|
13
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
14
|
+
const { Params, ContextUser } = params;
|
|
15
|
+
this.params = Params; // Set params for base class to use
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Extract and validate parameters
|
|
19
|
+
const userId = this.getParamValue(Params, 'UserID');
|
|
20
|
+
const status = this.getParamValue(Params, 'Status');
|
|
21
|
+
const includeExpired = this.getParamValue(Params, 'IncludeExpired') || false;
|
|
22
|
+
const includeCourseDetails = this.getParamValue(Params, 'IncludeCourseDetails') !== false;
|
|
23
|
+
const sortBy = this.getParamValue(Params, 'SortBy') || 'enrolled_at';
|
|
24
|
+
const sortOrder = this.getParamValue(Params, 'SortOrder') || 'desc';
|
|
25
|
+
const maxResults = this.getParamValue(Params, 'MaxResults') || 100;
|
|
26
|
+
|
|
27
|
+
if (!userId) {
|
|
28
|
+
return {
|
|
29
|
+
Success: false,
|
|
30
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
31
|
+
Message: 'UserID is required',
|
|
32
|
+
Params
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Build query parameters
|
|
37
|
+
const queryParams: any = {
|
|
38
|
+
limit: Math.min(maxResults, 100),
|
|
39
|
+
sort: sortBy,
|
|
40
|
+
order: sortOrder
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
if (status) {
|
|
44
|
+
queryParams.status = status;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!includeExpired) {
|
|
48
|
+
queryParams.hide_expired = true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Get user enrollments
|
|
52
|
+
const enrollmentsData = await this.makeLearnWorldsPaginatedRequest<any>(
|
|
53
|
+
`users/${userId}/enrollments`,
|
|
54
|
+
queryParams,
|
|
55
|
+
ContextUser
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const enrollments = enrollmentsData || [];
|
|
59
|
+
const formattedEnrollments: any[] = [];
|
|
60
|
+
|
|
61
|
+
// Process each enrollment
|
|
62
|
+
for (const enrollment of enrollments) {
|
|
63
|
+
const formattedEnrollment: any = {
|
|
64
|
+
id: enrollment.id,
|
|
65
|
+
courseId: enrollment.course_id,
|
|
66
|
+
enrolledAt: enrollment.enrolled_at || enrollment.created_at,
|
|
67
|
+
startsAt: enrollment.starts_at,
|
|
68
|
+
expiresAt: enrollment.expires_at,
|
|
69
|
+
status: enrollment.status || 'active',
|
|
70
|
+
progress: {
|
|
71
|
+
percentage: enrollment.progress_percentage || 0,
|
|
72
|
+
completedUnits: enrollment.completed_units || 0,
|
|
73
|
+
totalUnits: enrollment.total_units || 0,
|
|
74
|
+
completedLessons: enrollment.completed_lessons || 0,
|
|
75
|
+
totalLessons: enrollment.total_lessons || 0,
|
|
76
|
+
lastAccessedAt: enrollment.last_accessed_at,
|
|
77
|
+
totalTimeSpent: enrollment.total_time_spent || 0,
|
|
78
|
+
totalTimeSpentText: this.formatDuration(enrollment.total_time_spent || 0)
|
|
79
|
+
},
|
|
80
|
+
grade: enrollment.grade,
|
|
81
|
+
certificateEligible: enrollment.certificate_eligible || false,
|
|
82
|
+
certificateIssuedAt: enrollment.certificate_issued_at,
|
|
83
|
+
completedAt: enrollment.completed_at
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Get course details if requested
|
|
87
|
+
if (includeCourseDetails && enrollment.course_id) {
|
|
88
|
+
try {
|
|
89
|
+
const course = await this.makeLearnWorldsRequest<any>(
|
|
90
|
+
`courses/${enrollment.course_id}`,
|
|
91
|
+
'GET',
|
|
92
|
+
undefined,
|
|
93
|
+
ContextUser
|
|
94
|
+
);
|
|
95
|
+
formattedEnrollment.course = {
|
|
96
|
+
id: course.id,
|
|
97
|
+
title: course.title,
|
|
98
|
+
description: course.short_description || course.description,
|
|
99
|
+
imageUrl: course.image_url,
|
|
100
|
+
level: course.level,
|
|
101
|
+
duration: course.duration,
|
|
102
|
+
durationText: this.formatDuration(course.duration),
|
|
103
|
+
instructorName: course.instructor_name,
|
|
104
|
+
certificateEnabled: course.certificate_enabled || false
|
|
105
|
+
};
|
|
106
|
+
} catch (error) {
|
|
107
|
+
// Log error but continue processing
|
|
108
|
+
console.warn(`Failed to get course details for ${enrollment.course_id}:`, error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
formattedEnrollments.push(formattedEnrollment);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Calculate summary statistics
|
|
116
|
+
const totalEnrollments = formattedEnrollments.length;
|
|
117
|
+
const activeEnrollments = formattedEnrollments.filter(e => e.status === 'active').length;
|
|
118
|
+
const completedEnrollments = formattedEnrollments.filter(e =>
|
|
119
|
+
e.progress.percentage >= 100 || e.completedAt
|
|
120
|
+
).length;
|
|
121
|
+
const expiredEnrollments = formattedEnrollments.filter(e => e.status === 'expired').length;
|
|
122
|
+
const averageProgress = totalEnrollments > 0
|
|
123
|
+
? formattedEnrollments.reduce((sum, e) => sum + e.progress.percentage, 0) / totalEnrollments
|
|
124
|
+
: 0;
|
|
125
|
+
const totalTimeSpent = formattedEnrollments.reduce((sum, e) =>
|
|
126
|
+
sum + (e.progress.totalTimeSpent || 0), 0
|
|
127
|
+
);
|
|
128
|
+
const certificatesEarned = formattedEnrollments.filter(e => e.certificateIssuedAt).length;
|
|
129
|
+
|
|
130
|
+
// Create summary
|
|
131
|
+
const summary = {
|
|
132
|
+
userId: userId,
|
|
133
|
+
totalEnrollments: totalEnrollments,
|
|
134
|
+
activeEnrollments: activeEnrollments,
|
|
135
|
+
completedEnrollments: completedEnrollments,
|
|
136
|
+
expiredEnrollments: expiredEnrollments,
|
|
137
|
+
inProgressEnrollments: activeEnrollments - completedEnrollments,
|
|
138
|
+
averageProgressPercentage: Math.round(averageProgress * 100) / 100,
|
|
139
|
+
totalTimeSpent: totalTimeSpent,
|
|
140
|
+
totalTimeSpentText: this.formatDuration(totalTimeSpent),
|
|
141
|
+
certificatesEarned: certificatesEarned,
|
|
142
|
+
enrollmentsByStatus: {
|
|
143
|
+
active: activeEnrollments,
|
|
144
|
+
completed: completedEnrollments,
|
|
145
|
+
expired: expiredEnrollments
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// Update output parameters
|
|
150
|
+
const outputParams = [...Params];
|
|
151
|
+
const enrollmentsParam = outputParams.find(p => p.Name === 'Enrollments');
|
|
152
|
+
if (enrollmentsParam) enrollmentsParam.Value = formattedEnrollments;
|
|
153
|
+
const totalCountParam = outputParams.find(p => p.Name === 'TotalCount');
|
|
154
|
+
if (totalCountParam) totalCountParam.Value = totalEnrollments;
|
|
155
|
+
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
156
|
+
if (summaryParam) summaryParam.Value = summary;
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
Success: true,
|
|
160
|
+
ResultCode: 'SUCCESS',
|
|
161
|
+
Message: `Retrieved ${totalEnrollments} enrollments for user`,
|
|
162
|
+
Params: outputParams
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
} catch (error) {
|
|
166
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
167
|
+
return {
|
|
168
|
+
Success: false,
|
|
169
|
+
ResultCode: 'ERROR',
|
|
170
|
+
Message: `Error retrieving enrollments: ${errorMessage}`,
|
|
171
|
+
Params
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Define the parameters this action expects
|
|
178
|
+
*/
|
|
179
|
+
public get Params(): ActionParam[] {
|
|
180
|
+
const baseParams = this.getCommonLMSParams();
|
|
181
|
+
const specificParams: ActionParam[] = [
|
|
182
|
+
{
|
|
183
|
+
Name: 'UserID',
|
|
184
|
+
Type: 'Input',
|
|
185
|
+
Value: null
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
Name: 'Status',
|
|
189
|
+
Type: 'Input',
|
|
190
|
+
Value: null
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
Name: 'IncludeExpired',
|
|
194
|
+
Type: 'Input',
|
|
195
|
+
Value: false
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
Name: 'IncludeCourseDetails',
|
|
199
|
+
Type: 'Input',
|
|
200
|
+
Value: true
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
Name: 'SortBy',
|
|
204
|
+
Type: 'Input',
|
|
205
|
+
Value: 'enrolled_at'
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
Name: 'SortOrder',
|
|
209
|
+
Type: 'Input',
|
|
210
|
+
Value: 'desc'
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
Name: 'MaxResults',
|
|
214
|
+
Type: 'Input',
|
|
215
|
+
Value: 100
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
Name: 'Enrollments',
|
|
219
|
+
Type: 'Output',
|
|
220
|
+
Value: null
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
Name: 'TotalCount',
|
|
224
|
+
Type: 'Output',
|
|
225
|
+
Value: null
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
Name: 'Summary',
|
|
229
|
+
Type: 'Output',
|
|
230
|
+
Value: null
|
|
231
|
+
}
|
|
232
|
+
];
|
|
233
|
+
return [...baseParams, ...specificParams];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Metadata about this action
|
|
238
|
+
*/
|
|
239
|
+
public get Description(): string {
|
|
240
|
+
return 'Retrieves all course enrollments for a specific LearnWorlds user with detailed progress information';
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -2,4 +2,12 @@
|
|
|
2
2
|
export * from './get-users.action';
|
|
3
3
|
export * from './get-user-details.action';
|
|
4
4
|
export * from './get-user-progress.action';
|
|
5
|
-
export * from './get-courses.action';
|
|
5
|
+
export * from './get-courses.action';
|
|
6
|
+
export * from './get-course-details.action';
|
|
7
|
+
export * from './enroll-user.action';
|
|
8
|
+
export * from './get-user-enrollments.action';
|
|
9
|
+
export * from './get-course-analytics.action';
|
|
10
|
+
export * from './create-user.action';
|
|
11
|
+
export * from './update-user-progress.action';
|
|
12
|
+
export * from './get-certificates.action';
|
|
13
|
+
export * from './get-quiz-results.action';
|