MOBILE-3411 h5pactivity: Initial support of the activity
This commit is contained in:
		
							parent
							
								
									9b39fb9d8d
								
							
						
					
					
						commit
						6621fc54a4
					
				
							
								
								
									
										45
									
								
								src/addon/mod/h5pactivity/components/components.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/addon/mod/h5pactivity/components/components.module.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,45 @@ | ||||
| // (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 { NgModule } from '@angular/core'; | ||||
| import { CommonModule } from '@angular/common'; | ||||
| import { IonicModule } from 'ionic-angular'; | ||||
| import { TranslateModule } from '@ngx-translate/core'; | ||||
| import { CoreComponentsModule } from '@components/components.module'; | ||||
| import { CoreDirectivesModule } from '@directives/directives.module'; | ||||
| import { CoreCourseComponentsModule } from '@core/course/components/components.module'; | ||||
| import { AddonModH5PActivityIndexComponent } from './index/index'; | ||||
| 
 | ||||
| @NgModule({ | ||||
|     declarations: [ | ||||
|         AddonModH5PActivityIndexComponent, | ||||
|     ], | ||||
|     imports: [ | ||||
|         CommonModule, | ||||
|         IonicModule, | ||||
|         TranslateModule.forChild(), | ||||
|         CoreComponentsModule, | ||||
|         CoreDirectivesModule, | ||||
|         CoreCourseComponentsModule | ||||
|     ], | ||||
|     providers: [ | ||||
|     ], | ||||
|     exports: [ | ||||
|         AddonModH5PActivityIndexComponent, | ||||
|     ], | ||||
|     entryComponents: [ | ||||
|         AddonModH5PActivityIndexComponent, | ||||
|     ] | ||||
| }) | ||||
| export class AddonModH5PActivityComponentsModule {} | ||||
| @ -0,0 +1,17 @@ | ||||
| <!-- Buttons to add to the header. --> | ||||
| <core-navbar-buttons end> | ||||
|     <core-context-menu> | ||||
|         <core-context-menu-item *ngIf="externalUrl" [priority]="900" [content]="'core.openinbrowser' | translate" [href]="externalUrl" [iconAction]="'open'"></core-context-menu-item> | ||||
|         <core-context-menu-item *ngIf="description" [priority]="800" [content]="'core.moduleintro' | translate" (action)="expandDescription()" [iconAction]="'arrow-forward'"></core-context-menu-item> | ||||
|         <core-context-menu-item *ngIf="blog" [priority]="750" content="{{'addon.blog.blog' | translate}}" [iconAction]="'fa-newspaper-o'" (action)="gotoBlog($event)"></core-context-menu-item> | ||||
|         <core-context-menu-item *ngIf="loaded && isOnline" [priority]="700" [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon" [closeOnClick]="false"></core-context-menu-item> | ||||
|     </core-context-menu> | ||||
| </core-navbar-buttons> | ||||
| 
 | ||||
| <!-- Content. --> | ||||
| <core-loading [hideUntil]="loaded" class="core-loading-center safe-area-page"> | ||||
| 
 | ||||
|     <core-course-module-description [description]="description" [component]="component" [componentId]="componentId" contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId"></core-course-module-description> | ||||
| 
 | ||||
|     <!-- TODO --> | ||||
| </core-loading> | ||||
							
								
								
									
										83
									
								
								src/addon/mod/h5pactivity/components/index/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								src/addon/mod/h5pactivity/components/index/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,83 @@ | ||||
| // (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 { Component, Optional, Injector } from '@angular/core'; | ||||
| import { Content } from 'ionic-angular'; | ||||
| import { CoreCourseModuleMainActivityComponent } from '@core/course/classes/main-activity-component'; | ||||
| import { AddonModH5PActivity, AddonModH5PActivityProvider, AddonModH5PActivityData } from '../../providers/h5pactivity'; | ||||
| 
 | ||||
| /** | ||||
|  * Component that displays an H5P activity entry page. | ||||
|  */ | ||||
| @Component({ | ||||
|     selector: 'addon-mod-h5pactivity-index', | ||||
|     templateUrl: 'addon-mod-h5pactivity-index.html', | ||||
| }) | ||||
| export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActivityComponent { | ||||
|     component = AddonModH5PActivityProvider.COMPONENT; | ||||
|     moduleName = 'h5pactivity'; | ||||
| 
 | ||||
|     h5pActivity: AddonModH5PActivityData; // The H5P activity object.
 | ||||
| 
 | ||||
|     protected fetchContentDefaultError = 'addon.mod_h5pactivity.errorgetactivity'; | ||||
| 
 | ||||
|     constructor(injector: Injector, | ||||
|             @Optional() protected content: Content) { | ||||
|         super(injector, content); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         super.ngOnInit(); | ||||
| 
 | ||||
|         this.loadContent(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check the completion. | ||||
|      */ | ||||
|     protected checkCompletion(): void { | ||||
|         this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get the activity data. | ||||
|      * | ||||
|      * @param refresh If it's refreshing content. | ||||
|      * @param sync If it should try to sync. | ||||
|      * @param showErrors If show errors to the user of hide them. | ||||
|      * @return Promise resolved when done. | ||||
|      */ | ||||
|     protected async fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<void> { | ||||
|         try { | ||||
|             this.h5pActivity = await AddonModH5PActivity.instance.getH5PActivity(this.courseId, this.module.id); | ||||
| 
 | ||||
|             this.description = this.h5pActivity.intro; | ||||
|             this.dataRetrieved.emit(this.h5pActivity); | ||||
|         } finally { | ||||
|             this.fillContextMenu(refresh); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Perform the invalidate content function. | ||||
|      * | ||||
|      * @return Resolved when done. | ||||
|      */ | ||||
|     protected invalidateContent(): Promise<any> { | ||||
|        return AddonModH5PActivity.instance.invalidateActivityData(this.courseId); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										43
									
								
								src/addon/mod/h5pactivity/h5pactivity.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								src/addon/mod/h5pactivity/h5pactivity.module.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | ||||
| // (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 { NgModule } from '@angular/core'; | ||||
| import { AddonModH5PActivityComponentsModule } from './components/components.module'; | ||||
| import { AddonModH5PActivityModuleHandler } from './providers/module-handler'; | ||||
| import { AddonModH5PActivityProvider } from './providers/h5pactivity'; | ||||
| import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate'; | ||||
| 
 | ||||
| // List of providers (without handlers).
 | ||||
| export const ADDON_MOD_H5P_ACTIVITY_PROVIDERS: any[] = [ | ||||
|     AddonModH5PActivityProvider, | ||||
| ]; | ||||
| 
 | ||||
| @NgModule({ | ||||
|     declarations: [ | ||||
|     ], | ||||
|     imports: [ | ||||
|         AddonModH5PActivityComponentsModule | ||||
|     ], | ||||
|     providers: [ | ||||
|         AddonModH5PActivityProvider, | ||||
|         AddonModH5PActivityModuleHandler, | ||||
|     ] | ||||
| }) | ||||
| export class AddonModH5PActivityModule { | ||||
|     constructor(moduleDelegate: CoreCourseModuleDelegate, | ||||
|             moduleHandler: AddonModH5PActivityModuleHandler) { | ||||
| 
 | ||||
|         moduleDelegate.registerHandler(moduleHandler); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										4
									
								
								src/addon/mod/h5pactivity/lang/en.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/addon/mod/h5pactivity/lang/en.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| { | ||||
|     "errorgetactivity": "Error getting H5P activity data.", | ||||
|     "modulenameplural": "H5P" | ||||
| } | ||||
							
								
								
									
										16
									
								
								src/addon/mod/h5pactivity/pages/index/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/addon/mod/h5pactivity/pages/index/index.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| <ion-header> | ||||
|     <ion-navbar core-back-button> | ||||
|         <ion-title><core-format-text [text]="title" contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId"></core-format-text></ion-title> | ||||
| 
 | ||||
|         <ion-buttons end> | ||||
|             <!-- The buttons defined by the component will be added in here. --> | ||||
|         </ion-buttons> | ||||
|     </ion-navbar> | ||||
| </ion-header> | ||||
| <ion-content> | ||||
|     <ion-refresher [enabled]="h5pComponent.loaded" (ionRefresh)="h5pComponent.doRefresh($event)"> | ||||
|         <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content> | ||||
|     </ion-refresher> | ||||
| 
 | ||||
|     <addon-mod-h5pactivity-index [module]="module" [courseId]="courseId" (dataRetrieved)="updateData($event)"></addon-mod-h5pactivity-index> | ||||
| </ion-content> | ||||
							
								
								
									
										33
									
								
								src/addon/mod/h5pactivity/pages/index/index.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/addon/mod/h5pactivity/pages/index/index.module.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| // (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 { NgModule } from '@angular/core'; | ||||
| import { IonicPageModule } from 'ionic-angular'; | ||||
| import { TranslateModule } from '@ngx-translate/core'; | ||||
| import { CoreDirectivesModule } from '@directives/directives.module'; | ||||
| import { AddonModH5PActivityComponentsModule } from '../../components/components.module'; | ||||
| import { AddonModH5PActivityIndexPage } from './index'; | ||||
| 
 | ||||
| @NgModule({ | ||||
|     declarations: [ | ||||
|         AddonModH5PActivityIndexPage, | ||||
|     ], | ||||
|     imports: [ | ||||
|         CoreDirectivesModule, | ||||
|         AddonModH5PActivityComponentsModule, | ||||
|         IonicPageModule.forChild(AddonModH5PActivityIndexPage), | ||||
|         TranslateModule.forChild() | ||||
|     ], | ||||
| }) | ||||
| export class AddonModH5PActivityIndexPageModule {} | ||||
							
								
								
									
										49
									
								
								src/addon/mod/h5pactivity/pages/index/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								src/addon/mod/h5pactivity/pages/index/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,49 @@ | ||||
| // (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 { Component, ViewChild } from '@angular/core'; | ||||
| import { IonicPage, NavParams } from 'ionic-angular'; | ||||
| import { AddonModH5PActivityIndexComponent } from '../../components/index/index'; | ||||
| import { AddonModH5PActivityData } from '../../providers/h5pactivity'; | ||||
| 
 | ||||
| /** | ||||
|  * Page that displays an H5P activity. | ||||
|  */ | ||||
| @IonicPage({ segment: 'addon-mod-h5pactivity-index' }) | ||||
| @Component({ | ||||
|     selector: 'page-addon-mod-h5pactivity-index', | ||||
|     templateUrl: 'index.html', | ||||
| }) | ||||
| export class AddonModH5PActivityIndexPage { | ||||
|     @ViewChild(AddonModH5PActivityIndexComponent) h5pComponent: AddonModH5PActivityIndexComponent; | ||||
| 
 | ||||
|     title: string; | ||||
|     module: any; | ||||
|     courseId: number; | ||||
| 
 | ||||
|     constructor(navParams: NavParams) { | ||||
|         this.module = navParams.get('module') || {}; | ||||
|         this.courseId = navParams.get('courseId'); | ||||
|         this.title = this.module.name; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Update some data based on the H5P activity instance. | ||||
|      * | ||||
|      * @param h5p H5P activity instance. | ||||
|      */ | ||||
|     updateData(h5p: AddonModH5PActivityData): void { | ||||
|         this.title = h5p.name || this.title; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										173
									
								
								src/addon/mod/h5pactivity/providers/h5pactivity.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								src/addon/mod/h5pactivity/providers/h5pactivity.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,173 @@ | ||||
| // (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 { CoreSites } from '@providers/sites'; | ||||
| import { CoreWSExternalWarning, CoreWSExternalFile } from '@providers/ws'; | ||||
| import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; | ||||
| 
 | ||||
| import { makeSingleton, Translate } from '@singletons/core.singletons'; | ||||
| 
 | ||||
| /** | ||||
|  * Service that provides some features for H5P activity. | ||||
|  */ | ||||
| @Injectable() | ||||
| export class AddonModH5PActivityProvider { | ||||
|     static COMPONENT = 'mmaModH5PActivity'; | ||||
| 
 | ||||
|     protected ROOT_CACHE_KEY = 'mmaModH5PActivity:'; | ||||
| 
 | ||||
|     /** | ||||
|      * Get cache key for H5P activity data WS calls. | ||||
|      * | ||||
|      * @param courseId Course ID. | ||||
|      * @return Cache key. | ||||
|      */ | ||||
|     protected getH5PActivityDataCacheKey(courseId: number): string { | ||||
|         return this.ROOT_CACHE_KEY + 'h5pactivity:' + courseId; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get an H5P activity with key=value. If more than one is found, only the first will be returned. | ||||
|      * | ||||
|      * @param courseId Course ID. | ||||
|      * @param key Name of the property to check. | ||||
|      * @param value Value to search. | ||||
|      * @param moduleUrl Module URL. | ||||
|      * @param forceCache Whether it should always return cached data. | ||||
|      * @param siteId Site ID. If not defined, current site. | ||||
|      * @return Promise resolved with the activity data. | ||||
|      */ | ||||
|     protected async getH5PActivityByField(courseId: number, key: string, value: any, forceCache?: boolean, siteId?: string) | ||||
|             : Promise<AddonModH5PActivityData> { | ||||
| 
 | ||||
|         const site = await CoreSites.instance.getSite(siteId); | ||||
|         const params = { | ||||
|             courseids: [courseId], | ||||
|         }; | ||||
|         const preSets: CoreSiteWSPreSets = { | ||||
|             cacheKey: this.getH5PActivityDataCacheKey(courseId), | ||||
|             updateFrequency: CoreSite.FREQUENCY_RARELY, | ||||
|         }; | ||||
| 
 | ||||
|         if (forceCache) { | ||||
|             preSets.omitExpires = true; | ||||
|         } | ||||
| 
 | ||||
|         const response: AddonModH5PActivityGetByCoursesRresult = | ||||
|                 await site.read('mod_h5pactivity_get_h5pactivities_by_courses', params, preSets); | ||||
| 
 | ||||
|         if (response && response.h5pactivities) { | ||||
|             const currentActivity = response.h5pactivities.find((h5pActivity) => { | ||||
|                 return h5pActivity[key] == value; | ||||
|             }); | ||||
| 
 | ||||
|             if (currentActivity) { | ||||
|                 return currentActivity; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         throw Translate.instance.instant('addon.mod_h5pactivity.errorgetactivity'); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get an H5P activity by module ID. | ||||
|      * | ||||
|      * @param courseId Course ID. | ||||
|      * @param cmId Course module ID. | ||||
|      * @param forceCache Whether it should always return cached data. | ||||
|      * @param siteId Site ID. If not defined, current site. | ||||
|      * @return Promise resolved with the activity data. | ||||
|      */ | ||||
|     getH5PActivity(courseId: number, cmId: number, forceCache?: boolean, siteId?: string): Promise<AddonModH5PActivityData> { | ||||
|         return this.getH5PActivityByField(courseId, 'coursemodule', cmId, forceCache, siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get an H5P activity by instance ID. | ||||
|      * | ||||
|      * @param courseId Course ID. | ||||
|      * @param id Instance ID. | ||||
|      * @param forceCache Whether it should always return cached data. | ||||
|      * @param siteId Site ID. If not defined, current site. | ||||
|      * @return Promise resolved with the activity data. | ||||
|      */ | ||||
|     getH5PActivityById(courseId: number, id: number, forceCache?: boolean, siteId?: string): Promise<AddonModH5PActivityData> { | ||||
|         return this.getH5PActivityByField(courseId, 'id', id, forceCache, siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Invalidates H5P activity data. | ||||
|      * | ||||
|      * @param courseId Course ID. | ||||
|      * @param siteId Site ID. If not defined, current site. | ||||
|      * @return Promise resolved when the data is invalidated. | ||||
|      */ | ||||
|     async invalidateActivityData(courseId: number, siteId?: string): Promise<any> { | ||||
|         const site = await CoreSites.instance.getSite(siteId); | ||||
| 
 | ||||
|         return site.invalidateWsCacheForKey(this.getH5PActivityDataCacheKey(courseId)); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Delete launcher. | ||||
|      * | ||||
|      * @return Promise resolved when the launcher file is deleted. | ||||
|      */ | ||||
|     async isPluginEnabled(siteId?: string): Promise<boolean> { | ||||
|         const site = await CoreSites.instance.getSite(siteId); | ||||
| 
 | ||||
|         return site.wsAvailable('mod_h5pactivity_get_h5pactivities_by_courses'); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| export class AddonModH5PActivity extends makeSingleton(AddonModH5PActivityProvider) {} | ||||
| 
 | ||||
| /** | ||||
|  * Basic data for an H5P activity, exported by Moodle class h5pactivity_summary_exporter. | ||||
|  */ | ||||
| export type AddonModH5PActivityData = { | ||||
|     id: number; // The primary key of the record.
 | ||||
|     course: number; // Course id this h5p activity is part of.
 | ||||
|     name: string; // The name of the activity module instance.
 | ||||
|     timecreated?: number; // Timestamp of when the instance was added to the course.
 | ||||
|     timemodified?: number; // Timestamp of when the instance was last modified.
 | ||||
|     intro: string; // H5P activity description.
 | ||||
|     introformat: number; // Intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN).
 | ||||
|     grade?: number; // The maximum grade for submission.
 | ||||
|     displayoptions: number; // H5P Button display options.
 | ||||
|     enabletracking: number; // Enable xAPI tracking.
 | ||||
|     grademethod: number; // Which H5P attempt is used for grading.
 | ||||
|     contenthash?: string; // Sha1 hash of file content.
 | ||||
|     coursemodule: number; // Coursemodule.
 | ||||
|     introfiles: CoreWSExternalFile[]; | ||||
|     package: CoreWSExternalFile[]; | ||||
|     deployedfile?: { | ||||
|         filename?: string; // File name.
 | ||||
|         filepath?: string; // File path.
 | ||||
|         filesize?: number; // File size.
 | ||||
|         fileurl?: string; // Downloadable file url.
 | ||||
|         timemodified?: number; // Time modified.
 | ||||
|         mimetype?: string; // File mime type.
 | ||||
|     }; | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * Result of WS mod_h5pactivity_get_h5pactivities_by_courses. | ||||
|  */ | ||||
| export type AddonModH5PActivityGetByCoursesRresult = { | ||||
|     h5pactivities: AddonModH5PActivityData[]; | ||||
|     warnings?: CoreWSExternalWarning[]; | ||||
| }; | ||||
							
								
								
									
										89
									
								
								src/addon/mod/h5pactivity/providers/module-handler.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								src/addon/mod/h5pactivity/providers/module-handler.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,89 @@ | ||||
| // (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 { NavController, NavOptions } from 'ionic-angular'; | ||||
| 
 | ||||
| import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate'; | ||||
| import { CoreCourse } from '@core/course/providers/course'; | ||||
| import { CoreConstants } from '@core/constants'; | ||||
| 
 | ||||
| import { AddonModH5PActivity } from './h5pactivity'; | ||||
| import { AddonModH5PActivityIndexComponent } from '../components/index/index'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler to support H5P activities. | ||||
|  */ | ||||
| @Injectable() | ||||
| export class AddonModH5PActivityModuleHandler implements CoreCourseModuleHandler { | ||||
|     name = 'AddonModH5PActivity'; | ||||
|     modName = 'h5pactivity'; | ||||
| 
 | ||||
|     supportedFeatures = { | ||||
|         [CoreConstants.FEATURE_GROUPS]: true, | ||||
|         [CoreConstants.FEATURE_GROUPINGS]: true, | ||||
|         [CoreConstants.FEATURE_MOD_INTRO]: true, | ||||
|         [CoreConstants.FEATURE_SHOW_DESCRIPTION]: true, | ||||
|         [CoreConstants.FEATURE_COMPLETION_TRACKS_VIEWS]: true, | ||||
|         [CoreConstants.FEATURE_MODEDIT_DEFAULT_COMPLETION]: true, | ||||
|         [CoreConstants.FEATURE_GRADE_HAS_GRADE]: true, | ||||
|         [CoreConstants.FEATURE_GRADE_OUTCOMES]: true, | ||||
|         [CoreConstants.FEATURE_BACKUP_MOODLE2]: true, | ||||
|     }; | ||||
| 
 | ||||
|     /** | ||||
|      * Check if the handler is enabled on a site level. | ||||
|      * | ||||
|      * @return Whether or not the handler is enabled on a site level. | ||||
|      */ | ||||
|     isEnabled(): Promise<boolean> { | ||||
|         return AddonModH5PActivity.instance.isPluginEnabled(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get the data required to display the module in the course contents view. | ||||
|      * | ||||
|      * @param module The module object. | ||||
|      * @param courseId The course ID. | ||||
|      * @param sectionId The section ID. | ||||
|      * @return Data to render the module. | ||||
|      */ | ||||
|     getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { | ||||
| 
 | ||||
|         return { | ||||
|             icon: CoreCourse.instance.getModuleIconSrc(this.modName, module.modicon), | ||||
|             title: module.name, | ||||
|             class: 'addon-mod_h5pactivity-handler', | ||||
|             action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { | ||||
|                 const pageParams = {module: module, courseId: courseId}; | ||||
|                 if (params) { | ||||
|                     Object.assign(pageParams, params); | ||||
|                 } | ||||
|                 navCtrl.push('AddonModH5PActivityIndexPage', pageParams, options); | ||||
|             } | ||||
|         }; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get the component to render the module. This is needed to support singleactivity course format. | ||||
|      * The component returned must implement CoreCourseModuleMainComponent. | ||||
|      * | ||||
|      * @param course The course object. | ||||
|      * @param module The module object. | ||||
|      * @return The component to use, undefined if not found. | ||||
|      */ | ||||
|     getMainComponent(course: any, module: any): any { | ||||
|         return AddonModH5PActivityIndexComponent; | ||||
|     } | ||||
| } | ||||
| @ -155,6 +155,7 @@ import { AddonQbehaviourModule } from '@addon/qbehaviour/qbehaviour.module'; | ||||
| import { AddonQtypeModule } from '@addon/qtype/qtype.module'; | ||||
| import { AddonStorageManagerModule } from '@addon/storagemanager/storagemanager.module'; | ||||
| import { AddonFilterModule } from '@addon/filter/filter.module'; | ||||
| import { AddonModH5PActivityModule } from '@addon/mod/h5pactivity/h5pactivity.module'; | ||||
| 
 | ||||
| import { setSingletonsInjector } from '@singletons/core.singletons'; | ||||
| 
 | ||||
| @ -303,7 +304,8 @@ export const WP_PROVIDER: any = null; | ||||
|         AddonQbehaviourModule, | ||||
|         AddonQtypeModule, | ||||
|         AddonStorageManagerModule, | ||||
|         AddonFilterModule | ||||
|         AddonFilterModule, | ||||
|         AddonModH5PActivityModule, | ||||
|     ], | ||||
|     bootstrap: [IonicApp], | ||||
|     entryComponents: [ | ||||
|  | ||||
							
								
								
									
										1
									
								
								src/assets/img/mod/h5pactivity.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/assets/img/mod/h5pactivity.svg
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" preserveAspectRatio="xMinYMid meet"><title>h5p finalArtboard 1</title><rect width="24" height="24" rx="3" ry="3" fill="#0882c8"/><path d="M22.1,8a3.37,3.37,0,0,0-2.42-.77H16.05v2H11.71l-.36,1.46a6.32,6.32,0,0,1,1-.35,3.49,3.49,0,0,1,.86-.06,3.24,3.24,0,0,1,2.35.88,2.93,2.93,0,0,1,.9,2.2A3.72,3.72,0,0,1,16,15.19a3.16,3.16,0,0,1-1.31,1.32,3.41,3.41,0,0,1-.67.27H17.7V13.28h1.65A3.8,3.8,0,0,0,22,12.46a3,3,0,0,0,.88-2.28A2.9,2.9,0,0,0,22.1,8Zm-2.44,3a1.88,1.88,0,0,1-1.21.29H17.7V9.2h.87a1.56,1.56,0,0,1,1.13.31,1,1,0,0,1,.3.76A.94.94,0,0,1,19.66,11Z" fill="#fff"/><path d="M12.27,12.05a1.33,1.33,0,0,0-1.19.74l-2.6-.37,1.17-5.2H7.29v4.08H4V7.23H1.1v9.55H4V13.28H7.29v3.49h3.57a3.61,3.61,0,0,1-1.13-.53A3.2,3.2,0,0,1,9,15.43a4,4,0,0,1-.48-1.09L11.09,14a1.32,1.32,0,1,0,1.18-1.92Z" fill="#fff"/></svg> | ||||
| After Width: | Height: | Size: 859 B | 
| @ -659,6 +659,8 @@ | ||||
|     "addon.mod_glossary.noentriesfound": "No entries were found.", | ||||
|     "addon.mod_glossary.searchquery": "Search query", | ||||
|     "addon.mod_glossary.tagarea_glossary_entries": "Glossary entries", | ||||
|     "addon.mod_h5pactivity.errorgetactivity": "Error getting H5P activity data.", | ||||
|     "addon.mod_h5pactivity.modulenameplural": "H5P", | ||||
|     "addon.mod_imscp.deploymenterror": "Content package error!", | ||||
|     "addon.mod_imscp.modulenameplural": "IMS content packages", | ||||
|     "addon.mod_imscp.showmoduledescription": "Show description", | ||||
|  | ||||
| @ -109,6 +109,7 @@ import { ADDON_MOD_FEEDBACK_PROVIDERS } from '@addon/mod/feedback/feedback.modul | ||||
| import { ADDON_MOD_FOLDER_PROVIDERS } from '@addon/mod/folder/folder.module'; | ||||
| import { ADDON_MOD_FORUM_PROVIDERS } from '@addon/mod/forum/forum.module'; | ||||
| import { ADDON_MOD_GLOSSARY_PROVIDERS } from '@addon/mod/glossary/glossary.module'; | ||||
| import { ADDON_MOD_H5P_ACTIVITY_PROVIDERS } from '@addon/mod/h5pactivity/h5pactivity.module'; | ||||
| import { ADDON_MOD_IMSCP_PROVIDERS } from '@addon/mod/imscp/imscp.module'; | ||||
| import { ADDON_MOD_LESSON_PROVIDERS } from '@addon/mod/lesson/lesson.module'; | ||||
| import { ADDON_MOD_LTI_PROVIDERS } from '@addon/mod/lti/lti.module'; | ||||
| @ -242,7 +243,7 @@ export class CoreCompileProvider { | ||||
|                 .concat(ADDON_MOD_WORKSHOP_PROVIDERS).concat(ADDON_NOTES_PROVIDERS).concat(ADDON_NOTIFICATIONS_PROVIDERS) | ||||
|                 .concat(CORE_PUSHNOTIFICATIONS_PROVIDERS).concat(ADDON_REMOTETHEMES_PROVIDERS).concat(CORE_BLOCK_PROVIDERS) | ||||
|                 .concat(CORE_FILTER_PROVIDERS).concat(CORE_H5P_PROVIDERS).concat(CORE_EDITOR_PROVIDERS) | ||||
|                 .concat(CORE_SEARCH_PROVIDERS); | ||||
|                 .concat(CORE_SEARCH_PROVIDERS).concat(ADDON_MOD_H5P_ACTIVITY_PROVIDERS); | ||||
| 
 | ||||
|         // We cannot inject anything to this constructor. Use the Injector to inject all the providers into the instance.
 | ||||
|         for (const i in providers) { | ||||
|  | ||||
| @ -30,6 +30,8 @@ import { CoreCourseFormatDelegate } from './format-delegate'; | ||||
| import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications'; | ||||
| import { CoreCoursesProvider } from '@core/courses/providers/courses'; | ||||
| 
 | ||||
| import { makeSingleton } from '@singletons/core.singletons'; | ||||
| 
 | ||||
| /** | ||||
|  * Service that provides some features regarding a course. | ||||
|  */ | ||||
| @ -98,7 +100,7 @@ export class CoreCourseProvider { | ||||
|     protected CORE_MODULES = [ | ||||
|         'assign', 'assignment', 'book', 'chat', 'choice', 'data', 'database', 'date', 'external-tool', | ||||
|         'feedback', 'file', 'folder', 'forum', 'glossary', 'ims', 'imscp', 'label', 'lesson', 'lti', 'page', 'quiz', | ||||
|         'resource', 'scorm', 'survey', 'url', 'wiki', 'workshop' | ||||
|         'resource', 'scorm', 'survey', 'url', 'wiki', 'workshop', 'h5pactivity' | ||||
|     ]; | ||||
| 
 | ||||
|     constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private eventsProvider: CoreEventsProvider, | ||||
| @ -1144,6 +1146,8 @@ export class CoreCourseProvider { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| export class CoreCourse extends makeSingleton(CoreCourseProvider) {} | ||||
| 
 | ||||
| /** | ||||
|  * Data returned by course_summary_exporter. | ||||
|  */ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user