Merge pull request #2895 from dpalou/MOBILE-3800

MOBILE-3800 h5pactivity: Log event when viewing H5P report
main
Pau Ferrer Ocaña 2021-07-29 09:41:11 +02:00 committed by GitHub
commit e30f72e6ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 2 deletions

View File

@ -56,6 +56,8 @@ export class AddonModH5PActivityAttemptResultsPage implements OnInit {
try {
await this.fetchData();
await AddonModH5PActivity.logViewReport(this.h5pActivity!.id, this.h5pActivity!.name, { attemptId: this.attemptId });
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'Error loading attempt.');
} finally {

View File

@ -58,6 +58,8 @@ export class AddonModH5PActivityUserAttemptsPage implements OnInit {
try {
await this.fetchData();
await AddonModH5PActivity.logViewReport(this.h5pActivity!.id, this.h5pActivity!.name, { userId: this.userId });
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'Error loading attempts.');
} finally {

View File

@ -580,7 +580,7 @@ export class AddonModH5PActivityProvider {
* @return Promise resolved when the WS call is successful.
*/
logView(id: number, name?: string, siteId?: string): Promise<void> {
const params: AddonModH5pactivityViewH5pactivityWSParams = {
const params: AddonModH5PActivityViewH5pactivityWSParams = {
h5pactivityid: id,
};
@ -596,6 +596,40 @@ export class AddonModH5PActivityProvider {
);
}
/**
* Report an H5P activity report as being viewed.
*
* @param id H5P activity ID.
* @param name Name of the activity.
* @param options Options.
* @return Promise resolved when the WS call is successful.
*/
async logViewReport(id: number, name?: string, options: AddonModH5PActivityViewReportOptions = {}): Promise<void> {
const site = await CoreSites.getSite(options.siteId);
if (!site.wsAvailable('mod_h5pactivity_log_report_viewed')) {
// Site doesn't support the WS, stop.
return;
}
const params: AddonModH5PActivityLogReportViewedWSParams = {
h5pactivityid: id,
userid: options.userId,
attemptid: options.attemptId,
};
return CoreCourseLogHelper.logSingle(
'mod_h5pactivity_log_report_viewed',
params,
AddonModH5PActivityProvider.COMPONENT,
id,
name,
'h5pactivity',
{},
site.getId(),
);
}
}
export const AddonModH5PActivity = makeSingleton(AddonModH5PActivityProvider);
@ -840,10 +874,28 @@ export type AddonModH5PActivityGetAttemptsOptions = AddonModH5PActivityGetAttemp
/**
* Params of mod_h5pactivity_view_h5pactivity WS.
*/
export type AddonModH5pactivityViewH5pactivityWSParams = {
export type AddonModH5PActivityViewH5pactivityWSParams = {
h5pactivityid: number; // H5P activity instance id.
};
/**
* Params of mod_h5pactivity_log_report_viewed WS.
*/
export type AddonModH5PActivityLogReportViewedWSParams = {
h5pactivityid: number; // H5P activity instance id.
userid?: number | null; // The user id to log attempt (null means only current user).
attemptid?: number | null; // The attempt id.
};
/**
* Options for logViewReport.
*/
export type AddonModH5PActivityViewReportOptions = {
userId?: number; // User ID being viewed. Undefined for current user or when viewing an attempt.
attemptId?: number; // Attempt ID being viewed. Undefined if no attempt.
siteId?: string; // Site ID. If not defined, current site.
};
declare module '@singletons/events' {
/**