forked from EVOgeek/Vmeda.Online
		
	
						commit
						157979e25e
					
				@ -24,6 +24,7 @@ import { CoreUtils } from '@services/utils/utils';
 | 
				
			|||||||
import { makeSingleton } from '@singletons';
 | 
					import { makeSingleton } from '@singletons';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { AddonModForumModuleHandlerService } from './module';
 | 
					import { AddonModForumModuleHandlerService } from './module';
 | 
				
			||||||
 | 
					import { isSafeNumber } from '@/core/utils/types';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Handler for forum push notifications clicks.
 | 
					 * Handler for forum push notifications clicks.
 | 
				
			||||||
@ -44,7 +45,8 @@ export class AddonModForumPushClickHandlerService implements CorePushNotificatio
 | 
				
			|||||||
    async handles(notification: NotificationData): Promise<boolean> {
 | 
					    async handles(notification: NotificationData): Promise<boolean> {
 | 
				
			||||||
        return CoreUtils.isTrueOrOne(notification.notif)
 | 
					        return CoreUtils.isTrueOrOne(notification.notif)
 | 
				
			||||||
            && notification.moodlecomponent == 'mod_forum'
 | 
					            && notification.moodlecomponent == 'mod_forum'
 | 
				
			||||||
            && notification.name == 'posts';
 | 
					            && notification.name == 'posts'
 | 
				
			||||||
 | 
					            && !!(notification.contexturl || notification.customdata?.postid);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -58,13 +60,17 @@ export class AddonModForumPushClickHandlerService implements CorePushNotificatio
 | 
				
			|||||||
        const data = notification.customdata || {};
 | 
					        const data = notification.customdata || {};
 | 
				
			||||||
        const courseId = Number(notification.courseid);
 | 
					        const courseId = Number(notification.courseid);
 | 
				
			||||||
        const discussionId = Number(contextUrlParams.d || data.discussionid);
 | 
					        const discussionId = Number(contextUrlParams.d || data.discussionid);
 | 
				
			||||||
        const cmId = Number(data.cmid);
 | 
					        const cmId = data.cmid && Number(data.cmid);
 | 
				
			||||||
        const pageParams: Params = {
 | 
					        const pageParams: Params = {
 | 
				
			||||||
            forumId: Number(data.instance),
 | 
					            forumId: Number(data.instance),
 | 
				
			||||||
            cmId,
 | 
					            cmId,
 | 
				
			||||||
            courseId,
 | 
					            courseId,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!isSafeNumber(discussionId)) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (data.postid || contextUrlParams.urlHash) {
 | 
					        if (data.postid || contextUrlParams.urlHash) {
 | 
				
			||||||
            pageParams.postId = Number(data.postid || contextUrlParams.urlHash.replace('p', ''));
 | 
					            pageParams.postId = Number(data.postid || contextUrlParams.urlHash.replace('p', ''));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -12,6 +12,7 @@
 | 
				
			|||||||
// See the License for the specific language governing permissions and
 | 
					// See the License for the specific language governing permissions and
 | 
				
			||||||
// limitations under the License.
 | 
					// limitations under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { isSafeNumber } from '@/core/utils/types';
 | 
				
			||||||
import { Injectable } from '@angular/core';
 | 
					import { Injectable } from '@angular/core';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { CoreGrades } from '@features/grades/services/grades';
 | 
					import { CoreGrades } from '@features/grades/services/grades';
 | 
				
			||||||
@ -38,8 +39,12 @@ export class AddonModLessonPushClickHandlerService implements CorePushNotificati
 | 
				
			|||||||
     * @returns Whether the notification click is handled by this handler.
 | 
					     * @returns Whether the notification click is handled by this handler.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    async handles(notification: NotificationData): Promise<boolean> {
 | 
					    async handles(notification: NotificationData): Promise<boolean> {
 | 
				
			||||||
        if (CoreUtils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_lesson' &&
 | 
					        if (
 | 
				
			||||||
                notification.name == 'graded_essay') {
 | 
					            CoreUtils.isTrueOrOne(notification.notif) &&
 | 
				
			||||||
 | 
					            notification.moodlecomponent == 'mod_lesson' &&
 | 
				
			||||||
 | 
					            notification.name == 'graded_essay' &&
 | 
				
			||||||
 | 
					            notification.customdata?.cmid
 | 
				
			||||||
 | 
					        ) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return CoreGrades.isPluginEnabledForCourse(Number(notification.courseid), notification.site);
 | 
					            return CoreGrades.isPluginEnabledForCourse(Number(notification.courseid), notification.site);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -53,11 +58,15 @@ export class AddonModLessonPushClickHandlerService implements CorePushNotificati
 | 
				
			|||||||
     * @param notification The notification to check.
 | 
					     * @param notification The notification to check.
 | 
				
			||||||
     * @returns Promise resolved when done.
 | 
					     * @returns Promise resolved when done.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    handleClick(notification: NotificationData): Promise<void> {
 | 
					    async handleClick(notification: NotificationData): Promise<void> {
 | 
				
			||||||
        const data = notification.customdata || {};
 | 
					        const data = notification.customdata || {};
 | 
				
			||||||
        const courseId = Number(notification.courseid);
 | 
					        const courseId = Number(notification.courseid);
 | 
				
			||||||
        const moduleId = Number(data.cmid);
 | 
					        const moduleId = Number(data.cmid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!isSafeNumber(moduleId)) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return CoreGradesHelper.goToGrades(courseId, undefined, moduleId, notification.site);
 | 
					        return CoreGradesHelper.goToGrades(courseId, undefined, moduleId, notification.site);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -22,6 +22,7 @@ import { CoreUtils } from '@services/utils/utils';
 | 
				
			|||||||
import { makeSingleton } from '@singletons';
 | 
					import { makeSingleton } from '@singletons';
 | 
				
			||||||
import { AddonModQuiz } from '../quiz';
 | 
					import { AddonModQuiz } from '../quiz';
 | 
				
			||||||
import { AddonModQuizHelper } from '../quiz-helper';
 | 
					import { AddonModQuizHelper } from '../quiz-helper';
 | 
				
			||||||
 | 
					import { isSafeNumber } from '@/core/utils/types';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Handler for quiz push notifications clicks.
 | 
					 * Handler for quiz push notifications clicks.
 | 
				
			||||||
@ -43,7 +44,8 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    async handles(notification: AddonModQuizPushNotificationData): Promise<boolean> {
 | 
					    async handles(notification: AddonModQuizPushNotificationData): Promise<boolean> {
 | 
				
			||||||
        return CoreUtils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_quiz' &&
 | 
					        return CoreUtils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_quiz' &&
 | 
				
			||||||
                this.SUPPORTED_NAMES.indexOf(notification.name ?? '') != -1;
 | 
					                this.SUPPORTED_NAMES.indexOf(notification.name ?? '') !== -1 &&
 | 
				
			||||||
 | 
					                !!(notification.customdata?.instance || notification.contexturl);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -57,7 +59,12 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification
 | 
				
			|||||||
        const data = notification.customdata || {};
 | 
					        const data = notification.customdata || {};
 | 
				
			||||||
        const courseId = Number(notification.courseid);
 | 
					        const courseId = Number(notification.courseid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (notification.name == 'submission') {
 | 
					        if (
 | 
				
			||||||
 | 
					            notification.name === 'submission' &&
 | 
				
			||||||
 | 
					            data.instance !== undefined &&
 | 
				
			||||||
 | 
					            contextUrlParams.attempt !== undefined &&
 | 
				
			||||||
 | 
					            contextUrlParams.page !== undefined
 | 
				
			||||||
 | 
					        ) {
 | 
				
			||||||
            // A student made a submission, go to view the attempt.
 | 
					            // A student made a submission, go to view the attempt.
 | 
				
			||||||
            return AddonModQuizHelper.handleReviewLink(
 | 
					            return AddonModQuizHelper.handleReviewLink(
 | 
				
			||||||
                Number(contextUrlParams.attempt),
 | 
					                Number(contextUrlParams.attempt),
 | 
				
			||||||
@ -69,6 +76,9 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Open the activity.
 | 
					        // Open the activity.
 | 
				
			||||||
        const moduleId = Number(contextUrlParams.id);
 | 
					        const moduleId = Number(contextUrlParams.id);
 | 
				
			||||||
 | 
					        if (!isSafeNumber(moduleId)) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await CoreUtils.ignoreErrors(AddonModQuiz.invalidateContent(moduleId, courseId, notification.site));
 | 
					        await CoreUtils.ignoreErrors(AddonModQuiz.invalidateContent(moduleId, courseId, notification.site));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -216,7 +216,7 @@ export class CoreFilterHelperProvider {
 | 
				
			|||||||
                options.filter = true;
 | 
					                options.filter = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // We cannot check which filters are available, apply them all.
 | 
					                // We cannot check which filters are available, apply them all.
 | 
				
			||||||
                return CoreFilterDelegate.getEnabledFilters(contextLevel, instanceId);
 | 
					                return await CoreFilterDelegate.getEnabledFilters(contextLevel, instanceId);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const courseId = options.courseId;
 | 
					            const courseId = options.courseId;
 | 
				
			||||||
@ -239,21 +239,21 @@ export class CoreFilterHelperProvider {
 | 
				
			|||||||
                // Get all the modules filters with a single call to decrease the number of WS calls.
 | 
					                // Get all the modules filters with a single call to decrease the number of WS calls.
 | 
				
			||||||
                const getFilters = () => this.getCourseModulesContexts(courseId, siteId);
 | 
					                const getFilters = () => this.getCourseModulesContexts(courseId, siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                return this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site);
 | 
					                return await this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            } else if (contextLevel == 'course') {
 | 
					            } else if (contextLevel == 'course') {
 | 
				
			||||||
                // If enrolled, get all enrolled courses filters with a single call to decrease number of WS calls.
 | 
					                // If enrolled, get all enrolled courses filters with a single call to decrease number of WS calls.
 | 
				
			||||||
                const getFilters = () => this.getCourseContexts(instanceId, siteId);
 | 
					                const getFilters = () => this.getCourseContexts(instanceId, siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                return this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site);
 | 
					                return await this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site);
 | 
				
			||||||
            } else if (contextLevel == 'block' && courseId && CoreCourse.canGetCourseBlocks(site)) {
 | 
					            } else if (contextLevel == 'block' && courseId && CoreCourse.canGetCourseBlocks(site)) {
 | 
				
			||||||
                // Get all the course blocks filters with a single call to decrease number of WS calls.
 | 
					                // Get all the course blocks filters with a single call to decrease number of WS calls.
 | 
				
			||||||
                const getFilters = () => this.getBlocksContexts(courseId, siteId);
 | 
					                const getFilters = () => this.getBlocksContexts(courseId, siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                return this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site);
 | 
					                return await this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return CoreFilter.getAvailableInContext(contextLevel, instanceId, siteId);
 | 
					            return await CoreFilter.getAvailableInContext(contextLevel, instanceId, siteId);
 | 
				
			||||||
        } catch (error) {
 | 
					        } catch (error) {
 | 
				
			||||||
            this.logger.error('Error getting filters, return an empty array', error, contextLevel, instanceId);
 | 
					            this.logger.error('Error getting filters, return an empty array', error, contextLevel, instanceId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user