diff --git a/src/addons/mod/assign/services/handlers/prefetch.ts b/src/addons/mod/assign/services/handlers/prefetch.ts index 1f7d6e533..e9223ddf4 100644 --- a/src/addons/mod/assign/services/handlers/prefetch.ts +++ b/src/addons/mod/assign/services/handlers/prefetch.ts @@ -28,7 +28,6 @@ import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/ import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreWSFile } from '@services/ws'; import { AddonModAssignHelper, AddonModAssignSubmissionFormatted } from '../assign-helper'; -import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreUtils } from '@services/utils/utils'; import { CoreFilepool } from '@services/filepool'; import { CoreGroups } from '@services/groups'; @@ -243,7 +242,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref promises.push(this.prefetchSubmissions(assign, courseId, module.id, userId, siteId)); - promises.push(CoreCourseHelper.getModuleCourseIdByInstance(assign.id, 'assign', siteId)); + promises.push(CoreCourse.getModuleBasicInfoByInstance(assign.id, 'assign', siteId)); // Get course data, needed to determine upload max size if it's configured to be course limit. promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); @@ -515,7 +514,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref * @return Promise resolved when done. */ sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise { - return AddonModAssignSync.syncAssign(module.instance!, siteId); + return AddonModAssignSync.syncAssign(module.instance, siteId); } } diff --git a/src/addons/mod/choice/services/handlers/prefetch.ts b/src/addons/mod/choice/services/handlers/prefetch.ts index 0aa454612..5ae104e28 100644 --- a/src/addons/mod/choice/services/handlers/prefetch.ts +++ b/src/addons/mod/choice/services/handlers/prefetch.ts @@ -147,7 +147,7 @@ export class AddonModChoicePrefetchHandlerService extends CoreCourseActivityPref * @return Promise resolved when done. */ sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise { - return AddonModChoiceSync.syncChoice(module.instance!, undefined, siteId); + return AddonModChoiceSync.syncChoice(module.instance, undefined, siteId); } } diff --git a/src/addons/mod/data/services/handlers/prefetch.ts b/src/addons/mod/data/services/handlers/prefetch.ts index 4a7bf6b38..86c79ee94 100644 --- a/src/addons/mod/data/services/handlers/prefetch.ts +++ b/src/addons/mod/data/services/handlers/prefetch.ts @@ -173,7 +173,7 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet async invalidateModule(module: CoreCourseAnyModuleData, courseId: number): Promise { const promises: Promise[] = []; promises.push(AddonModData.invalidateDatabaseData(courseId)); - promises.push(AddonModData.invalidateDatabaseAccessInformationData(module.instance!)); + promises.push(AddonModData.invalidateDatabaseAccessInformationData(module.instance)); await Promise.all(promises); } @@ -279,7 +279,7 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet */ async sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise { const promises = [ - AddonModDataSync.syncDatabase(module.instance!, siteId), + AddonModDataSync.syncDatabase(module.instance, siteId), AddonModDataSync.syncRatings(module.id, true, siteId), ]; diff --git a/src/addons/mod/feedback/services/handlers/prefetch.ts b/src/addons/mod/feedback/services/handlers/prefetch.ts index 3180321d9..b7f78b3b3 100644 --- a/src/addons/mod/feedback/services/handlers/prefetch.ts +++ b/src/addons/mod/feedback/services/handlers/prefetch.ts @@ -211,7 +211,7 @@ export class AddonModFeedbackPrefetchHandlerService extends CoreCourseActivityPr * @inheritdoc */ sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise { - return AddonModFeedbackSync.syncFeedback(module.instance!, siteId); + return AddonModFeedbackSync.syncFeedback(module.instance, siteId); } } diff --git a/src/addons/mod/folder/components/index/index.ts b/src/addons/mod/folder/components/index/index.ts index 18f99216c..90e3f7ed4 100644 --- a/src/addons/mod/folder/components/index/index.ts +++ b/src/addons/mod/folder/components/index/index.ts @@ -66,7 +66,7 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo await this.loadContent(); try { - await AddonModFolder.logView(this.module.instance!, this.module.name); + await AddonModFolder.logView(this.module.instance, this.module.name); CoreCourse.checkModuleCompletion(this.courseId, this.module.completiondata); } catch { // Ignore errors. diff --git a/src/addons/mod/forum/services/handlers/prefetch.ts b/src/addons/mod/forum/services/handlers/prefetch.ts index 41357fcf6..a460bc6e7 100644 --- a/src/addons/mod/forum/services/handlers/prefetch.ts +++ b/src/addons/mod/forum/services/handlers/prefetch.ts @@ -320,8 +320,8 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe ): Promise { const promises: Promise[] = []; - promises.push(AddonModForumSync.syncForumDiscussions(module.instance!, undefined, siteId)); - promises.push(AddonModForumSync.syncForumReplies(module.instance!, undefined, siteId)); + promises.push(AddonModForumSync.syncForumDiscussions(module.instance, undefined, siteId)); + promises.push(AddonModForumSync.syncForumReplies(module.instance, undefined, siteId)); promises.push(AddonModForumSync.syncRatings(module.id, undefined, true, siteId)); const results = await Promise.all(promises); diff --git a/src/addons/mod/glossary/services/handlers/prefetch.ts b/src/addons/mod/glossary/services/handlers/prefetch.ts index 58420e244..4ef05bccc 100644 --- a/src/addons/mod/glossary/services/handlers/prefetch.ts +++ b/src/addons/mod/glossary/services/handlers/prefetch.ts @@ -219,7 +219,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr */ async sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise { const results = await Promise.all([ - AddonModGlossarySync.syncGlossaryEntries(module.instance!, undefined, siteId), + AddonModGlossarySync.syncGlossaryEntries(module.instance, undefined, siteId), AddonModGlossarySync.syncRatings(module.id, undefined, siteId), ]); diff --git a/src/addons/mod/imscp/components/index/index.ts b/src/addons/mod/imscp/components/index/index.ts index 502478fab..6ed251203 100644 --- a/src/addons/mod/imscp/components/index/index.ts +++ b/src/addons/mod/imscp/components/index/index.ts @@ -53,7 +53,7 @@ export class AddonModImscpIndexComponent extends CoreCourseModuleMainResourceCom await this.loadContent(); try { - await AddonModImscp.logView(this.module.instance!, this.module.name); + await AddonModImscp.logView(this.module.instance, this.module.name); CoreCourse.checkModuleCompletion(this.courseId, this.module.completiondata); } catch { // Ignore errors. diff --git a/src/addons/mod/lesson/services/handlers/prefetch.ts b/src/addons/mod/lesson/services/handlers/prefetch.ts index 2b550bf94..4d87bf1ce 100644 --- a/src/addons/mod/lesson/services/handlers/prefetch.ts +++ b/src/addons/mod/lesson/services/handlers/prefetch.ts @@ -537,7 +537,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref * @return Promise resolved when done. */ sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise { - return AddonModLessonSync.syncLesson(module.instance!, false, false, siteId); + return AddonModLessonSync.syncLesson(module.instance, false, false, siteId); } } diff --git a/src/addons/mod/page/components/index/index.ts b/src/addons/mod/page/components/index/index.ts index a58d49a3a..e416a9244 100644 --- a/src/addons/mod/page/components/index/index.ts +++ b/src/addons/mod/page/components/index/index.ts @@ -54,7 +54,7 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp await this.loadContent(); try { - await AddonModPage.logView(this.module.instance!, this.module.name); + await AddonModPage.logView(this.module.instance, this.module.name); CoreCourse.checkModuleCompletion(this.courseId, this.module.completiondata); } catch { // Ignore errors. diff --git a/src/addons/mod/quiz/services/handlers/prefetch.ts b/src/addons/mod/quiz/services/handlers/prefetch.ts index e1d035e83..dedc71db5 100644 --- a/src/addons/mod/quiz/services/handlers/prefetch.ts +++ b/src/addons/mod/quiz/services/handlers/prefetch.ts @@ -208,7 +208,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet // Invalidate the calls required to check if a quiz is downloadable. await Promise.all([ AddonModQuiz.invalidateQuizData(courseId), - AddonModQuiz.invalidateUserAttemptsForUser(module.instance!), + AddonModQuiz.invalidateUserAttemptsForUser(module.instance), ]); } diff --git a/src/addons/mod/resource/components/index/index.ts b/src/addons/mod/resource/components/index/index.ts index 8b95a597a..8064bfd14 100644 --- a/src/addons/mod/resource/components/index/index.ts +++ b/src/addons/mod/resource/components/index/index.ts @@ -82,7 +82,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource await this.loadContent(); try { - await AddonModResource.logView(this.module.instance!, this.module.name); + await AddonModResource.logView(this.module.instance, this.module.name); CoreCourse.checkModuleCompletion(this.courseId, this.module.completiondata); } catch { // Ignore errors. diff --git a/src/addons/mod/resource/services/resource-helper.ts b/src/addons/mod/resource/services/resource-helper.ts index c3f577847..59c695869 100644 --- a/src/addons/mod/resource/services/resource-helper.ts +++ b/src/addons/mod/resource/services/resource-helper.ts @@ -202,7 +202,7 @@ export class AddonModResourceHelperProvider { ); try { - await AddonModResource.logView(module.instance!, module.name); + await AddonModResource.logView(module.instance, module.name); CoreCourse.checkModuleCompletion(courseId, module.completiondata); } catch { // Ignore errors. diff --git a/src/addons/mod/survey/services/handlers/prefetch.ts b/src/addons/mod/survey/services/handlers/prefetch.ts index fca2d7852..31ffcff48 100644 --- a/src/addons/mod/survey/services/handlers/prefetch.ts +++ b/src/addons/mod/survey/services/handlers/prefetch.ts @@ -107,7 +107,7 @@ export class AddonModSurveyPrefetchHandlerService extends CoreCourseActivityPref * @inheritdoc */ sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise { - return AddonModSurveySync.syncSurvey(module.instance!, undefined, siteId); + return AddonModSurveySync.syncSurvey(module.instance, undefined, siteId); } } diff --git a/src/addons/mod/url/components/index/index.ts b/src/addons/mod/url/components/index/index.ts index db01da3b2..0c1c8c16a 100644 --- a/src/addons/mod/url/components/index/index.ts +++ b/src/addons/mod/url/components/index/index.ts @@ -169,7 +169,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo */ protected async logView(): Promise { try { - await AddonModUrl.logView(this.module.instance!, this.module.name); + await AddonModUrl.logView(this.module.instance, this.module.name); CoreCourse.checkModuleCompletion(this.courseId, this.module.completiondata); } catch { // Ignore errors. diff --git a/src/addons/mod/wiki/services/handlers/prefetch.ts b/src/addons/mod/wiki/services/handlers/prefetch.ts index d6b3b4179..25f26727f 100644 --- a/src/addons/mod/wiki/services/handlers/prefetch.ts +++ b/src/addons/mod/wiki/services/handlers/prefetch.ts @@ -14,8 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler'; -import { CoreCourseAnyModuleData } from '@features/course/services/course'; -import { CoreCourseHelper } from '@features/course/services/course-helper'; +import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreFilepool } from '@services/filepool'; import { CoreGroups } from '@services/groups'; import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate'; @@ -190,7 +189,7 @@ export class AddonModWikiPrefetchHandlerService extends CoreCourseActivityPrefet // Fetch info to provide wiki links. promises.push(AddonModWiki.getWiki(courseId, module.id, { siteId }).then((wiki) => - CoreCourseHelper.getModuleCourseIdByInstance(wiki.id, 'wiki', siteId))); + CoreCourse.getModuleBasicInfoByInstance(wiki.id, 'wiki', siteId))); // Get related page files and fetch them. promises.push(this.getFiles(module, courseId, single, siteId).then((files) => @@ -203,7 +202,7 @@ export class AddonModWikiPrefetchHandlerService extends CoreCourseActivityPrefet * @inheritdoc */ sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise { - return AddonModWikiSync.syncWiki(module.instance!, module.course, module.id, siteId); + return AddonModWikiSync.syncWiki(module.instance, module.course, module.id, siteId); } } diff --git a/src/addons/mod/workshop/pages/edit-submission/edit-submission.ts b/src/addons/mod/workshop/pages/edit-submission/edit-submission.ts index 9fdb9af26..aa215a1ce 100644 --- a/src/addons/mod/workshop/pages/edit-submission/edit-submission.ts +++ b/src/addons/mod/workshop/pages/edit-submission/edit-submission.ts @@ -116,7 +116,7 @@ export class AddonModWorkshopEditSubmissionPage implements OnInit, OnDestroy, Ca this.editorExtraParams.id = this.submissionId; } - this.workshopId = this.module.instance!; + this.workshopId = this.module.instance; this.componentId = this.module.id; if (!this.isDestroyed) { diff --git a/src/addons/mod/workshop/services/handlers/prefetch.ts b/src/addons/mod/workshop/services/handlers/prefetch.ts index 7700b19cf..b89f83af9 100644 --- a/src/addons/mod/workshop/services/handlers/prefetch.ts +++ b/src/addons/mod/workshop/services/handlers/prefetch.ts @@ -379,7 +379,7 @@ export class AddonModWorkshopPrefetchHandlerService extends CoreCourseActivityPr * @inheritdoc */ async sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise { - return AddonModWorkshopSync.syncWorkshop(module.instance!, siteId); + return AddonModWorkshopSync.syncWorkshop(module.instance, siteId); } } diff --git a/src/core/features/course/classes/main-activity-page.ts b/src/core/features/course/classes/main-activity-page.ts index de7604457..f82ad56de 100644 --- a/src/core/features/course/classes/main-activity-page.ts +++ b/src/core/features/course/classes/main-activity-page.ts @@ -15,7 +15,7 @@ import { Component, OnInit } from '@angular/core'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreCourseAnyModuleData } from '../services/course'; +import { CoreCourseModuleData } from '../services/course-helper'; import { CoreCourseModuleMainResourceComponent } from './main-resource-component'; /** @@ -29,7 +29,7 @@ export class CoreCourseModuleMainActivityPage('module'); + this.module = CoreNavigator.getRequiredRouteParam('module'); this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); } catch (error) { CoreDomUtils.showErrorModal(error); diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 53ff749db..590d7aea1 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -1429,26 +1429,6 @@ export class CoreCourseHelperProvider { return CoreConstants.ICON_DOWNLOADING; } - /** - * Get the course ID from a module instance ID, showing an error message if it can't be retrieved. - * - * @param id Instance ID. - * @param module Name of the module. E.g. 'glossary'. - * @param siteId Site ID. If not defined, current site. - * @return Promise resolved with the module's course ID. - */ - async getModuleCourseIdByInstance(id: number, module: string, siteId?: string): Promise { - try { - const cm = await CoreCourse.getModuleBasicInfoByInstance(id, module, siteId); - - return cm.course; - } catch (error) { - CoreDomUtils.showErrorModalDefault(error, 'core.course.errorgetmodule', true); - - throw error; - } - } - /** * Get prefetch info for a module. * @@ -1629,7 +1609,7 @@ export class CoreCourseHelperProvider { const site = await CoreSites.getSite(siteId); // Get the module. - const module = + const module = await CoreCourse.getModule(moduleId, courseId, sectionId, false, false, siteId, modName); if (CoreSites.getCurrentSiteId() == site.getId()) { @@ -1649,13 +1629,11 @@ export class CoreCourseHelperProvider { } } - this.logger.warn('navCtrl was not passed to navigateToModule by the link handler for ' + module.modname); - const params: Params = { course: { id: courseId }, - module: module, - sectionId: sectionId, - modParams: modParams, + module, + sectionId, + modParams, }; if (courseId == site.getSiteHomeId()) { diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 279750440..592b7ca84 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -936,7 +936,7 @@ export class CoreCourseProvider { * Load module contents into module.contents if they aren't loaded already. * * @param module Module to load the contents. - * @param courseId The course ID. Recommended to speed up the process and minimize data usage. + * @param courseId Not used since 4.0. * @param sectionId The section ID. * @param preferCache True if shouldn't call WS if data is cached, false otherwise. * @param ignoreCache True if it should ignore cached data (it will always fail in offline or server down). @@ -960,7 +960,7 @@ export class CoreCourseProvider { return; } - const mod = await this.getModule(module.id, courseId, sectionId, preferCache, ignoreCache, siteId, modName); + const mod = await this.getModule(module.id, module.course, sectionId, preferCache, ignoreCache, siteId, modName); if (!mod.contents) { throw new CoreError(Translate.instant('core.course.modulenotfound')); @@ -1532,13 +1532,13 @@ export type CoreCourseGetContentsWSModule = { id: number; // Activity id. url?: string; // Activity url. name: string; // Activity module name. - instance?: number; // Instance id. - contextid?: number; // Activity context id. + instance: number; // Instance id. Cannot be undefined. + contextid?: number; // @since 3.10. Activity context id. description?: string; // Activity description. - visible?: number; // Is the module visible. - uservisible?: boolean; // Is the module visible for the user?. + visible: number; // Is the module visible. Cannot be undefined. + uservisible: boolean; // Is the module visible for the user?. Cannot be undefined. availabilityinfo?: string; // Availability information. - visibleoncoursepage?: number; // Is the module visible on course page. + visibleoncoursepage: number; // Is the module visible on course page. Cannot be undefined. modicon: string; // Activity icon url. modname: string; // Activity module type. modplural: string; // Activity module plural name.