@@ -364,5 +364,60 @@ angular.module('mm.addons.mod_lesson')
364364 } ) ;
365365 }
366366
367+ /**
368+ * Content links handler for lesson grade link.
369+ *
370+ * @module mm.addons.mod_lesson
371+ * @ngdoc method
372+ * @name $mmaModLessonHandlers#gradeLinksHandler
373+ */
374+ self . gradeLinksHandler = $mmContentLinksHelper . createModuleGradeLinkHandler ( 'mmaModLesson' , 'lesson' , $mmaModLesson , viewGrade ) ;
375+
376+ /**
377+ * Treat a grade link to a user different than current one.
378+ *
379+ * @param {String } url URL to treat.
380+ * @param {Object } params Params of the URL.
381+ * @param {Number } [courseId] Course ID related to the URL.
382+ * @param {String } siteId Site ID.
383+ * @return {[type] } [description]
384+ */
385+ function viewGrade ( url , params , courseId , siteId ) {
386+ siteId = siteId || $mmSite . getId ( ) ;
387+
388+ var moduleId = parseInt ( params . id , 10 ) ,
389+ modal = $mmUtil . showModalLoading ( ) ,
390+ module ;
391+
392+ return $mmCourse . getModuleBasicInfo ( moduleId , siteId ) . then ( function ( mod ) {
393+ module = mod ;
394+ courseId = module . course || courseId || params . courseid || params . cid ;
395+
396+ // Check if the user can see the user reports in the lesson.
397+ return $mmaModLesson . getAccessInformation ( module . instance ) ;
398+ } ) . then ( function ( info ) {
399+ if ( info . canviewreports ) {
400+ // User can view reports, go to view the report.
401+ return $state . go ( 'redirect' , {
402+ siteid : siteId ,
403+ state : 'site.mod_lesson-userretake' ,
404+ params : {
405+ courseid : courseId ,
406+ lessonid : module . instance ,
407+ userid : parseInt ( params . userid , 10 )
408+ }
409+ } ) ;
410+ } else {
411+ // User cannot view the report, go to lesson index.
412+ return $mmCourseHelper . navigateToModule ( moduleId , siteId , courseId , module . section ) ;
413+ }
414+ } ) . catch ( function ( error ) {
415+ $mmUtil . showErrorModalDefault ( error , 'mm.course.errorgetmodule' , true ) ;
416+ return $q . reject ( ) ;
417+ } ) . finally ( function ( ) {
418+ modal . dismiss ( ) ;
419+ } ) ;
420+ }
421+
367422 return self ;
368423} ) ;
0 commit comments