Merge pull request #3412 from dpalou/MOBILE-4153

MOBILE-4153 scorm: Support links to player.php
main
Pau Ferrer Ocaña 2022-10-20 10:59:22 +02:00 committed by GitHub
commit 6e23451b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 137 additions and 13 deletions

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { CoreConstants } from '@/core/constants';
import { Component, OnInit, Optional } from '@angular/core';
import { Component, Input, OnInit, Optional } from '@angular/core';
import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component';
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
import { CoreCourse } from '@features/course/services/course';
@ -53,6 +53,8 @@ import {
})
export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityComponent implements OnInit {
@Input() autoPlayData?: AddonModScormAutoPlayData; // Data to use to play the SCORM automatically.
component = AddonModScormProvider.COMPONENT;
moduleName = 'scorm';
@ -189,11 +191,16 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom
// Check whether to launch the SCORM immediately.
if (this.skip === undefined) {
this.skip = !this.hasOffline && !this.errorMessage &&
(!this.scorm.lastattemptlock || this.attemptsLeft > 0) &&
this.accessInfo.canskipview && !this.accessInfo.canviewreport &&
this.scorm.skipview! >= AddonModScormProvider.SKIPVIEW_FIRST &&
(this.scorm.skipview == AddonModScormProvider.SKIPVIEW_ALWAYS || this.lastAttempt == 0);
this.skip = !this.hasOffline && !this.errorMessage && (!this.scorm.lastattemptlock || this.attemptsLeft > 0) &&
(
!!this.autoPlayData
||
(
this.accessInfo.canskipview && !this.accessInfo.canviewreport &&
(this.scorm.skipview ?? 0) >= AddonModScormProvider.SKIPVIEW_FIRST &&
(this.scorm.skipview == AddonModScormProvider.SKIPVIEW_ALWAYS || this.lastAttempt == 0)
)
);
}
}
@ -533,7 +540,9 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom
* @param scoId SCO ID.
*/
protected openScorm(scoId?: number, preview: boolean = false): void {
// Display the full page when returning to the page.
const autoPlayData = this.autoPlayData;
this.autoPlayData = undefined;
this.skip = false;
this.hasPlayed = true;
@ -555,11 +564,11 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom
`${AddonModScormModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/player`,
{
params: {
mode: preview ? AddonModScormProvider.MODEBROWSE : AddonModScormProvider.MODENORMAL,
mode: autoPlayData?.mode ?? (preview ? AddonModScormProvider.MODEBROWSE : AddonModScormProvider.MODENORMAL),
moduleUrl: this.module.url,
newAttempt: !!this.startNewAttempt,
organizationId: this.currentOrganization.identifier,
scoId: scoId,
newAttempt: autoPlayData?.newAttempt ?? this.startNewAttempt,
organizationId: autoPlayData?.organizationId ?? this.currentOrganization.identifier,
scoId: autoPlayData?.scoId ?? scoId,
},
},
);
@ -621,3 +630,13 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom
export type AttemptGrade = AddonModScormAttemptGrade & {
gradeFormatted?: string;
};
/**
* Data to use to auto-play the SCORM.
*/
export type AddonModScormAutoPlayData = {
mode?: string;
newAttempt?: boolean;
organizationId?: string;
scoId?: number;
};

View File

@ -19,6 +19,6 @@
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<addon-mod-scorm-index [module]="module" [courseId]="courseId" (dataRetrieved)="updateData($event)">
<addon-mod-scorm-index [module]="module" [courseId]="courseId" [autoPlayData]="autoPlayData" (dataRetrieved)="updateData($event)">
</addon-mod-scorm-index>
</ion-content>

View File

@ -14,7 +14,8 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { CoreCourseModuleMainActivityPage } from '@features/course/classes/main-activity-page';
import { AddonModScormIndexComponent } from '../../components/index/index';
import { CoreNavigator } from '@services/navigator';
import { AddonModScormAutoPlayData, AddonModScormIndexComponent } from '../../components/index/index';
/**
* Page that displays the scorm entry page.
@ -27,4 +28,22 @@ export class AddonModScormIndexPage extends CoreCourseModuleMainActivityPage<Add
@ViewChild(AddonModScormIndexComponent) activityComponent?: AddonModScormIndexComponent;
autoPlayData?: AddonModScormAutoPlayData; // Data to auto-play the SCORM.
/**
* @inheritdoc
*/
ngOnInit(): void {
super.ngOnInit();
if (CoreNavigator.getRouteBooleanParam('autoPlay')) {
this.autoPlayData = {
mode: CoreNavigator.getRouteParam('mode'),
newAttempt: CoreNavigator.getRouteBooleanParam('newAttempt'),
organizationId: CoreNavigator.getRouteParam('organizationId'),
scoId: CoreNavigator.getRouteNumberParam('scoId'),
};
}
}
}

View File

@ -27,6 +27,7 @@ import { AddonModScormGradeLinkHandler } from './services/handlers/grade-link';
import { AddonModScormIndexLinkHandler } from './services/handlers/index-link';
import { AddonModScormListLinkHandler } from './services/handlers/list-link';
import { AddonModScormModuleHandler, AddonModScormModuleHandlerService } from './services/handlers/module';
import { AddonModScormPlayerLinkHandler } from './services/handlers/player-link';
import { AddonModScormPluginFileHandler } from './services/handlers/pluginfile';
import { AddonModScormPrefetchHandler } from './services/handlers/prefetch';
import { AddonModScormSyncCronHandler } from './services/handlers/sync-cron';
@ -70,6 +71,7 @@ const routes: Routes = [
CoreContentLinksDelegate.registerHandler(AddonModScormGradeLinkHandler.instance);
CoreContentLinksDelegate.registerHandler(AddonModScormIndexLinkHandler.instance);
CoreContentLinksDelegate.registerHandler(AddonModScormListLinkHandler.instance);
CoreContentLinksDelegate.registerHandler(AddonModScormPlayerLinkHandler.instance);
CorePluginFileDelegate.registerHandler(AddonModScormPluginFileHandler.instance);
},
},

View File

@ -0,0 +1,84 @@
// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { CoreCourseHelper } from '@features/course/services/course-helper';
import { CoreNavigationOptions } from '@services/navigator';
import { makeSingleton } from '@singletons';
/**
* Handler to treat links to SCORM player.
*/
@Injectable({ providedIn: 'root' })
export class AddonModScormPlayerLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonModScormPlayerLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModScorm';
pattern = /\/mod\/scorm\/player\.php.*([?&](id|a)=\d+)/;
/**
* @inheritdoc
*/
getActions(siteIds: string[], url: string, params: Record<string, string>, courseId?: number): CoreContentLinksAction[] {
return [{
action: async (siteId) => {
const cmId = Number(params.id);
const instanceId = Number(params.a);
courseId = Number(courseId || params.courseid || params.cid);
if (!cmId && !instanceId) {
// Shouldn't happen, the regex should handle this.
return;
}
const navOptions: CoreNavigationOptions = {
params: {
autoPlay: true,
mode: params.mode || undefined,
newAttempt: params.newattempt === 'on',
organizationId: params.currentorg,
scoId: Number(params.scoid) || undefined,
},
};
if (cmId) {
CoreCourseHelper.navigateToModule(
cmId,
{
courseId,
modNavOptions: navOptions,
siteId,
},
);
} else {
CoreCourseHelper.navigateToModuleByInstance(
instanceId,
'scorm',
{
courseId,
modNavOptions: navOptions,
siteId,
},
);
}
},
}];
}
}
export const AddonModScormPlayerLinkHandler = makeSingleton(AddonModScormPlayerLinkHandlerService);